(file) Return to Semaphore.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 martin 1.11 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.12 //
  3 martin 1.11 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.12 //
 10 martin 1.11 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.12 //
 17 martin 1.11 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.12 //
 20 martin 1.11 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.12 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.11 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.12 //
 28 martin 1.11 //////////////////////////////////////////////////////////////////////////
 29 mike   1.2  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32             #ifndef Pegasus_Semaphore_h
 33             #define Pegasus_Semaphore_h
 34             
 35             #include <Pegasus/Common/Config.h>
 36             #include <Pegasus/Common/Linkage.h>
 37             #include <Pegasus/Common/Threads.h>
 38             
 39             //==============================================================================
 40             //
 41             // Select sempahore implementation by defining one of these:
 42             //
 43             //    PEGASUS_USE_POSIX_SEMAPHORE
 44             //    PEGASUS_USE_PTHREAD_SEMAPHORE
 45             //    PEGASUS_USE_WINDOWS_SEMAPHORE
 46             //
 47             //==============================================================================
 48             
 49 r.kieninger 1.10 #if defined(PEGASUS_OS_ZOS) || \
 50 mike        1.2      defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) || \
 51 ouyang.jian 1.5      defined(PEGASUS_PLATFORM_PASE_ISERIES_IBMCXX) || \
 52 mike        1.4      defined(PEGASUS_OS_DARWIN) || \
 53 mike        1.2      defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || \
 54                      defined(PEGASUS_PLATFORM_VMS_IA64_DECCXX) || \
 55                      defined(PEGASUS_PLATFORM_VMS_ALPHA_DECCXX)
 56                  # define PEGASUS_USE_PTHREAD_SEMAPHORE
 57                  #elif defined(PEGASUS_OS_TYPE_WINDOWS)
 58                  # define PEGASUS_USE_WINDOWS_SEMAPHORE
 59                  #else
 60                  # define PEGASUS_USE_POSIX_SEMAPHORE
 61                  #endif
 62                  
 63                  #if defined(PEGASUS_USE_POSIX_SEMAPHORE)
 64                  # include <semaphore.h>
 65                  #endif
 66                  
 67                  PEGASUS_NAMESPACE_BEGIN
 68                  
 69                  //==============================================================================
 70                  //
 71                  // SemaphoreRep
 72                  //
 73                  //==============================================================================
 74 mike        1.2  
 75                  #if defined(PEGASUS_USE_PTHREAD_SEMAPHORE)
 76                  struct SemaphoreRep
 77                  {
 78 kumpf       1.9      int count;
 79 mike        1.2      Uint32 waiters;
 80                      pthread_mutex_t mutex;
 81                      pthread_cond_t cond;
 82                      ThreadType owner;
 83                  };
 84                  #endif /* PEGASUS_USE_PTHREAD_SEMAPHORE */
 85                  
 86                  #if defined(PEGASUS_USE_POSIX_SEMAPHORE)
 87                  struct SemaphoreRep
 88                  {
 89                      sem_t sem;
 90                      ThreadType owner;
 91                  };
 92                  #endif /* defined(PEGASUS_USE_POSIX_SEMAPHORE) */
 93                  
 94                  #if defined(PEGASUS_USE_WINDOWS_SEMAPHORE)
 95                  struct SemaphoreRep
 96                  {
 97                      HANDLE sem;
 98                      ThreadType owner;
 99                  };
100 mike        1.2  #endif /* PEGASUS_USE_WINDOWS_SEMAPHORE */
101                  
102                  //==============================================================================
103                  //
104                  // Semaphore
105                  //
106                  //==============================================================================
107                  
108                  class PEGASUS_COMMON_LINKAGE Semaphore
109                  {
110                  public:
111                  
112                      /** Creates a semaphore and sets its initial value as specified.
113                          @param initial The initial value for the Semaphore (defaults to 1).
114                      */
115                      Semaphore(Uint32 initial = 1);
116                  
117                      /** Destructor.
118                      */
119                      ~Semaphore();
120                  
121 kumpf       1.7      /** Blocks until this Semaphore is in a signalled state.  Interrupt
122                          signals are ignored.
123 kumpf       1.9          @exception Exception If unable to block on the semaphore.
124 mike        1.2      */
125 kumpf       1.7      void wait();
126 mike        1.2  
127                      /** Waits for the Semaphore to be signalled for a specified time interval.
128                          This method returns normally if the Semaphore has a non-zero count or
129                          it is signalled during the specified time interval.
130                          @param milliseconds The time interval to wait (in milliseconds).
131 kumpf       1.8          @return True if the Semaphore has a non-zero count or is signalled
132                              during the specified time interval, false otherwise.
133 mike        1.2      */
134 kumpf       1.8      Boolean time_wait(Uint32 milliseconds);
135 mike        1.2  
136                      /** Increments the count of the semaphore.
137                      */
138                      void signal();
139                  
140                  private:
141                  
142                      Semaphore(const Semaphore& x); // Unimplemented
143                      Semaphore& operator=(const Semaphore& x); // Unimplemented
144                  
145                      mutable SemaphoreRep _rep;
146                      friend class Condition;
147                  };
148                  
149                  PEGASUS_NAMESPACE_END
150                  
151                  #endif /* Pegasus_Semaphore_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2