|
0
|
1 #ifndef CYGONCE_KERNEL_MUTEX_HXX |
|
|
2 #define CYGONCE_KERNEL_MUTEX_HXX |
|
|
3 |
|
|
4 //========================================================================== |
|
|
5 // |
|
|
6 // mutex.hxx |
|
|
7 // |
|
|
8 // Mutex class declarations |
|
|
9 // |
|
|
10 //========================================================================== |
|
|
11 //####COPYRIGHTBEGIN#### |
|
|
12 // |
|
|
13 // ------------------------------------------- |
|
|
14 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
15 // Version 1.0 (the "License"); you may not use this file except in |
|
|
16 // compliance with the License. You may obtain a copy of the License at |
|
|
17 // http://sourceware.cygnus.com/ecos |
|
|
18 // |
|
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
21 // License for the specific language governing rights and limitations under |
|
|
22 // the License. |
|
|
23 // |
|
|
24 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
25 // September 30, 1998. |
|
|
26 // |
|
|
27 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
28 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
29 // ------------------------------------------- |
|
|
30 // |
|
|
31 //####COPYRIGHTEND#### |
|
|
32 //========================================================================== |
|
|
33 //#####DESCRIPTIONBEGIN#### |
|
|
34 // |
|
|
35 // Author(s): nickg |
|
|
36 // Contributors: nickg |
|
|
37 // Date: 1997-09-09 |
|
|
38 // Purpose: Define Mutex class interfaces |
|
|
39 // Description: The classes defined here provide the APIs for mutexes |
|
|
40 // and condition variables. |
|
|
41 // Usage: #include <cyg/kernel/mutex.hxx> |
|
|
42 // |
|
|
43 // |
|
|
44 //####DESCRIPTIONEND#### |
|
|
45 // |
|
|
46 //========================================================================== |
|
|
47 |
|
|
48 #include <cyg/kernel/ktypes.h> |
|
|
49 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
50 |
|
|
51 #include <cyg/kernel/thread.hxx> |
|
|
52 |
|
|
53 // ------------------------------------------------------------------------- |
|
|
54 // Mutex. |
|
|
55 |
|
|
56 class Cyg_Mutex |
|
|
57 { |
|
|
58 friend class Cyg_Condition_Variable; |
|
|
59 |
|
|
60 cyg_atomic locked; // true if locked |
|
|
61 |
|
|
62 Cyg_Thread *owner; // Current locking thread |
|
|
63 |
|
|
64 Cyg_ThreadQueue queue; // Queue of waiting threads |
|
|
65 |
|
|
66 public: |
|
|
67 |
|
|
68 CYGDBG_DEFINE_CHECK_THIS |
|
|
69 |
|
|
70 Cyg_Mutex(); // Create in unlocked state |
|
|
71 |
|
|
72 ~Cyg_Mutex(); // Destructor |
|
|
73 |
|
|
74 cyg_bool lock(); // lock and/or wait |
|
|
75 |
|
|
76 cyg_bool trylock(); // try to lock and return success |
|
|
77 |
|
|
78 void unlock(); // unlock |
|
|
79 |
|
|
80 }; |
|
|
81 |
|
|
82 // ------------------------------------------------------------------------- |
|
|
83 // Condition variable. |
|
|
84 |
|
|
85 class Cyg_Condition_Variable |
|
|
86 { |
|
|
87 Cyg_Mutex *mutex; // Associated mutex |
|
|
88 |
|
|
89 Cyg_ThreadQueue queue; // Queue of waiting threads |
|
|
90 |
|
|
91 public: |
|
|
92 |
|
|
93 CYGDBG_DEFINE_CHECK_THIS |
|
|
94 |
|
|
95 Cyg_Condition_Variable( |
|
|
96 Cyg_Mutex &mutex // linked mutex |
|
|
97 ); |
|
|
98 |
|
|
99 ~Cyg_Condition_Variable(); // Destructor |
|
|
100 |
|
|
101 void wait(); // Wait for condition to be true |
|
|
102 |
|
|
103 void signal(); // Set cond true, wake one thread |
|
|
104 |
|
|
105 void broadcast(); // Set cond true, wake all threads |
|
|
106 |
|
|
107 #ifdef CYGMFN_KERNEL_SYNCH_CONDVAR_TIMED_WAIT |
|
|
108 |
|
|
109 // Wait until a signal or timeout expiry |
|
|
110 cyg_bool wait( cyg_tick_count timeout ); |
|
|
111 |
|
|
112 #endif |
|
|
113 |
|
|
114 }; |
|
|
115 |
|
|
116 |
|
|
117 // ------------------------------------------------------------------------- |
|
|
118 |
|
|
119 #endif // ifndef CYGONCE_KERNEL_MUTEX_HXX |
|
|
120 // EOF mutex.hxx |