![]() ![]() |
![]() |
1 mike 1.2 //%2006//////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development 4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. 5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; 6 // IBM Corp.; EMC Corporation, The Open Group. 7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; 8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. 9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; 10 // EMC Corporation; VERITAS Software Corporation; The Open Group. 11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; 12 // EMC Corporation; Symantec Corporation; The Open Group. 13 // 14 // Permission is hereby granted, free of charge, to any person obtaining a copy 15 // of this software and associated documentation files (the "Software"), to 16 // deal in the Software without restriction, including without limitation the 17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 18 // sell copies of the Software, and to permit persons to whom the Software is 19 // furnished to do so, subject to the following conditions: 20 // 21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 22 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED 23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 // 30 //============================================================================== 31 // 32 //%///////////////////////////////////////////////////////////////////////////// 33 34 #ifndef Pegasus_Semaphore_h 35 #define Pegasus_Semaphore_h 36 37 #include <Pegasus/Common/Config.h> 38 #include <Pegasus/Common/Linkage.h> 39 #include <Pegasus/Common/Threads.h> 40 41 //============================================================================== 42 // 43 mike 1.2 // Select sempahore implementation by defining one of these: 44 // 45 // PEGASUS_USE_POSIX_SEMAPHORE 46 // PEGASUS_USE_PTHREAD_SEMAPHORE 47 // PEGASUS_USE_WINDOWS_SEMAPHORE 48 // 49 //============================================================================== 50 51 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || \ 52 defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) || \ | ||
53 ouyang.jian 1.5 defined(PEGASUS_PLATFORM_PASE_ISERIES_IBMCXX) || \ | ||
54 mike 1.4 defined(PEGASUS_OS_DARWIN) || \ | ||
55 mike 1.2 defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || \ 56 defined(PEGASUS_PLATFORM_VMS_IA64_DECCXX) || \ 57 defined(PEGASUS_PLATFORM_VMS_ALPHA_DECCXX) 58 # define PEGASUS_USE_PTHREAD_SEMAPHORE 59 #elif defined(PEGASUS_OS_TYPE_WINDOWS) 60 # define PEGASUS_USE_WINDOWS_SEMAPHORE 61 #else 62 # define PEGASUS_USE_POSIX_SEMAPHORE 63 #endif 64 65 #if defined(PEGASUS_USE_POSIX_SEMAPHORE) 66 # include <semaphore.h> 67 #endif 68 69 PEGASUS_NAMESPACE_BEGIN 70 71 //============================================================================== 72 // 73 // SemaphoreRep 74 // 75 //============================================================================== 76 mike 1.2 77 #if defined(PEGASUS_USE_PTHREAD_SEMAPHORE) 78 struct SemaphoreRep 79 { 80 Uint32 waiters; 81 pthread_mutex_t mutex; 82 pthread_cond_t cond; 83 ThreadType owner; 84 }; 85 #endif /* PEGASUS_USE_PTHREAD_SEMAPHORE */ 86 87 #if defined(PEGASUS_USE_POSIX_SEMAPHORE) 88 struct SemaphoreRep 89 { 90 sem_t sem; 91 ThreadType owner; 92 }; 93 #endif /* defined(PEGASUS_USE_POSIX_SEMAPHORE) */ 94 95 #if defined(PEGASUS_USE_WINDOWS_SEMAPHORE) 96 struct SemaphoreRep 97 mike 1.2 { 98 HANDLE sem; 99 ThreadType owner; 100 }; 101 #endif /* PEGASUS_USE_WINDOWS_SEMAPHORE */ 102 103 //============================================================================== 104 // 105 // Semaphore 106 // 107 //============================================================================== 108 109 class PEGASUS_COMMON_LINKAGE Semaphore 110 { 111 public: 112 113 /** Creates a semaphore and sets its initial value as specified. 114 @param initial The initial value for the Semaphore (defaults to 1). 115 */ 116 Semaphore(Uint32 initial = 1); 117 118 mike 1.2 /** Destructor. 119 */ 120 ~Semaphore(); 121 | ||
122 kumpf 1.7 /** Blocks until this Semaphore is in a signalled state. Interrupt 123 signals are ignored. | ||
124 mike 1.2 @exception WaitFailed If unable to block on the semaphore. 125 */ | ||
126 kumpf 1.7 void wait(); | ||
127 mike 1.2 128 /** Waits for the Semaphore to be signalled for a specified time interval. 129 This method returns normally if the Semaphore has a non-zero count or 130 it is signalled during the specified time interval. 131 @param milliseconds The time interval to wait (in milliseconds). | ||
132 kumpf 1.8 @return True if the Semaphore has a non-zero count or is signalled 133 during the specified time interval, false otherwise. | ||
134 mike 1.2 @exception TimeOut If the wait operation does not succeed within 135 the specified time interval. 136 */ | ||
137 kumpf 1.8 Boolean time_wait(Uint32 milliseconds); | ||
138 mike 1.2 139 /** Increments the count of the semaphore. 140 */ 141 void signal(); 142 143 /** Return the count of the semaphore. 144 */ 145 int count() const; 146 147 private: 148 149 Semaphore(const Semaphore& x); // Unimplemented 150 Semaphore& operator=(const Semaphore& x); // Unimplemented 151 152 mutable int _count; 153 mutable SemaphoreRep _rep; 154 friend class Condition; 155 }; 156 157 PEGASUS_NAMESPACE_END 158 159 mike 1.2 #endif /* Pegasus_Semaphore_h */ |
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |