comparison packages/kernel/current/include/sema2.hxx @ 0:3111d98ba7b3 ecos-v1_1-release

Initial commit of eCos version 1.1
author jlarmour
date Tue, 11 May 1999 11:16:07 +0000
parents
children 443894e2e912
comparison
equal deleted inserted replaced
-1:000000000000 0:3111d98ba7b3
1 #ifndef CYGONCE_KERNEL_SEMA2_HXX
2 #define CYGONCE_KERNEL_SEMA2_HXX
3
4 //==========================================================================
5 //
6 // sema2.hxx
7 //
8 // Semaphore 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 Semaphore class interfaces
39 // Description: The classes defined here provide the APIs for binary
40 // and counting semaphores.
41 // Usage: #include <cyg/kernel/sema2.hxx>
42 //
43 //
44 //####DESCRIPTIONEND####
45 //
46 //==========================================================================
47
48 #include <cyg/kernel/ktypes.h>
49 #include <cyg/infra/cyg_ass.h> // assertion macros
50 #include <cyg/kernel/thread.hxx>
51
52 #if 0
53 // THERE IS NO BINARY-SEMAPHORE-2
54
55 // -------------------------------------------------------------------------
56 // Binary semaphore. This has only two states: posted and not-posted.
57
58 class Cyg_Binary_Semaphore2
59 {
60 cyg_bool state; // The binary semaphore state
61
62 Cyg_ThreadQueue queue; // Queue of waiting threads
63
64 public:
65
66 CYGDBG_DEFINE_CHECK_THIS
67
68 Cyg_Binary_Semaphore2( // Constructor
69 cyg_bool init_state = false // Initial state value
70 );
71
72 ~Cyg_Binary_Semaphore2(); // Destructor
73
74 cyg_bool wait(); // Wait until state == true
75
76 cyg_bool trywait(); // Set state false if possible
77
78 void post(); // Increment count
79
80 cyg_bool posted(); // Get current state
81
82 };
83 #endif
84
85 // -------------------------------------------------------------------------
86 // Counting semaphore. This implements the usual counter based semaphore.
87
88 class Cyg_Counting_Semaphore2
89 {
90 cyg_count32 count; // The semaphore count
91
92 Cyg_ThreadQueue queue; // Queue of waiting threads
93
94 public:
95
96 CYGDBG_DEFINE_CHECK_THIS
97
98 Cyg_Counting_Semaphore2( // Constructor
99 cyg_count32 init_count = 0 // Initial count value
100 );
101
102 ~Cyg_Counting_Semaphore2(); // Destructor
103
104 cyg_bool wait(); // Wait until decrement
105
106 #ifdef CYGFUN_KERNEL_THREADS_TIMER
107 cyg_bool wait( cyg_tick_count abs_timeout );
108 #endif // Wait until decrement or timeout
109
110 cyg_bool trywait(); // Try to decrement
111
112 void post(); // Increment count
113
114 cyg_count32 peek(); // Get current count value
115
116 inline
117 cyg_bool waiting() // Is anyone waiting?
118 {
119 return !queue.empty();
120 }
121
122 };
123
124 // -------------------------------------------------------------------------
125 #endif // ifndef CYGONCE_KERNEL_SEMA2_HXX
126 // EOF sema2.hxx