Open Dynamics Engine
threading_fake_sync.h
1 /*************************************************************************
2  * *
3  * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
4  * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5  * *
6  * Threading fake synchronization objects file. *
7  * Copyright (C) 2011-2012 Oleh Derevenko. All rights reserved. *
8  * e-mail: odar@eleks.com (change all "a" to "e") *
9  * *
10  * This library is free software; you can redistribute it and/or *
11  * modify it under the terms of EITHER: *
12  * (1) The GNU Lesser General Public License as published by the Free *
13  * Software Foundation; either version 2.1 of the License, or (at *
14  * your option) any later version. The text of the GNU Lesser *
15  * General Public License is included with this library in the *
16  * file LICENSE.TXT. *
17  * (2) The BSD-style license that is included with this library in *
18  * the file LICENSE-BSD.TXT. *
19  * *
20  * This library is distributed in the hope that it will be useful, *
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
23  * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
24  * *
25  *************************************************************************/
26 
27 /*
28  * Self-wakeup implementation for built-in threading support provider.
29  * Fake mutex implementation for built-in threading support provider.
30  *
31  * The classes have been moved into a separate header as they are to be used
32  * in both WIN and POSIX implementations.
33  */
34 
35 
36 #ifndef _ODE_THREADING_FAKE_SYNC_H_
37 #define _ODE_THREADING_FAKE_SYNC_H_
38 
39 
40 #include <ode/odeconfig.h>
41 #include <ode/error.h>
42 
43 
44 /************************************************************************/
45 /* dxSelfWakeup class definition */
46 /************************************************************************/
47 
49 {
50 public:
51  dxSelfWakeup():
52  m_wakeup_state(false),
53  m_state_is_permanent(false)
54  {
55  }
56 
57  bool InitializeObject() { return true; }
58 
59 public:
60  void ResetWakeup() { m_wakeup_state = false; m_state_is_permanent = false; }
61  void WakeupAThread() { dIASSERT(!m_state_is_permanent); m_wakeup_state = true; } // Wakeup should not be used after permanent signal
62  void WakeupAllThreads() { m_wakeup_state = true; m_state_is_permanent = true; }
63 
64  bool WaitWakeup(const dThreadedWaitTime *timeout_time_ptr);
65 
66 private:
67  bool m_wakeup_state;
68  bool m_state_is_permanent;
69 };
70 
71 
72 bool dxSelfWakeup::WaitWakeup(const dThreadedWaitTime *timeout_time_ptr)
73 {
74  bool wait_result = m_wakeup_state;
75 
76  if (m_wakeup_state)
77  {
78  m_wakeup_state = m_state_is_permanent;
79  }
80  else
81  {
82  dICHECK(false); // Self-wakeup should only be used in cases when waiting is called after object is signaled
83  }
84 
85  return wait_result;
86 }
87 
88 
89 /************************************************************************/
90 /* Fake mutex class implementation */
91 /************************************************************************/
92 
94 {
95 public:
96  dxFakeMutex() {}
97 
98  bool InitializeObject() { return true; }
99 
100 public:
101  void LockMutex() { /* Do nothing */ }
102  bool TryLockMutex() { /* Do nothing */ return true; }
103  void UnlockMutex() { /* Do nothing */ }
104 };
105 
106 
107 /************************************************************************/
108 /* Fake lull class implementation */
109 /************************************************************************/
110 
112 {
113 public:
114  dxFakeLull() {}
115 
116  bool InitializeObject() { return true; }
117 
118 public:
119  void RegisterToLull() { /* Do nothing */ }
120  void WaitForLullAlarm() { dICHECK(false); } // Fake lull can't be waited
121  void UnregisterFromLull() { /* Do nothing */ }
122 
123  void SignalLullAlarmIfAnyRegistrants() { /* Do nothing */ }
124 };
125 
126 
127 #endif // #ifndef _ODE_THREADING_FAKE_SYNC_H_
Definition: threading_fake_sync.h:48
Definition: threading.h:154
Definition: threading_fake_sync.h:111
Definition: threading_fake_sync.h:93