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

Diff for /pegasus/src/Pegasus/Common/ReadWriteSem.cpp between version 1.1.2.6 and 1.5.4.1

version 1.1.2.6, 2006/07/28 21:19:53 version 1.5.4.1, 2008/02/21 06:33:19
Line 29 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Day (mdday@us.ibm.com)  
 //  
 // Reworked By: Mike Brasher (m.brasher@inovadevelopment.com)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include "ReadWriteSem.h" #include "ReadWriteSem.h"
 #include "Time.h" #include "Time.h"
 #include "PegasusAssert.h" #include "PegasusAssert.h"
   #include "Threads.h"
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
   
 //============================================================================== //==============================================================================
 // //
 // PEGASUS_USE_POSIX_RWLOCK // PEGASUS_USE_POSIX_RWLOCK
 // //
 //============================================================================== //==============================================================================
   
 #ifdef PEGASUS_USE_POSIX_RWLOCK #ifdef PEGASUS_USE_POSIX_RWLOCK
   
 ReadWriteSem::ReadWriteSem():_readers(0), _writers(0) ReadWriteSem::ReadWriteSem():_readers(0), _writers(0)
 { {
     pthread_rwlock_init(&_rwlock.rwlock, NULL);     pthread_rwlock_init(&_rwlock.rwlock, NULL);
Line 54 
Line 54 
  
 ReadWriteSem::~ReadWriteSem() ReadWriteSem::~ReadWriteSem()
 { {
       int r = 0;
     while (EBUSY == pthread_rwlock_destroy(&_rwlock.rwlock))      while ((r=pthread_rwlock_destroy(&_rwlock.rwlock)) == EBUSY ||
              (r == -1 && errno == EBUSY))
     {     {
         Threads::yield();         Threads::yield();
     }     }
Line 112 
Line 113 
     }     }
     else     else
         throw(Permission(Threads::self()));         throw(Permission(Threads::self()));
       if (errorcode == -1)
           errorcode = errno;
     if (errorcode == EBUSY)     if (errorcode == EBUSY)
         throw(AlreadyLocked(_rwlock.owner));         throw(AlreadyLocked(_rwlock.owner));
     else if (errorcode == EDEADLK)     else if (errorcode == EDEADLK)
Line 127 
Line 129 
 void ReadWriteSem::timed_wait(Uint32 mode, void ReadWriteSem::timed_wait(Uint32 mode,
                               ThreadType caller, int milliseconds)                               ThreadType caller, int milliseconds)
 { {
     int errorcode = 0, timeout;      int errorcode = 0, timeout = 0;
     struct timeval now, finish, remaining;     struct timeval now, finish, remaining;
     Uint32 usec;     Uint32 usec;
  
Line 143 
Line 145 
         do         do
         {         {
             errorcode = pthread_rwlock_tryrdlock(&_rwlock.rwlock);             errorcode = pthread_rwlock_tryrdlock(&_rwlock.rwlock);
               if (errorcode == -1)
                   errorcode = errno;
             gettimeofday(&now, NULL);             gettimeofday(&now, NULL);
         }         }
         while (errorcode == EBUSY &&         while (errorcode == EBUSY &&
Line 158 
Line 162 
         do         do
         {         {
             errorcode = pthread_rwlock_trywrlock(&_rwlock.rwlock);             errorcode = pthread_rwlock_trywrlock(&_rwlock.rwlock);
               if (errorcode == -1)
                   errorcode = errno;
             gettimeofday(&now, NULL);             gettimeofday(&now, NULL);
         }         }
         while (errorcode == EBUSY &&         while (errorcode == EBUSY &&
Line 202 
Line 208 
  
 int ReadWriteSem::read_count() const int ReadWriteSem::read_count() const
 { {
 #if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)      return _readers.get();
     PEGASUS_ASSERT(_readers.get() == _rwlock.rwlock.__rw_readers);  
 #endif  
     return (_readers.get());  
 } }
  
 int ReadWriteSem::write_count() const int ReadWriteSem::write_count() const
 { {
 #if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)      return _writers.get();
     if (_rwlock.rwlock.__rw_writer != NULL)  
     {  
         PEGASUS_ASSERT(_writers.get() == 1);  
     }  
 #endif  
     return (_writers.get());  
 } }
  
 #endif /* PEGASUS_USE_POSIX_RWLOCK */ #endif /* PEGASUS_USE_POSIX_RWLOCK */
Line 234 
Line 231 
 // 2) I do not hold the write lock // 2) I do not hold the write lock
 // 3) I am not using a reader slot // 3) I am not using a reader slot
  
   #if 0
 void extricate_read_write(void *parm) void extricate_read_write(void *parm)
 { {
     ReadWriteSem *rws = (ReadWriteSem *) parm;     ReadWriteSem *rws = (ReadWriteSem *) parm;
Line 247 
Line 245 
     if (Threads::equal(rws->_rwlock._internal_lock.get_owner(), myself))     if (Threads::equal(rws->_rwlock._internal_lock.get_owner(), myself))
         rws->_rwlock._internal_lock.unlock();         rws->_rwlock._internal_lock.unlock();
 } }
   #endif
  
  
 ReadWriteSem::ReadWriteSem():_readers(0), _writers(0), _rwlock() ReadWriteSem::ReadWriteSem():_readers(0), _writers(0), _rwlock()
Line 258 
Line 257 
     // lock everyone out of this object     // lock everyone out of this object
     try     try
     {     {
         _rwlock._internal_lock.lock(Threads::self());          _rwlock._internal_lock.lock();
     }     }
     catch(Deadlock & d)      catch (Deadlock &)
     {     {
         d = d;                  // no problem - we own the lock, which is          // no problem - we own the lock, which is what we want
                                 // what we want  
     }     }
     catch(IPCException &)     catch(IPCException &)
     {     {
Line 288 
Line 286 
 void ReadWriteSem::timed_wait(Uint32 mode, ThreadType caller, void ReadWriteSem::timed_wait(Uint32 mode, ThreadType caller,
                               int milliseconds)                               int milliseconds)
 { {
   
 //----------------------------------------------------------------- //-----------------------------------------------------------------
 // Lock this object to maintain integrity while we decide // Lock this object to maintain integrity while we decide
 // exactly what to do next. // exactly what to do next.
Line 307 
Line 304 
  
     // cleanup stack frame     // cleanup stack frame
     {     {
           // Threads::cleanup_push(extricate_read_write, this);
         Threads::cleanup_push(extricate_read_write, this);  
  
         try         try
         {         {
             if (milliseconds == 0)             if (milliseconds == 0)
                 _rwlock._internal_lock.try_lock(Threads::self());                  _rwlock._internal_lock.try_lock();
             else if (milliseconds == -1)             else if (milliseconds == -1)
                 _rwlock._internal_lock.lock(Threads::self());                  _rwlock._internal_lock.lock();
             else             else
                 _rwlock._internal_lock.timed_lock(milliseconds,                  _rwlock._internal_lock.timed_lock(milliseconds);
                                                   Threads::self());  
         }         }
         catch(const IPCException & e)         catch(const IPCException & e)
         {         {
Line 375 
Line 370 
             {             {
                 try                 try
                 {                 {
                     _rwlock._wlock.try_lock(Threads::self());                      _rwlock._wlock.try_lock();
                 }                 }
                 catch(IPCException & e)                 catch(IPCException & e)
                 {                 {
Line 388 
Line 383 
             {             {
                 try                 try
                 {                 {
                     _rwlock._wlock.lock(Threads::self());                      _rwlock._wlock.lock();
                 }                 }
                 catch(const IPCException & e)                 catch(const IPCException & e)
                 {                 {
Line 401 
Line 396 
             {             {
                 try                 try
                 {                 {
                     _rwlock._wlock.timed_lock(milliseconds, Threads::self());                      _rwlock._wlock.timed_lock(milliseconds);
                 }                 }
                 catch(const IPCException & e)                 catch(const IPCException & e)
                 {                 {
Line 523 
Line 518 
         Threads::cleanup_pop(0);         Threads::cleanup_pop(0);
     }     }
  
     if (Threads::id(caught.get_owner()) != 0)      if (!Threads::null(caught.get_owner()))
         throw caught;         throw caught;
     if (Threads::id(caughtWaitFailed.get_owner()) != 0)      if (!Threads::null(caughtWaitFailed.get_owner()))
         throw caughtWaitFailed;         throw caughtWaitFailed;
     if (Threads::id(caughtTimeOut.get_owner()) != 0)      if (!Threads::null(caughtTimeOut.get_owner()))
         throw caughtTimeOut;         throw caughtTimeOut;
     if (Threads::id(caughtTooManyReaders.get_owner()) != 0)      if (!Threads::null(caughtTooManyReaders.get_owner()))
   
         throw caughtTooManyReaders;         throw caughtTooManyReaders;
     return;     return;
 } }
Line 562 
Line 558 
  
 int ReadWriteSem::read_count() const int ReadWriteSem::read_count() const
 { {
     return (_readers.get());      return _readers.get();
 } }
  
 int ReadWriteSem::write_count() const int ReadWriteSem::write_count() const
 { {
     return (_writers.get());      return _writers.get();
 } }
  
 #endif /* !PEGASUS_USE_SEMAPHORE_RWLOCK */ #endif /* !PEGASUS_USE_SEMAPHORE_RWLOCK */


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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2