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

Diff for /pegasus/src/Pegasus/Common/Semaphore.cpp between version 1.1.2.1 and 1.1.2.6

version 1.1.2.1, 2006/07/27 23:11:52 version 1.1.2.6, 2006/08/02 07:26:35
Line 33 
Line 33 
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
   #include <Pegasus/Common/Time.h>
   #include <Pegasus/Common/IPCExceptions.h>
 #include "Semaphore.h" #include "Semaphore.h"
 #include "IPCExceptions.h"  
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
   static const Uint32 PEGASUS_SEM_VALUE_MAX = 0x0000ffff;
   
 //============================================================================== //==============================================================================
 // //
 // PEGASUS_USE_PTHREAD_SEMAPHORE // PEGASUS_USE_PTHREAD_SEMAPHORE
 // //
 //============================================================================== //==============================================================================
  
 #define SEM_VALUE_MAX 0x0000FFFF  
   
 #if defined(PEGASUS_USE_PTHREAD_SEMAPHORE) #if defined(PEGASUS_USE_PTHREAD_SEMAPHORE)
  
 Semaphore::Semaphore(Uint32 initial) Semaphore::Semaphore(Uint32 initial)
Line 53 
Line 54 
     pthread_mutex_init (&_rep.mutex, NULL);     pthread_mutex_init (&_rep.mutex, NULL);
     pthread_cond_init (&_rep.cond, NULL);     pthread_cond_init (&_rep.cond, NULL);
  
     if (initial > SEM_VALUE_MAX)      if (initial > PEGASUS_SEM_VALUE_MAX)
          _count = SEM_VALUE_MAX - 1;           _count = PEGASUS_SEM_VALUE_MAX - 1;
     else     else
          _count = initial;          _count = initial;
  
Line 94 
Line 95 
 #endif #endif
 } }
  
 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)  #if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)
 // cleanup function // cleanup function
 static void semaphore_cleanup(void *arg) static void semaphore_cleanup(void *arg)
 { {
Line 113 
Line 114 
  
    // Push cleanup function onto cleanup stack    // Push cleanup function onto cleanup stack
    // The mutex will unlock if the thread is killed early    // The mutex will unlock if the thread is killed early
 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)  #if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)
     Threads::cleanup_push(&semaphore_cleanup, &_rep);     Threads::cleanup_push(&semaphore_cleanup, &_rep);
 #endif #endif
  
Line 135 
Line 136 
  
     // Since we push an unlock onto the cleanup stack     // Since we push an unlock onto the cleanup stack
    // We will pop it off to release the mutex when leaving the critical section.    // We will pop it off to release the mutex when leaving the critical section.
 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)  #if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)
    Threads::cleanup_pop(1);    Threads::cleanup_pop(1);
 #endif #endif
    // Release mutex to leave critical section.    // Release mutex to leave critical section.
Line 154 
Line 155 
    pthread_mutex_lock (&_rep.mutex);    pthread_mutex_lock (&_rep.mutex);
    Boolean timedOut = false;    Boolean timedOut = false;
  
 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || \  #if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)
     defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)  
    // Push cleanup function onto cleanup stack    // Push cleanup function onto cleanup stack
    // The mutex will unlock if the thread is killed early    // The mutex will unlock if the thread is killed early
    Thread::cleanup_push(&semaphore_cleanup, &_rep);    Thread::cleanup_push(&semaphore_cleanup, &_rep);
Line 193 
Line 193 
    // Decrement the waiters count.    // Decrement the waiters count.
    _rep.waiters--;    _rep.waiters--;
  
 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || \  #if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)
     defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX)  
    // Since we push an unlock onto the cleanup stack    // Since we push an unlock onto the cleanup stack
    // We will pop it off to release the mutex when leaving the critical section.    // We will pop it off to release the mutex when leaving the critical section.
    Threads::cleanup_pop(1);    Threads::cleanup_pop(1);
Line 242 
Line 241 
  
 Semaphore::Semaphore(Uint32 initial) Semaphore::Semaphore(Uint32 initial)
 { {
    if(initial > SEM_VALUE_MAX)     if(initial > PEGASUS_SEM_VALUE_MAX)
       initial = SEM_VALUE_MAX - 1;        initial = PEGASUS_SEM_VALUE_MAX - 1;
    sem_init(&_rep.sem,0,initial);    sem_init(&_rep.sem,0,initial);
    _rep.owner = Threads::self();    _rep.owner = Threads::self();
 } }
Line 354 
Line 353 
  
 #if defined(PEGASUS_USE_WINDOWS_SEMAPHORE) #if defined(PEGASUS_USE_WINDOWS_SEMAPHORE)
  
 static const int SEM_VALUE_MAX = 0x0000ffff;  
   
 Semaphore::Semaphore(Uint32 initial) Semaphore::Semaphore(Uint32 initial)
 { {
    if(initial > SEM_VALUE_MAX)     if(initial > PEGASUS_SEM_VALUE_MAX)
       initial = SEM_VALUE_MAX - 1;        initial = PEGASUS_SEM_VALUE_MAX - 1;
    _count = initial;    _count = initial;
    _rep.owner = (ThreadType)GetCurrentThreadId();     _rep.owner = Threads::self();
    _rep.sem = CreateSemaphore(NULL, initial, SEM_VALUE_MAX, NULL);     _rep.sem = CreateSemaphore(NULL, initial, PEGASUS_SEM_VALUE_MAX, NULL);
 } }
  
 Semaphore::~Semaphore() Semaphore::~Semaphore()
Line 378 
Line 375 
     if(errorcode != WAIT_FAILED)     if(errorcode != WAIT_FAILED)
         _count--;         _count--;
     else     else
         throw(WaitFailed((ThreadType)GetCurrentThreadId()));          throw(WaitFailed(Threads::self()));
 } }
  
 // wait succeeds immediately if semaphore has a non-zero count, // wait succeeds immediately if semaphore has a non-zero count,
Line 388 
Line 385 
 { {
     DWORD errorcode = WaitForSingleObject(_rep.sem, 0);     DWORD errorcode = WaitForSingleObject(_rep.sem, 0);
     if(errorcode == WAIT_TIMEOUT || errorcode == WAIT_FAILED)     if(errorcode == WAIT_TIMEOUT || errorcode == WAIT_FAILED)
         throw(WaitFailed((ThreadType)GetCurrentThreadId()));          throw(WaitFailed(Threads::self()));
     _count--;     _count--;
 } }
  
Line 399 
Line 396 
 { {
     DWORD errorcode = WaitForSingleObject(_rep.sem, milliseconds);     DWORD errorcode = WaitForSingleObject(_rep.sem, milliseconds);
     if (errorcode == WAIT_TIMEOUT || errorcode == WAIT_FAILED)     if (errorcode == WAIT_TIMEOUT || errorcode == WAIT_FAILED)
         throw(TimeOut((ThreadType)GetCurrentThreadId()));          throw(TimeOut(Threads::self()));
     _count--;     _count--;
 } }
  


Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.1.2.6

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2