Mercurial > flash_v2
annotate packages/kernel/current/include/sema.hxx @ 64:c38311975d4f ecos-sw-2000-01-28
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
| author | jlarmour |
|---|---|
| date | Fri, 28 Jan 2000 04:59:39 +0000 |
| parents | 443894e2e912 |
| children | bf00f99aec69 |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_SEMA_HXX |
| 2 #define CYGONCE_KERNEL_SEMA_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // sema.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 |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // Version 1.0 (the "License"); you may not use this file except in |
|
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 |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // http://sourceware.cygnus.com/ecos |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // Software distributed under the License is distributed on an |
|
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/sema.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 // ------------------------------------------------------------------------- | |
| 55 // Binary semaphore. This has only two states: posted and not-posted. | |
| 56 | |
| 57 class Cyg_Binary_Semaphore | |
| 58 { | |
| 59 cyg_bool state; // The binary semaphore state | |
| 60 | |
| 61 Cyg_ThreadQueue queue; // Queue of waiting threads | |
| 62 | |
| 63 public: | |
| 64 | |
| 65 CYGDBG_DEFINE_CHECK_THIS | |
| 66 | |
| 67 Cyg_Binary_Semaphore( // Constructor | |
| 68 cyg_bool init_state = false // Initial state value | |
| 69 ); | |
| 70 | |
| 71 ~Cyg_Binary_Semaphore(); // Destructor | |
| 72 | |
| 73 cyg_bool wait(); // Wait until state == true | |
| 74 | |
| 75 cyg_bool trywait(); // Set state false if possible | |
| 76 | |
| 77 void post(); // Increment count | |
| 78 | |
| 79 cyg_bool posted(); // Get current state | |
| 80 | |
| 81 }; | |
| 82 | |
| 83 // ------------------------------------------------------------------------- | |
| 84 // Counting semaphore. This implements the usual counter based semaphore. | |
| 85 | |
| 86 class Cyg_Counting_Semaphore | |
| 87 { | |
| 88 cyg_count32 count; // The semaphore count | |
| 89 | |
| 90 Cyg_ThreadQueue queue; // Queue of waiting threads | |
| 91 | |
| 92 public: | |
| 93 | |
| 94 CYGDBG_DEFINE_CHECK_THIS | |
| 95 | |
| 96 Cyg_Counting_Semaphore( // Constructor | |
| 97 cyg_count32 init_count = 0 // Initial count value | |
| 98 ); | |
| 99 | |
| 100 ~Cyg_Counting_Semaphore(); // Destructor | |
| 101 | |
| 102 cyg_bool wait(); // Wait until decrement | |
| 103 | |
| 104 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 105 cyg_bool wait( cyg_tick_count timeout ); | |
| 106 #endif // Wait until decrement or timeout | |
| 107 | |
| 108 cyg_bool trywait(); // Try to decrement | |
| 109 | |
| 110 void post(); // Increment count | |
| 111 | |
| 112 cyg_count32 peek(); // Get current count value | |
| 113 | |
| 114 inline | |
| 2 | 115 cyg_bool waiting() // Is anyone waiting? |
| 0 | 116 { |
| 117 return !queue.empty(); | |
| 118 } | |
| 119 | |
| 120 }; | |
| 121 | |
| 122 // ------------------------------------------------------------------------- | |
| 123 #endif // ifndef CYGONCE_KERNEL_SEMA_HXX | |
| 124 // EOF sema.hxx |
