diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 12 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 12 | ||||
-rw-r--r-- | ace/OS.h | 35 | ||||
-rw-r--r-- | ace/OS.i | 84 | ||||
-rw-r--r-- | ace/Synch.cpp | 17 | ||||
-rw-r--r-- | ace/Synch.h | 10 | ||||
-rw-r--r-- | ace/Synch_T.h | 2 | ||||
-rw-r--r-- | ace/Token.cpp | 2 | ||||
-rw-r--r-- | tests/Thread_Mutex_Test.cpp | 25 |
10 files changed, 147 insertions, 64 deletions
diff --git a/ChangeLog b/ChangeLog index 6717db20ef5..0de736f1ea0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ Tue Apr 18 15:18:53 2000 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + * ace/OS.h, + * ace/OS.i, + * ace/Synch.h, + * ace/Synch.cpp: Updated the ACE_OS::*mutex_init() methods (and the + corresponding ACE_Thread_Mutex, ACE_Mutex, and + ACE_Recursive_Thread_Mutex classes) so that they now take an + optional ACE_mutexattr_t * rather than just a void *. This is + nice because it makes it possible to pass in special attributes, + such as the mutex prioceiling attribute, to the underlying + pthreads mutex (assuming we're running on pthreads, of course). + Thanks to lafortg@res.raytheon.com for motivating this. + * ace/Containers_T.cpp (copy_nodes): Added a call to the allocator->malloc() rather than new. Thanks to Umar Syyid <usyyid@hns.com> for reporting this. diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index 6717db20ef5..0de736f1ea0 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,5 +1,17 @@ Tue Apr 18 15:18:53 2000 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + * ace/OS.h, + * ace/OS.i, + * ace/Synch.h, + * ace/Synch.cpp: Updated the ACE_OS::*mutex_init() methods (and the + corresponding ACE_Thread_Mutex, ACE_Mutex, and + ACE_Recursive_Thread_Mutex classes) so that they now take an + optional ACE_mutexattr_t * rather than just a void *. This is + nice because it makes it possible to pass in special attributes, + such as the mutex prioceiling attribute, to the underlying + pthreads mutex (assuming we're running on pthreads, of course). + Thanks to lafortg@res.raytheon.com for motivating this. + * ace/Containers_T.cpp (copy_nodes): Added a call to the allocator->malloc() rather than new. Thanks to Umar Syyid <usyyid@hns.com> for reporting this. diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index 6717db20ef5..0de736f1ea0 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,5 +1,17 @@ Tue Apr 18 15:18:53 2000 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + * ace/OS.h, + * ace/OS.i, + * ace/Synch.h, + * ace/Synch.cpp: Updated the ACE_OS::*mutex_init() methods (and the + corresponding ACE_Thread_Mutex, ACE_Mutex, and + ACE_Recursive_Thread_Mutex classes) so that they now take an + optional ACE_mutexattr_t * rather than just a void *. This is + nice because it makes it possible to pass in special attributes, + such as the mutex prioceiling attribute, to the underlying + pthreads mutex (assuming we're running on pthreads, of course). + Thanks to lafortg@res.raytheon.com for motivating this. + * ace/Containers_T.cpp (copy_nodes): Added a call to the allocator->malloc() rather than new. Thanks to Umar Syyid <usyyid@hns.com> for reporting this. @@ -2158,6 +2158,7 @@ typedef pthread_t ACE_thread_t; typedef pthread_mutex_t ACE_mutex_t; typedef pthread_cond_t ACE_cond_t; typedef pthread_condattr_t ACE_condattr_t; +typedef pthread_mutexattr_t ACE_mutexattr_t; # endif /* ! ACE_LACKS_COND_T */ typedef pthread_mutex_t ACE_thread_mutex_t; @@ -2319,6 +2320,10 @@ struct ACE_Export ACE_condattr_t { int type; }; +struct ACE_Export ACE_mutexattr_t +{ + int type; +}; typedef ACE_thread_t ACE_hthread_t; typedef ACE_mutex_t ACE_thread_mutex_t; @@ -2347,7 +2352,11 @@ struct ACE_Export ACE_condattr_t { int type; }; -#endif +struct ACE_Export ACE_mutexattr_t +{ + int type; +}; +#endif /* ACE_PSOS_HAS_COND_T */ // TCB registers 0-7 are for application use @@ -2594,6 +2603,10 @@ struct ACE_Export ACE_condattr_t { int type; }; +struct ACE_Export ACE_mutexattr_t +{ + int type; +}; # endif /* ACE_LACKS_COND_T */ # if defined (ACE_LACKS_RWLOCK_T) && !defined (ACE_HAS_PTHREADS_UNIX98_EXT) @@ -2759,6 +2772,10 @@ struct ACE_Export ACE_condattr_t { int type; }; +struct ACE_Export ACE_mutexattr_t +{ + int type; +}; typedef int ACE_mutex_t; typedef int ACE_thread_mutex_t; typedef int ACE_recursive_thread_mutex_t; @@ -5562,7 +5579,7 @@ public: // = A set of wrappers for condition variables. static int condattr_init (ACE_condattr_t &attributes, - int type = ACE_DEFAULT_SYNCH_TYPE); + int type = ACE_DEFAULT_SYNCH_TYPE); static int condattr_destroy (ACE_condattr_t &attributes); static int cond_broadcast (ACE_cond_t *cv); static int cond_destroy (ACE_cond_t *cv); @@ -5946,42 +5963,34 @@ public: // = A set of wrappers for recursive mutex locks. static int recursive_mutex_init (ACE_recursive_thread_mutex_t *m, LPCTSTR name = 0, - void *arg = 0, + ACE_mutexattr_t *arg = 0, LPSECURITY_ATTRIBUTES sa = 0); static int recursive_mutex_destroy (ACE_recursive_thread_mutex_t *m); - static int recursive_mutex_lock (ACE_recursive_thread_mutex_t *m); - static int recursive_mutex_trylock (ACE_recursive_thread_mutex_t *m); - static int recursive_mutex_unlock (ACE_recursive_thread_mutex_t *m); // = A set of wrappers for mutex locks. static int mutex_init (ACE_mutex_t *m, int type = ACE_DEFAULT_SYNCH_TYPE, LPCTSTR name = 0, - void *arg = 0, + ACE_mutexattr_t *arg = 0, LPSECURITY_ATTRIBUTES sa = 0); static int mutex_destroy (ACE_mutex_t *m); - static int mutex_lock (ACE_mutex_t *m); // Win32 note: Abandoned mutexes are not treated differently. 0 is // returned since the calling thread does get the ownership. - static int mutex_lock (ACE_mutex_t *m, int &abandoned); // This method is only implemented for Win32. For abandoned // mutexes, <abandoned> is set to 1 and 0 is returned. - static int mutex_trylock (ACE_mutex_t *m); // Win32 note: Abandoned mutexes are not treated differently. 0 is // returned since the calling thread does get the ownership. - static int mutex_trylock (ACE_mutex_t *m, int &abandoned); // This method is only implemented for Win32. For abandoned // mutexes, <abandoned> is set to 1 and 0 is returned. - static int mutex_unlock (ACE_mutex_t *m); // = A set of wrappers for mutex locks that only work within a @@ -5989,7 +5998,7 @@ public: static int thread_mutex_init (ACE_thread_mutex_t *m, int type = ACE_DEFAULT_SYNCH_TYPE, LPCTSTR name = 0, - void *arg = 0); + ACE_mutexattr_t *arg = 0); static int thread_mutex_destroy (ACE_thread_mutex_t *m); static int thread_mutex_lock (ACE_thread_mutex_t *m); static int thread_mutex_trylock (ACE_thread_mutex_t *m); @@ -1855,61 +1855,85 @@ ACE_INLINE int ACE_OS::mutex_init (ACE_mutex_t *m, int type, LPCTSTR name, - void *arg, + ACE_mutexattr_t *attributes, LPSECURITY_ATTRIBUTES sa) { // ACE_TRACE ("ACE_OS::mutex_init"); #if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_PTHREADS) ACE_UNUSED_ARG (name); - ACE_UNUSED_ARG (arg); + ACE_UNUSED_ARG (attributes); ACE_UNUSED_ARG (sa); - pthread_mutexattr_t attributes; + pthread_mutexattr_t l_attributes; + if (attributes == 0) + attributes = &l_attributes; int result = -1; + // Only do these initializations if the <attributes> parameter + // wasn't originally set. + if (attributes == &l_attributes) + { +# if defined (ACE_HAS_PTHREADS_DRAFT4) + if (::pthread_mutexattr_create (attributes) == 0) +# elif defined (ACE_HAS_PTHREADS_DRAFT7) || defined (ACE_HAS_PTHREADS_STD) + if (ACE_ADAPT_RETVAL (::pthread_mutexattr_init (attributes), result) == 0) +# else // draft 6 + if (::pthread_mutexattr_init (attributes) == 0) +# endif /* ACE_HAS_PTHREADS_DRAFT4 */ + result = 0; + else + result = -1; // ACE_ADAPT_RETVAL used it for intermediate status + } + + if (result == 0) + { # if defined (ACE_HAS_PTHREADS_DRAFT4) - if (::pthread_mutexattr_create (&attributes) == 0 + if ( # if defined (ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP) - && ::pthread_mutexattr_setkind_np (&attributes, type) == 0 + ::pthread_mutexattr_setkind_np (attributes, type) == 0 && # endif /* ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP */ - && ::pthread_mutex_init (m, attributes) == 0) + ::pthread_mutex_init (m, *attributes) == 0) # elif defined (ACE_HAS_PTHREADS_DRAFT7) || defined (ACE_HAS_PTHREADS_STD) - if (ACE_ADAPT_RETVAL(::pthread_mutexattr_init (&attributes), result) == 0 + if ( # if defined (_POSIX_THREAD_PROCESS_SHARED) && !defined (ACE_LACKS_MUTEXATTR_PSHARED) - && ACE_ADAPT_RETVAL(::pthread_mutexattr_setpshared(&attributes, type), - result) == 0 + ACE_ADAPT_RETVAL (::pthread_mutexattr_setpshared (attributes, type), + result) == 0 && # endif /* _POSIX_THREAD_PROCESS_SHARED && ! ACE_LACKS_MUTEXATTR_PSHARED */ - && ACE_ADAPT_RETVAL(::pthread_mutex_init (m, &attributes), result)== 0) -# else // draft 6 - if (::pthread_mutexattr_init (&attributes) == 0 + ACE_ADAPT_RETVAL (::pthread_mutex_init (m, attributes), result) == 0) +# else + if ( # if !defined (ACE_LACKS_MUTEXATTR_PSHARED) - && ::pthread_mutexattr_setpshared (&attributes, type) == 0 + ::pthread_mutexattr_setpshared (attributes, type) == 0 && # endif /* ACE_LACKS_MUTEXATTR_PSHARED */ -# if defined (ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP) - && ::pthread_mutexattr_setkind_np (&attributes, type) == 0 +# if defined (ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP) + ::pthread_mutexattr_setkind_np (attributes, type) == 0 && # endif /* ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP */ - && ::pthread_mutex_init (m, &attributes) == 0) + ::pthread_mutex_init (m, attributes) == 0) # endif /* ACE_HAS_PTHREADS_DRAFT4 */ - result = 0; - else - result = -1; // ACE_ADAPT_RETVAL used it for intermediate status + result = 0; + else + result = -1; // ACE_ADAPT_RETVAL used it for intermediate status + } # if (!defined (ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP) && !defined (_POSIX_THREAD_PROCESS_SHARED) || defined (ACE_LACKS_MUTEXATTR_PSHARED)) ACE_UNUSED_ARG (type); # endif /* ! ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP */ + // Only do the deletions if the <attributes> parameter wasn't + // originally set. + if (attributes == &l_attributes) # if defined (ACE_HAS_PTHREADS_DRAFT4) - ::pthread_mutexattr_delete (&attributes); + ::pthread_mutexattr_delete (&l_attributes); # else - ::pthread_mutexattr_destroy (&attributes); + ::pthread_mutexattr_destroy (&l_attributes); # endif /* ACE_HAS_PTHREADS_DRAFT4 */ return result; # elif defined (ACE_HAS_STHREADS) ACE_UNUSED_ARG (name); ACE_UNUSED_ARG (sa); - ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mutex_init (m, type, arg), + ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mutex_init (m, type, attributes), ace_result_), int, -1); # elif defined (ACE_HAS_WTHREADS) @@ -1929,7 +1953,7 @@ ACE_OS::mutex_init (ACE_mutex_t *m, return ACE_OS::thread_mutex_init (&m->thr_mutex_, type, name, - arg); + attributes); default: errno = EINVAL; return -1; @@ -1938,7 +1962,7 @@ ACE_OS::mutex_init (ACE_mutex_t *m, # elif defined (ACE_PSOS) ACE_UNUSED_ARG (type); - ACE_UNUSED_ARG (arg); + ACE_UNUSED_ARG (attributes); ACE_UNUSED_ARG (sa); # if defined (ACE_PSOS_HAS_MUTEX) @@ -1981,7 +2005,7 @@ ACE_OS::mutex_init (ACE_mutex_t *m, # endif /* ACE_PSOS_HAS_MUTEX */ # elif defined (VXWORKS) ACE_UNUSED_ARG (name); - ACE_UNUSED_ARG (arg); + ACE_UNUSED_ARG (attributes); ACE_UNUSED_ARG (sa); return (*m = ::semMCreate (type)) == 0 ? -1 : 0; @@ -1990,7 +2014,7 @@ ACE_OS::mutex_init (ACE_mutex_t *m, ACE_UNUSED_ARG (m); ACE_UNUSED_ARG (type); ACE_UNUSED_ARG (name); - ACE_UNUSED_ARG (arg); + ACE_UNUSED_ARG (attributes); ACE_UNUSED_ARG (sa); ACE_NOTSUP_RETURN (-1); #endif /* ACE_HAS_THREADS */ @@ -2307,7 +2331,7 @@ ACE_INLINE int ACE_OS::thread_mutex_init (ACE_thread_mutex_t *m, int type, LPCTSTR name, - void *arg) + ACE_mutexattr_t *arg) { // ACE_TRACE ("ACE_OS::thread_mutex_init"); #if defined (ACE_HAS_THREADS) @@ -2807,7 +2831,7 @@ ACE_OS::thr_self (void) ACE_INLINE int ACE_OS::recursive_mutex_init (ACE_recursive_thread_mutex_t *m, LPCTSTR name, - void *arg, + ACE_mutexattr_t *arg, LPSECURITY_ATTRIBUTES sa) { ACE_UNUSED_ARG (sa); @@ -2820,7 +2844,7 @@ ACE_OS::recursive_mutex_init (ACE_recursive_thread_mutex_t *m, else if (ACE_OS::cond_init (&m->lock_available_, (short) USYNC_THREAD, name, - arg) == -1) + 0) == -1) return -1; else { @@ -4385,7 +4409,7 @@ ACE_OS::event_init (ACE_event_t *event, result = ACE_OS::mutex_init (&event->lock_, type, name, - arg); + (ACE_mutexattr_t *) arg); return result; #else ACE_UNUSED_ARG (event); diff --git a/ace/Synch.cpp b/ace/Synch.cpp index 18f3b13bce2..4808e991cfd 100644 --- a/ace/Synch.cpp +++ b/ace/Synch.cpp @@ -374,7 +374,7 @@ ACE_Mutex::dump (void) const ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } -ACE_Mutex::ACE_Mutex (int type, LPCTSTR name, void *arg) +ACE_Mutex::ACE_Mutex (int type, LPCTSTR name, ACE_mutexattr_t *arg) : #if defined (CHORUS) process_lock_ (0), @@ -608,7 +608,7 @@ ACE_Thread_Mutex_Guard::dump (void) const #endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */ ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex (LPCTSTR name, - void *arg) + ACE_mutexattr_t *arg) : removed_ (0) { // ACE_TRACE ("ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex"); @@ -872,7 +872,7 @@ ACE_Barrier::dump (void) const ACE_Barrier::ACE_Barrier (u_int count, LPCTSTR name, void *arg) - : lock_ (name, arg), + : lock_ (name, (ACE_mutexattr_t *) arg), current_generation_ (0), count_ (count), sub_barrier_1_ (count, lock_, name, arg), @@ -982,15 +982,18 @@ ACE_Thread_Mutex::~ACE_Thread_Mutex (void) this->remove (); } -ACE_Thread_Mutex::ACE_Thread_Mutex (LPCTSTR name, void *arg) +ACE_Thread_Mutex::ACE_Thread_Mutex (LPCTSTR name, ACE_mutexattr_t *arg) : removed_ (0) { // ACE_TRACE ("ACE_Thread_Mutex::ACE_Thread_Mutex"); - if (ACE_OS::thread_mutex_init (&this->lock_, USYNC_THREAD, name, arg) != 0) + if (ACE_OS::thread_mutex_init (&this->lock_, + USYNC_THREAD, + name, + arg) != 0) ACE_ERROR ((LM_ERROR, - ASYS_TEXT("%p\n"), - ASYS_TEXT("ACE_Thread_Mutex::ACE_Thread_Mutex"))); + ASYS_TEXT ("%p\n"), + ASYS_TEXT ("ACE_Thread_Mutex::ACE_Thread_Mutex"))); } ACE_ALLOC_HOOK_DEFINE(ACE_RW_Thread_Mutex) diff --git a/ace/Synch.h b/ace/Synch.h index 6bb3ca2267c..91bc87620da 100644 --- a/ace/Synch.h +++ b/ace/Synch.h @@ -532,7 +532,7 @@ class ACE_Export ACE_Mutex public: ACE_Mutex (int type = USYNC_THREAD, LPCTSTR name = 0, - void *arg = 0); + ACE_mutexattr_t *arg = 0); // Initialize the mutex. ~ACE_Mutex (void); @@ -1078,11 +1078,13 @@ class ACE_Export ACE_Thread_Mutex // ACE_Thread_Mutex is recursive on some platforms (like // Win32). However, on most platforms (like Solaris) it is not // recursive. To be totally safe and portable, developers - // should use ACE_Recursive_Thread_Mutex when they need a + // should use <ACE_Recursive_Thread_Mutex> when they need a // recursive mutex. friend class ACE_Condition_Thread_Mutex; public: - ACE_Thread_Mutex (LPCTSTR name = 0, void *arg = 0); + ACE_Thread_Mutex (LPCTSTR name = 0, + ACE_mutexattr_t *attributes = 0); + // Constructor. ~ACE_Thread_Mutex (void); // Implicitly destroy the mutex. @@ -1332,7 +1334,7 @@ class ACE_Export ACE_Recursive_Thread_Mutex // release of a mutex that occurs in the same thread. public: ACE_Recursive_Thread_Mutex (LPCTSTR name = 0, - void *arg = 0); + ACE_mutexattr_t *arg = 0); // Initialize a recursive mutex. ~ACE_Recursive_Thread_Mutex (void); diff --git a/ace/Synch_T.h b/ace/Synch_T.h index e9e27d2c85b..55914136c08 100644 --- a/ace/Synch_T.h +++ b/ace/Synch_T.h @@ -10,7 +10,7 @@ // Synch_T.h // // = AUTHOR -// Doug Schmidt +// Douglas C. Schmidt <schmidt@uci.edu> // // ============================================================================ diff --git a/ace/Token.cpp b/ace/Token.cpp index c758932c28a..7b8b67fb94f 100644 --- a/ace/Token.cpp +++ b/ace/Token.cpp @@ -160,7 +160,7 @@ ACE_Token::ACE_Token_Queue::insert_entry (ACE_Token::ACE_Token_Queue_Entry &entr } ACE_Token::ACE_Token (LPCTSTR name, void *any) - : lock_ (name, any), + : lock_ (name, (ACE_mutexattr_t *) any), owner_ (ACE_OS::NULL_thread), in_use_ (0), waiters_ (0), diff --git a/tests/Thread_Mutex_Test.cpp b/tests/Thread_Mutex_Test.cpp index b801ccc8250..24d6b5484cc 100644 --- a/tests/Thread_Mutex_Test.cpp +++ b/tests/Thread_Mutex_Test.cpp @@ -28,23 +28,30 @@ static void * test (void *args) { ACE_Thread_Mutex *mutex = (ACE_Thread_Mutex *) args; - ACE_UNUSED_ARG (mutex); // To suppress ghs warning about unused - // local variable "mutex". + ACE_UNUSED_ARG (mutex); // Suppress ghs warning about unused local "mutex". ACE_OS::srand (ACE_OS::time (0)); for (size_t i = 0; i < ACE_MAX_ITERATIONS / 2; i++) { - ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%P|%t) = trying to acquire on iteration %d\n"), i)); - ACE_ASSERT (mutex->acquire () == 0); - ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%P|%t) = acquired on iteration %d\n"), i)); + ACE_DEBUG ((LM_DEBUG, + ASYS_TEXT ("(%P|%t) = trying to acquire on iteration %d\n"), + i)); + int result = mutex->acquire (); + ACE_ASSERT (result == 0); + ACE_DEBUG ((LM_DEBUG, + ASYS_TEXT ("(%P|%t) = acquired on iteration %d\n"), + i)); // Sleep for a random amount of time between 0 and 2 seconds. // Note that it's ok to use rand() here because we are running // within the critical section defined by the Thread_Mutex. ACE_OS::sleep (ACE_OS::rand () % 2); - ACE_ASSERT (mutex->release () == 0); - ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("(%P|%t) = released on iteration %d\n"), i)); + result = mutex->release (); + ACE_ASSERT (result == 0); + ACE_DEBUG ((LM_DEBUG, + ASYS_TEXT ("(%P|%t) = released on iteration %d\n"), + i)); } return 0; @@ -61,7 +68,9 @@ spawn (void) ACE_THR_FUNC (test), (void *) &mutex, THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR ((LM_ERROR, ASYS_TEXT ("%p\n%a"), ASYS_TEXT ("thread create failed"))); + ACE_ERROR ((LM_ERROR, + ASYS_TEXT ("%p\n%a"), + ASYS_TEXT ("thread create failed"))); // Wait for the threads to exit. ACE_Thread_Manager::instance ()->wait (); |