Panda3D
Loading...
Searching...
No Matches
conditionVarSimpleImpl.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file conditionVarSimpleImpl.cxx
10 * @author drose
11 * @date 2007-06-19
12 */
13
14#include "selectThreadImpl.h"
15
16#ifdef THREAD_SIMPLE_IMPL
17
19#include "threadSimpleImpl.h"
20
21/**
22 *
23 */
24void ConditionVarSimpleImpl::
25wait() {
26 _mutex.unlock_quietly();
27
28 ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
29 ThreadSimpleImpl *thread = manager->get_current_thread();
30 manager->enqueue_block(thread, this);
31 manager->next_context();
32
33 _mutex.lock();
34}
35
36/**
37 *
38 */
39void ConditionVarSimpleImpl::
40wait(double timeout) {
41 _mutex.unlock_quietly();
42
43 // TODO. For now this will release every frame, since we don't have an
44 // interface yet on ThreadSimpleManager to do a timed wait. Maybe that's
45 // good enough forever (it does satisfy the condition variable semantics,
46 // after all).
47 ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
48 ThreadSimpleImpl *thread = manager->get_current_thread();
49 manager->enqueue_ready(thread, true);
50 manager->next_context();
51
52 _mutex.lock();
53}
54
55/**
56 *
57 */
58void ConditionVarSimpleImpl::
59do_notify() {
60 ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
61 if (manager->unblock_one(this)) {
62 // There had been a thread waiting on this condition variable. Switch
63 // contexts immediately, to make fairness more likely.
64 ThreadSimpleImpl *thread = manager->get_current_thread();
65 manager->enqueue_ready(thread, false);
66 manager->next_context();
67 }
68}
69
70/**
71 *
72 */
73void ConditionVarSimpleImpl::
74do_notify_all() {
75 ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
76 if (manager->unblock_all(this)) {
77 // There had been a thread waiting on this condition variable. Switch
78 // contexts immediately, to make fairness more likely.
79 ThreadSimpleImpl *thread = manager->get_current_thread();
80 manager->enqueue_ready(thread, false);
81 manager->next_context();
82 }
83}
84
85#endif // THREAD_SIMPLE_IMPL
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.