Mercurial > flash_v2
annotate packages/kernel/current/include/sema2.hxx @ 124:0ec04793409a ecos-sw-2000-09-11
Merge from eCos master repository on 2000-09-11-03:00:13-BST
| author | jlarmour |
|---|---|
| date | Mon, 11 Sep 2000 02:42:46 +0000 |
| parents | 6ed91473a1cd |
| children | e0c0827131d1 |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_SEMA2_HXX |
| 2 #define CYGONCE_KERNEL_SEMA2_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // sema2.hxx |
| 0 | 7 // |
| 2 | 8 // Semaphore class declarations |
| 0 | 9 // |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
12 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
14 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
15 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
16 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
17 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
30 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
31 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
32 // |
| 0 | 33 //####COPYRIGHTEND#### |
| 34 //========================================================================== | |
| 35 //#####DESCRIPTIONBEGIN#### | |
| 36 // | |
| 2 | 37 // Author(s): nickg |
| 38 // Contributors: nickg | |
| 39 // Date: 1997-09-09 | |
| 40 // Purpose: Define Semaphore class interfaces | |
| 41 // Description: The classes defined here provide the APIs for binary | |
| 0 | 42 // and counting semaphores. |
| 2 | 43 // Usage: #include <cyg/kernel/sema2.hxx> |
| 44 // | |
| 0 | 45 // |
| 46 //####DESCRIPTIONEND#### | |
| 47 // | |
| 48 //========================================================================== | |
| 49 | |
| 50 #include <cyg/kernel/ktypes.h> | |
| 51 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 52 #include <cyg/kernel/thread.hxx> | |
| 53 | |
| 54 #if 0 | |
| 55 // THERE IS NO BINARY-SEMAPHORE-2 | |
| 56 | |
| 57 // ------------------------------------------------------------------------- | |
| 58 // Binary semaphore. This has only two states: posted and not-posted. | |
| 59 | |
| 60 class Cyg_Binary_Semaphore2 | |
| 61 { | |
| 62 cyg_bool state; // The binary semaphore state | |
| 63 | |
| 64 Cyg_ThreadQueue queue; // Queue of waiting threads | |
| 65 | |
| 66 public: | |
| 67 | |
| 68 CYGDBG_DEFINE_CHECK_THIS | |
| 69 | |
| 70 Cyg_Binary_Semaphore2( // Constructor | |
| 71 cyg_bool init_state = false // Initial state value | |
| 72 ); | |
| 73 | |
| 74 ~Cyg_Binary_Semaphore2(); // Destructor | |
| 75 | |
| 76 cyg_bool wait(); // Wait until state == true | |
| 77 | |
| 78 cyg_bool trywait(); // Set state false if possible | |
| 79 | |
| 80 void post(); // Increment count | |
| 81 | |
| 82 cyg_bool posted(); // Get current state | |
| 83 | |
| 84 }; | |
| 85 #endif | |
| 86 | |
| 87 // ------------------------------------------------------------------------- | |
| 88 // Counting semaphore. This implements the usual counter based semaphore. | |
| 89 | |
| 90 class Cyg_Counting_Semaphore2 | |
| 91 { | |
| 92 cyg_count32 count; // The semaphore count | |
| 93 | |
| 94 Cyg_ThreadQueue queue; // Queue of waiting threads | |
| 95 | |
| 96 public: | |
| 97 | |
| 98 CYGDBG_DEFINE_CHECK_THIS | |
| 99 | |
| 100 Cyg_Counting_Semaphore2( // Constructor | |
| 101 cyg_count32 init_count = 0 // Initial count value | |
| 102 ); | |
| 103 | |
| 104 ~Cyg_Counting_Semaphore2(); // Destructor | |
| 105 | |
| 106 cyg_bool wait(); // Wait until decrement | |
| 107 | |
| 108 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 109 cyg_bool wait( cyg_tick_count abs_timeout ); | |
| 110 #endif // Wait until decrement or timeout | |
| 111 | |
| 112 cyg_bool trywait(); // Try to decrement | |
| 113 | |
| 114 void post(); // Increment count | |
| 115 | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
116 cyg_count32 peek() const; // Get current count value |
| 0 | 117 |
| 118 inline | |
| 2 | 119 cyg_bool waiting() // Is anyone waiting? |
| 0 | 120 { |
| 121 return !queue.empty(); | |
| 122 } | |
| 123 | |
| 124 }; | |
| 125 | |
| 126 // ------------------------------------------------------------------------- | |
| 127 #endif // ifndef CYGONCE_KERNEL_SEMA2_HXX | |
| 128 // EOF sema2.hxx |
