diff options
author | Ossama Othman <ossama-othman@users.noreply.github.com> | 2001-01-26 22:33:06 +0000 |
---|---|---|
committer | Ossama Othman <ossama-othman@users.noreply.github.com> | 2001-01-26 22:33:06 +0000 |
commit | f9232701ff492b6d8b5eda8e4bb5c85ea72c5bb0 (patch) | |
tree | eb9ccb6c2eed261b6b2f0ba2e1361fa7f7251c83 | |
parent | a4cb385d45f8adb31d23819c5677851e25ad40a9 (diff) | |
download | ATCD-f9232701ff492b6d8b5eda8e4bb5c85ea72c5bb0.tar.gz |
ChangeLogTag:Fri Jan 26 14:13:32 2001 Ossama Othman <ossama@uci.edu>
-rw-r--r-- | ChangeLog | 28 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 28 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 28 | ||||
-rw-r--r-- | ace/OS.h | 14 | ||||
-rw-r--r-- | ace/OS.i | 68 | ||||
-rw-r--r-- | ace/README | 3 | ||||
-rw-r--r-- | ace/Synch.h | 16 | ||||
-rw-r--r-- | ace/Synch.i | 22 | ||||
-rw-r--r-- | ace/config-linux-common.h | 9 | ||||
-rw-r--r-- | ace/config-linux.h | 26 |
10 files changed, 231 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog index b4704136e04..c0a5243a318 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +Fri Jan 26 14:13:32 2001 Ossama Othman <ossama@uci.edu> + + * ace/OS.h: + * ace/OS.i (mutex_timedlock): + + Wrapped the pthread_mutex_timedlock() function. It times out if + a lock hasn't been acquired by the given absolute time. + + * ace/Synch.h: + * ace/Synch.i (acquire): + + Added versions of this method that accept an ACE_Time_Value. + They are used to prevent blocking definitely while waiting for a + given mutex to become available. + + * ace/config-linux.h (ACE_HAS_MUTEX_TIMEOUTS): + + glibc 2.2.x supports the pthread_mutex_timedlock() function. + + * ace/config-linux-common.h: + + Undefine ACE_LACKS_{LLSEEK,LSEEK64}_PROTOTYPE prior to include + the KCC configuration file. + + * ace/README: + + Added ACE_HAS_MUTEX_TIMEOUTS to the list of ACE macros. + Fri Jan 26 11:18:15 2001 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> * ace/Log_Msg.cpp (dump): Fixed some unintentional tabs. Thanks diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index b4704136e04..c0a5243a318 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,3 +1,31 @@ +Fri Jan 26 14:13:32 2001 Ossama Othman <ossama@uci.edu> + + * ace/OS.h: + * ace/OS.i (mutex_timedlock): + + Wrapped the pthread_mutex_timedlock() function. It times out if + a lock hasn't been acquired by the given absolute time. + + * ace/Synch.h: + * ace/Synch.i (acquire): + + Added versions of this method that accept an ACE_Time_Value. + They are used to prevent blocking definitely while waiting for a + given mutex to become available. + + * ace/config-linux.h (ACE_HAS_MUTEX_TIMEOUTS): + + glibc 2.2.x supports the pthread_mutex_timedlock() function. + + * ace/config-linux-common.h: + + Undefine ACE_LACKS_{LLSEEK,LSEEK64}_PROTOTYPE prior to include + the KCC configuration file. + + * ace/README: + + Added ACE_HAS_MUTEX_TIMEOUTS to the list of ACE macros. + Fri Jan 26 11:18:15 2001 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> * ace/Log_Msg.cpp (dump): Fixed some unintentional tabs. Thanks diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index b4704136e04..c0a5243a318 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,31 @@ +Fri Jan 26 14:13:32 2001 Ossama Othman <ossama@uci.edu> + + * ace/OS.h: + * ace/OS.i (mutex_timedlock): + + Wrapped the pthread_mutex_timedlock() function. It times out if + a lock hasn't been acquired by the given absolute time. + + * ace/Synch.h: + * ace/Synch.i (acquire): + + Added versions of this method that accept an ACE_Time_Value. + They are used to prevent blocking definitely while waiting for a + given mutex to become available. + + * ace/config-linux.h (ACE_HAS_MUTEX_TIMEOUTS): + + glibc 2.2.x supports the pthread_mutex_timedlock() function. + + * ace/config-linux-common.h: + + Undefine ACE_LACKS_{LLSEEK,LSEEK64}_PROTOTYPE prior to include + the KCC configuration file. + + * ace/README: + + Added ACE_HAS_MUTEX_TIMEOUTS to the list of ACE macros. + Fri Jan 26 11:18:15 2001 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> * ace/Log_Msg.cpp (dump): Fixed some unintentional tabs. Thanks @@ -5719,6 +5719,20 @@ public: static int mutex_trylock (ACE_mutex_t *m, int &abandoned); + /// This method attempts to acquire a lock, but gives up if the lock + /// has not been acquired by the given time. + /** + * If the lock is not acquired within the given amount of time, then + * this method returns with an ETIMEDOUT errno on platforms that + * actually support timed mutexes. Otherwise it simply does a + * mutex_trylock(). If the timeout pointer, then it will block + * indefinitely. The timeout should be an absolute time. Note that + * the mutex should not be a recursive one, i.e., it should only be + * a standard mutex or an error checking mutex. + */ + static int mutex_timedlock (ACE_mutex_t *m, + ACE_Time_Value *timeout); + static int mutex_unlock (ACE_mutex_t *m); //@} @@ -1776,7 +1776,7 @@ ACE_OS::mutex_lock (ACE_mutex_t *m) #if defined (ACE_HAS_PACE) int dummy_retval = 0; ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pace_pthread_mutex_lock (m), - dummy_retval), int, -1);; + dummy_retval), int, -1); #elif defined (ACE_HAS_THREADS) # if defined (ACE_HAS_PTHREADS) // Note, don't use "::" here since the following call is often a macro. @@ -2004,6 +2004,72 @@ ACE_OS::mutex_trylock (ACE_mutex_t *m, int &abandoned) } ACE_INLINE int +ACE_OS::mutex_timedlock (ACE_mutex_t *m, + ACE_Time_Value *timeout) +{ +#if defined (ACE_HAS_THREADS) + +# if defined (ACE_HAS_MUTEX_TIMEOUTS) + + int result; + timespec_t ts; + + // "timeout" should be an absolute time. + + if (timeout != 0) + ts = *timeout; // Calls ACE_Time_Value::operator timespec_t(). + + // Note that the mutex should not be a recursive one, i.e., it + // should only be a standard mutex or an error checking mutex. + +# if defined (ACE_HAS_PTHREADS) + + if (timeout == 0) + return ACE_OS::mutex_lock (m); // Block indefinitely + else + { + ACE_OSCALL (ACE_ADAPT_RETVAL ( + ::pthread_mutex_timedlock (m, &ts), + result), int, -1, result); + } +# else /* ACE_HAS_PTHREADS */ + + // @@ Apparently only POSIX threads have the timed lock + // functionality. + + if (timeout == 0) + return ACE_OS::mutex_lock (m); // Block indefinitely. + else + return ACE_OS::mutex_trylock (m); // The best that we can do is + // try to grab the lock. + +# endif /* ACE_HAS_PTHREADS */ + + if (timeout != 0) + timeout->set (ts); // Update the time value before returning. + + return result; + +# else /* ACE_HAS_MUTEX_TIMEOUTS */ + + if (timeout == 0) + return ACE_OS::mutex_lock (m); // Block indefinitely. + else + return ACE_OS::mutex_trylock (m); // The best that we can do is + // try to grab the lock. + +# endif /* ACE_HAS_MUTEX_TIMEOUTS */ + +#else /* ACE_HAS_THREADS */ + + ACE_UNUSED_ARG (m); + ACE_UNUSED_ARG (timeout); + ACE_NOTSUP_RETURN (-1); + +#endif /* ACE_HAS_THREADS */ +} + +ACE_INLINE int ACE_OS::mutex_unlock (ACE_mutex_t *m) { ACE_OS_TRACE ("ACE_OS::mutex_unlock"); diff --git a/ace/README b/ace/README index 391299174b8..4cbfc645690 100644 --- a/ace/README +++ b/ace/README @@ -379,6 +379,9 @@ ACE_HAS_MT_SAFE_MKTIME Platform supports MT safe mktime() call (do any of them?) ACE_HAS_MUTABLE_KEYWORD Compiler supports mutable. +ACE_HAS_MUTEX_TIMEOUTS Compiler supports timed mutex + acquisitions + (e.g. pthread_mutex_timedlock()). ACE_HAS_NONCONST_GETBY Platform uses non-const char * in calls to gethostbyaddr, gethostbyname, getservbyname diff --git a/ace/Synch.h b/ace/Synch.h index 481d6d398a9..4dcc537b2cd 100644 --- a/ace/Synch.h +++ b/ace/Synch.h @@ -444,6 +444,14 @@ public: int acquire (void); /** + * Block the thread until <tv> times out. Note that <tv> is assumed + * to be in "absolute" rather than "relative" time. The value of + * <tv> is updated upon return to show the actual (absolute) + * acquisition time. + */ + int acquire (ACE_Time_Value &tv); + + /** * 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>. @@ -932,6 +940,14 @@ public: int acquire (void); /** + * Block the thread until <tv> times out. Note that <tv> is assumed + * to be in "absolute" rather than "relative" time. The value of + * <tv> is updated upon return to show the actual (absolute) + * acquisition time. + */ + int acquire (ACE_Time_Value &tv); + + /** * 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>. diff --git a/ace/Synch.i b/ace/Synch.i index 1c9714d5b39..a283e00c0b3 100644 --- a/ace/Synch.i +++ b/ace/Synch.i @@ -165,6 +165,13 @@ ACE_Mutex::acquire (void) } ACE_INLINE int +ACE_Mutex::acquire (ACE_Time_Value &tv) +{ + // ACE_TRACE ("ACE_Mutex::acquire"); + return ACE_OS::mutex_timedlock (&this->lock_, &tv); +} + +ACE_INLINE int ACE_Mutex::tryacquire (void) { // ACE_TRACE ("ACE_Mutex::tryacquire"); @@ -323,10 +330,10 @@ ACE_Semaphore::tryacquire_write (void) return this->tryacquire (); } -// This is only here to make the <ACE_Semaphore> -// interface consistent with the other synchronization APIs. -// Assumes the caller has already acquired the semaphore using one of -// the above calls, and returns 0 (success) always. +// This is only here to make the <ACE_Semaphore> interface consistent +// with the other synchronization APIs. Assumes the caller has +// already acquired the semaphore using one of the above calls, and +// returns 0 (success) always. ACE_INLINE int ACE_Semaphore::tryacquire_write_upgrade (void) { @@ -472,6 +479,13 @@ ACE_Thread_Mutex::acquire (void) } ACE_INLINE int +ACE_Thread_Mutex::acquire (ACE_Time_Value &tv) +{ + // ACE_TRACE ("ACE_Thread_Mutex::acquire"); + return ACE_OS::mutex_timedlock (&this->lock_, &tv); +} + +ACE_INLINE int ACE_Thread_Mutex::tryacquire (void) { // ACE_TRACE ("ACE_Thread_Mutex::tryacquire"); diff --git a/ace/config-linux-common.h b/ace/config-linux-common.h index 710781b0427..a0dd666aeb7 100644 --- a/ace/config-linux-common.h +++ b/ace/config-linux-common.h @@ -119,6 +119,8 @@ # define ACE_HAS_STRING_CLASS # undef ACE_HAS_LLSEEK # undef ACE_HAS_LSEEK64 +# undef ACE_LACKS_LLSEEK_PROTOTYPE +# undef ACE_LACKS_LSEEK64_PROTOTYPE # include "ace/config-kcc-common.h" #elif defined (__DECCXX) # define ACE_CONFIG_INCLUDE_CXX_COMMON @@ -192,6 +194,13 @@ # define ACE_LACKS_SOME_POSIX_PROTOTYPES #endif +// glibc supports the mkstemp() function. +#define ACE_HAS_MKSTEMP + +// glibc requires _XOPEN_SOURCE_EXTENDED to make this prototype +// visible, so force ACE to declare one. Yuk! +#define ACE_LACKS_MKSTEMP_PROTOTYPE + // Platform defines struct timespec but not timespec_t #define ACE_LACKS_TIMESPEC_T diff --git a/ace/config-linux.h b/ace/config-linux.h index b5294e26541..85fda1c180d 100644 --- a/ace/config-linux.h +++ b/ace/config-linux.h @@ -4,8 +4,8 @@ // The following configuration file is designed to work for Linux // platforms using GNU C++. -#ifndef ACE_CONFIG_H -#define ACE_CONFIG_H +#ifndef ACE_CONFIG_LINUX_H +#define ACE_CONFIG_LINUX_H #include "ace/pre.h" #include "ace/config-linux-common.h" @@ -37,20 +37,34 @@ // functions). #define ACE_HAS_REENTRANT_FUNCTIONS -#if (__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1) +#if !(__GLIBC_PREREQ (2, 1)) // Older versions of glibc lacked reentrant netdb functions # define ACE_LACKS_NETDB_REENTRANT_FUNCTIONS // glibc < 2.1 lacks pthread_attr_setstacksize() # define ACE_LACKS_THREAD_STACK_SIZE -#endif /* (__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1) */ +#endif /* (__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1) */ // uses ctime_r & asctime_r with only two parameters vs. three #define ACE_HAS_2_PARAM_ASCTIME_R_AND_CTIME_R #endif + #include /**/ <pthread.h> -#endif /*ACE_MT_SAFE*/ + +#if __GLIBC_PREREQ (2, 2) + // glibc 2.2.x or better has pthread_mutex_timedlock() +# define ACE_HAS_MUTEX_TIMEOUTS +# if !defined (_XOPEN_SOURCE) \ + || (defined (_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0) < 600) +// pthread_mutex_timedlock() prototype is not visible if _XOPEN_SOURCE +// is not >= 600 (i.e. for XPG6). +extern int pthread_mutex_timedlock (pthread_mutex_t *mutex, + const struct timespec * abstime); +# endif /* _XOPEN_SOURCE && _XOPEN_SOURCE < 600 */ +#endif /* (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) */ + +#endif /* ACE_MT_SAFE */ #include "ace/post.h" -#endif /* ACE_CONFIG_H */ +#endif /* ACE_CONFIG_LINUX_H */ |