Panda3D
mutexSimpleImpl.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 mutexSimpleImpl.cxx
10  * @author drose
11  * @date 2007-06-19
12  */
13 
14 #include "selectThreadImpl.h"
15 
16 #ifdef THREAD_SIMPLE_IMPL
17 
18 #include "mutexSimpleImpl.h"
19 #include "threadSimpleImpl.h"
20 #include "threadSimpleManager.h"
21 
22 /**
23  *
24  */
25 void MutexSimpleImpl::
26 do_lock() {
27  // By the time we get here, we already know that someone else is holding the
28  // lock: (_flags & F_lock_count) != 0.
29  ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
30  ThreadSimpleImpl *thread = manager->get_current_thread();
31 
32  while ((_flags & F_lock_count) != 0) {
33  manager->enqueue_block(thread, this);
34  manager->next_context();
35  }
36 
37  _flags |= F_lock_count;
38 }
39 
40 /**
41  *
42  */
43 void MutexSimpleImpl::
44 do_unlock() {
45  // By the time we get here, we already know that someone else is blocked on
46  // this mutex: (_flags & F_waiters) != 0.
47  ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
48  if (manager->unblock_one(this)) {
49  // There had been a thread waiting on this mutex. Switch contexts
50  // immediately, to make fairness more likely.
51  ThreadSimpleImpl *thread = manager->get_current_thread();
52  manager->enqueue_ready(thread, false);
53  manager->next_context();
54  }
55 }
56 
57 /**
58  *
59  */
60 void MutexSimpleImpl::
61 do_unlock_quietly() {
62  ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
63  manager->unblock_one(this);
64 }
65 
66 #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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.