diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-10-16 03:06:15 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-10-16 03:06:15 +0000 |
commit | f009b2be9fd50c90ad36fea9a2a1997f6ed1e232 (patch) | |
tree | 057c7ac54ac178a728955baa8a44fc5d5431ec21 | |
parent | cd80247e4a6cf2a5deaf6998d4ef43104270e739 (diff) | |
download | ATCD-f009b2be9fd50c90ad36fea9a2a1997f6ed1e232.tar.gz |
*** empty log message ***
-rw-r--r-- | ChangeLog-97b | 19 | ||||
-rw-r--r-- | ace/OS.h | 4 | ||||
-rw-r--r-- | ace/OS.i | 38 | ||||
-rw-r--r-- | ace/Synch.h | 113 |
4 files changed, 136 insertions, 38 deletions
diff --git a/ChangeLog-97b b/ChangeLog-97b index 780070be1d5..e8377ad4b93 100644 --- a/ChangeLog-97b +++ b/ChangeLog-97b @@ -1,5 +1,24 @@ Wed Oct 15 11:07:47 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> + * ace/OS.i: Fixed the flock_trywrlock() and flock_tryrdlock() so + that they both set errno = EBUSY if they lock is already held. + + * ace/OS.i (mutex_trylock): Make the VxWorks version consistent + with the other versions by returning -1 and setting errno to + EBUSY. Thanks to David Levine for reporting this. + + * ace/Synch.h: Updated the documentation to clarify what the + return value is from the tryacquire() methods. + + * ace/OS.i (mutex_trylock): On NT, if we try to acquire a mutex + that's already locked we'll return -1 and set errno to EBUSY + rather than ETIME to be consistent with Pthreads. Please see + the following entry to understand why this doesn't break + existing code ;-). + + * ace/OS.h: Added a #define for EBUSY on NT. We'll make it the + same as ETIME to avoid breaking existing code! + * tests/Process_Strategy_Test.cpp (main): Ignore SIGCHLD in the child. @@ -2775,6 +2775,10 @@ typedef long ACE_INT32; #define ETIME ETIMEDOUT #endif /* ETIMED */ +#if !defined (EBUSY) +#define EBUSY ETIME +#endif /* EBUSY */ + #if !defined (_SC_TIMER_MAX) #define _SC_TIMER_MAX 44 #endif /* _SC_TIMER_MAX */ @@ -1453,7 +1453,7 @@ ACE_OS::mutex_trylock (ACE_mutex_t *m) // Note that we still hold the lock return 0; case WAIT_TIMEOUT: - errno = ETIME; + errno = EBUSY; return -1; default: errno = ::GetLastError (); @@ -1470,8 +1470,11 @@ ACE_OS::mutex_trylock (ACE_mutex_t *m) #elif defined (VXWORKS) if (::semTake (*m, NO_WAIT) == ERROR) if (errno == S_objLib_OBJ_TIMEOUT) - // couldn't get the semaphore - return 1; + { + // couldn't get the semaphore + errno = EBUSY; + return -1; + } else // error return -1; @@ -1503,7 +1506,7 @@ ACE_OS::mutex_trylock (ACE_mutex_t *m, int &abandoned) abandoned = 1; return 0; // something goofed, but we hold the lock ... case WAIT_TIMEOUT: - errno = ETIME; + errno = EBUSY; return -1; default: errno = ::GetLastError (); @@ -1647,7 +1650,7 @@ ACE_OS::thread_mutex_trylock (ACE_thread_mutex_t *m) ACE_NOTSUP_RETURN (-1); #endif /* ACE_HAS_WIN32_TRYLOCK */ #elif defined (VXWORKS) - return mutex_trylock (m); + return ACE_OS::mutex_trylock (m); #endif /* ACE_HAS_STHREADS || ACE_HAS_DCETHREADS || ACE_HAS_PTHREADS */ #else ACE_UNUSED_ARG (m); @@ -1666,7 +1669,7 @@ ACE_OS::thread_mutex_unlock (ACE_thread_mutex_t *m) ::LeaveCriticalSection (m); return 0; #elif defined (VXWORKS) - return mutex_unlock (m); + return ACE_OS::mutex_unlock (m); #endif /* ACE_HAS_STHREADS || ACE_HAS_DCETHREADS || ACE_HAS_PTHREADS */ #else ACE_UNUSED_ARG (m); @@ -2072,7 +2075,7 @@ ACE_OS::sema_trywait (ACE_sema_t *s) int, -1); #elif defined (ACE_HAS_THREADS) #if defined (ACE_HAS_STHREADS) - // STHREADS semaphores set errno to EBUSY if trywait fails + // STHREADS semaphores set errno to EBUSY if trywait fails. ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_trywait (s), ace_result_), int, -1); @@ -2106,6 +2109,7 @@ ACE_OS::sema_trywait (ACE_sema_t *s) } #elif defined (VXWORKS) + // @@ David, should this be changed to set errno to EBUSY? ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::semTake (s->sema_, NO_WAIT), ace_result_), int, -1); #endif /* ACE_HAS_STHREADS */ @@ -6509,8 +6513,14 @@ ACE_OS::flock_trywrlock (ACE_OS::ace_flock_t *lock, short whence, off_t start, o lock->lock_.l_len = len; lock->lock_.l_type = F_WRLCK; // set write lock - // Does not block, if no access, returns -1. - ACE_OSCALL_RETURN (::fcntl (lock->handle_, F_SETLK, &lock->lock_), int, -1); + int result = 0; + // Does not block, if no access, returns -1 and set errno = EBUSY; + ACE_OSCALL (::fcntl (lock->handle_, F_SETLK, &lock->lock_), int, -1, result); + + if (result == -1 && (errno == EACCES || errno == EAGAIN)) + errno = EBUSY; + + return result; #endif /* ACE_WIN32 */ } @@ -6537,8 +6547,14 @@ ACE_OS::flock_tryrdlock (ACE_OS::ace_flock_t *lock, short whence, off_t start, o lock->lock_.l_len = len; lock->lock_.l_type = F_RDLCK; // set read lock - // Does not block, if no access, returns -1. - ACE_OSCALL_RETURN (::fcntl (lock->handle_, F_SETLK, &lock->lock_), int, -1); + int result = 0; + // Does not block, if no access, returns -1 and set errno = EBUSY; + ACE_OSCALL (::fcntl (lock->handle_, F_SETLK, &lock->lock_), int, -1, result); + + if (result == -1 && (errno == EACCES || errno == EAGAIN)) + errno = EBUSY; + + return result; #endif /* ACE_WIN32 */ } diff --git a/ace/Synch.h b/ace/Synch.h index 73f7a7533c2..24e781ac564 100644 --- a/ace/Synch.h +++ b/ace/Synch.h @@ -50,31 +50,38 @@ public: // Explicitly destroy the lock. virtual int acquire (void) = 0; - // Block the thread until the lock is acquired. + // Block the thread until the lock is acquired. Returns -1 on + // failure. virtual int tryacquire (void) = 0; - // Conditionally acquire the lock (i.e., won't block). + // Conditionally acquire the lock (i.e., won't block). Returns -1 + // on failure. If we "failed" because someone else already had the + // lock, <errno> is set to <EBUSY>. virtual int release (void) = 0; - // Release the lock. + // Release the lock. Returns -1 on failure. virtual int acquire_read (void) = 0; // Block until the thread acquires a read lock. If the locking // mechanism doesn't support read locks then this just calls - // <acquire>. + // <acquire>. Returns -1 on failure. virtual int acquire_write (void) = 0; // Block until the thread acquires a write lock. If the locking // mechanism doesn't support read locks then this just calls - // <acquire>. + // <acquire>. Returns -1 on failure. virtual int tryacquire_read (void) = 0; // Conditionally acquire a read lock. If the locking mechanism // doesn't support read locks then this just calls <acquire>. + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. virtual int tryacquire_write (void) = 0; // Conditionally acquire a write lock. If the locking mechanism // doesn't support read locks then this just calls <acquire>. + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. }; class ACE_Export ACE_File_Lock @@ -115,7 +122,9 @@ public: int tryacquire (short whence = 0, off_t start = 0, off_t len = 1); // Note, for interface uniformity with other synchronization // wrappers we include the <tryacquire> method. This is implemented - // as a write-lock to be on the safe-side... + // as a write-lock to be on the safe-side... Returns -1 on failure. + // If we "failed" because someone else already had the lock, <errno> + // is set to <EBUSY>. int release (short whence = 0, off_t start = 0, off_t len = 1); // Unlock a readers/writer lock. @@ -125,13 +134,19 @@ public: // writer hold the lock. int tryacquire_write (short whence = 0, off_t start = 0, off_t len = 1); - // Conditionally acquire a write lock (i.e., won't block). + // Conditionally acquire a write lock (i.e., won't block). Returns + // -1 on failure. If we "failed" because someone else already had + // the lock, <errno> is set to <EBUSY>. int acquire_read (short whence = 0, off_t start = 0, off_t len = 1); // Acquire a read lock, but block if a writer hold the lock. + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. int tryacquire_read (short whence = 0, off_t start = 0, off_t len = 1); - // Conditionally acquire a read lock (i.e., won't block). + // Conditionally acquire a read lock (i.e., won't block). Returns + // -1 on failure. If we "failed" because someone else already had + // the lock, <errno> is set to <EBUSY>. ACE_HANDLE get_handle (void); // Get underlying <ACE_HANDLE> for the file. @@ -192,11 +207,13 @@ public: int tryacquire (void); // Conditionally decrement the semaphore if count is greater than 0 - // (i.e., won't block). + // (i.e., won't block). Returns -1 on failure. If we "failed" + // because someone else already had the lock, <errno> is set to + // <EBUSY>. int release (void); // Increment the semaphore by 1, potentially unblocking a waiting - // thread. + // thread. int release (size_t release_count); // Increment the semaphore by <release_count>, potentially @@ -216,11 +233,15 @@ public: // Conditionally acquire semaphore (i.e., won't block). This calls // <tryacquire> and is only here to make the <ACE_Semaphore> // interface consistent with the other synchronization APIs. + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. int tryacquire_write (void); // Conditionally acquire semaphore (i.e., won't block). This calls // <tryacquire> and is only here to make the <ACE_Semaphore> // interface consistent with the other synchronization APIs. + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. void dump (void) const; // Dump the state of an object. @@ -265,7 +286,9 @@ public: int tryacquire (void); // Conditionally decrement the semaphore if count is greater than 0 - // (i.e., won't block). + // (i.e., won't block). Returns -1 on failure. If we "failed" + // because someone else already had the lock, <errno> is set to + // <EBUSY>. int release (void); // Increment the semaphore, potentially unblocking a waiting thread. @@ -284,11 +307,15 @@ public: // Conditionally acquire semaphore (i.e., won't block). This calls // <tryacquire> and is only here to make the <ACE_Process_Semaphore> // interface consistent with the other synchronization APIs. + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. int tryacquire_write (void); // Conditionally acquire semaphore (i.e., won't block). This calls // <tryacquire> and is only here to make the <ACE_Process_Semaphore> // interface consistent with the other synchronization APIs. + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) const ACE_sema_t &lock (void) const; @@ -338,7 +365,9 @@ public: // writer hold the lock. int tryacquire_read (void); - // Conditionally acquire a read lock (i.e., won't block). + // Conditionally acquire a read lock (i.e., won't block). Returns + // -1 on failure. If we "failed" because someone else already had + // the lock, <errno> is set to <EBUSY>. int tryacquire_write (void); // Conditionally acquire a write lock (i.e., won't block). @@ -351,7 +380,9 @@ public: int tryacquire (void); // Note, for interface uniformity with other synchronization // wrappers we include the <tryacquire> method. This is implemented - // as a write-lock to be safe... + // as a write-lock to be safe... Returns -1 on failure. If we + // "failed" because someone else already had the lock, <errno> is + // set to <EBUSY>. int release (void); // Unlock a readers/writer lock. @@ -396,7 +427,9 @@ public: // Acquire lock ownership (wait on priority queue if necessary). int tryacquire (void); - // Conditionally acquire lock (i.e., don't wait on queue). + // Conditionally acquire lock (i.e., don't wait on queue). Returns + // -1 on failure. If we "failed" because someone else already had + // the lock, <errno> is set to <EBUSY>. int release (void); // Release lock and unblock a thread at head of priority queue. @@ -413,13 +446,17 @@ public: int tryacquire_read (void); // Conditionally acquire mutex (i.e., won't block). This calls - // <tryacquire> and is only here to make the <ACE_Mutex> - // interface consistent with the other synchronization APIs. + // <tryacquire> and is only here to make the <ACE_Mutex> interface + // consistent with the other synchronization APIs. Returns -1 on + // failure. If we "failed" because someone else already had the + // lock, <errno> is set to <EBUSY>. int tryacquire_write (void); // Conditionally acquire mutex (i.e., won't block). This calls - // <tryacquire> and is only here to make the <ACE_Mutex> - // interface consistent with the other synchronization APIs. + // <tryacquire> and is only here to make the <ACE_Mutex> interface + // consistent with the other synchronization APIs. Returns -1 on + // failure. If we "failed" because someone else already had the + // lock, <errno> is set to <EBUSY>. const ACE_mutex_t &lock (void) const; // Return the underlying mutex. @@ -459,7 +496,9 @@ public: // Acquire lock ownership (wait on priority queue if necessary). int tryacquire (void); - // Conditionally acquire lock (i.e., don't wait on queue). + // Conditionally acquire lock (i.e., don't wait on queue). Returns + // -1 on failure. If we "failed" because someone else already had + // the lock, <errno> is set to <EBUSY>. int release (void); // Release lock and unblock a thread at head of priority queue. @@ -471,10 +510,14 @@ public: // Acquire lock ownership (wait on priority queue if necessary). int tryacquire_read (void); - // Conditionally acquire a lock (i.e., won't block). + // Conditionally acquire a lock (i.e., won't block). Returns -1 on + // failure. If we "failed" because someone else already had the + // lock, <errno> is set to <EBUSY>. int tryacquire_write (void); - // Conditionally acquire a lock (i.e., won't block). + // Conditionally acquire a lock (i.e., won't block). Returns -1 on + // failure. If we "failed" because someone else already had the + // lock, <errno> is set to <EBUSY>. #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) const ACE_mutex_t &lock (void) const; @@ -809,7 +852,9 @@ public: // Acquire lock ownership (wait on priority queue if necessary). int tryacquire (void); - // Conditionally acquire lock (i.e., don't wait on queue). + // Conditionally acquire lock (i.e., don't wait on queue). Returns + // -1 on failure. If we "failed" because someone else already had + // the lock, <errno> is set to <EBUSY>. int release (void); // Release lock and unblock a thread at head of priority queue. @@ -828,11 +873,15 @@ public: // Conditionally acquire mutex (i.e., won't block). This calls // <tryacquire> and is only here to make the <ACE_Thread_Mutex> // interface consistent with the other synchronization APIs. + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. int tryacquire_write (void); // Conditionally acquire mutex (i.e., won't block). This calls // <tryacquire> and is only here to make the <ACE_Thread_Mutex> // interface consistent with the other synchronization APIs. + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. const ACE_thread_mutex_t &lock (void) const; // Return the underlying mutex. @@ -881,7 +930,9 @@ public: // Explicitly acquire the lock. int tryacquire (void); - // Conditionally acquire the lock (i.e., won't block). + // Conditionally acquire the lock (i.e., won't block). Returns -1 + // on failure. If we "failed" because someone else already had the + // lock, <errno> is set to <EBUSY>. int release (void); // Explicitly release the lock. @@ -1015,6 +1066,8 @@ public: int tryacquire (void); // Conditionally acquire a recursive mutex (i.e., won't block). + // Returns -1 on failure. If we "failed" because someone else + // already had the lock, <errno> is set to <EBUSY>. int acquire_read (void); // Acquire mutex ownership. This calls <acquire> and is only @@ -1028,13 +1081,19 @@ public: int tryacquire_read (void); // Conditionally acquire mutex (i.e., won't block). This calls - // <tryacquire> and is only here to make the <ACE_Recusive_Thread_Mutex> - // interface consistent with the other synchronization APIs. + // <tryacquire> and is only here to make the + // <ACE_Recusive_Thread_Mutex> interface consistent with the other + // synchronization APIs. Returns -1 on failure. If we "failed" + // because someone else already had the lock, <errno> is set to + // <EBUSY>. int tryacquire_write (void); // Conditionally acquire mutex (i.e., won't block). This calls - // <tryacquire> and is only here to make the <ACE_Recusive_Thread_Mutex> - // interface consistent with the other synchronization APIs. + // <tryacquire> and is only here to make the + // <ACE_Recusive_Thread_Mutex> interface consistent with the other + // synchronization APIs. Returns -1 on failure. If we "failed" + // because someone else already had the lock, <errno> is set to + // <EBUSY>. int release (void); // Releases a recursive mutex (will not release mutex until all the |