From: Ken Raeburn Date: Thu, 5 Aug 2004 07:42:46 +0000 (+0000) Subject: * k5-thread.h [HAVE_PTHREAD]: Include sched.h if DEBUG_THREADS_SLOW is defined. X-Git-Tag: krb5-1.4-beta1~166 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fe590f6e3e7c29c5ea7e3e1c94365c76ee9c13c7;p=krb5.git * k5-thread.h [HAVE_PTHREAD]: Include sched.h if DEBUG_THREADS_SLOW is defined. (MAYBE_SCHED_YIELD) [HAVE_PTHREAD]: Define, to call sched_yield or not, depending on DEBUG_THREADS_SLOW. (k5_os_mutex_lock, k5_os_mutex_unlock) [HAVE_PTHREAD]: Use MAYBE_SCHED_YIELD. (DEBUG_THREADS_SLOW): Define. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16642 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/ChangeLog b/src/include/ChangeLog index 9ebf8d097..74894bb21 100644 --- a/src/include/ChangeLog +++ b/src/include/ChangeLog @@ -1,3 +1,13 @@ +2004-08-05 Ken Raeburn + + * k5-thread.h [HAVE_PTHREAD]: Include sched.h if + DEBUG_THREADS_SLOW is defined. + (MAYBE_SCHED_YIELD) [HAVE_PTHREAD]: Define, to call sched_yield or + not, depending on DEBUG_THREADS_SLOW. + (k5_os_mutex_lock, k5_os_mutex_unlock) [HAVE_PTHREAD]: Use + MAYBE_SCHED_YIELD. + (DEBUG_THREADS_SLOW): Define. + 2004-08-03 Ken Raeburn * configure.in: Actually check for pthread_mutex_lock. diff --git a/src/include/k5-thread.h b/src/include/k5-thread.h index 97247c5b8..f9c39ef37 100644 --- a/src/include/k5-thread.h +++ b/src/include/k5-thread.h @@ -139,6 +139,7 @@ #define DEBUG_THREADS #define DEBUG_THREADS_LOC +#define DEBUG_THREADS_SLOW /* permit debugging stuff that'll slow things down */ #undef DEBUG_THREADS_STATS #include @@ -417,6 +418,13 @@ typedef struct { #define k5_pthread_assert_unlocked(M) (0) #define k5_pthread_assert_locked(M) (0) +#ifdef DEBUG_THREADS_SLOW +# include +# define MAYBE_SCHED_YIELD() ((void)sched_yield()) +#else +# define MAYBE_SCHED_YIELD() ((void)0) +#endif + #ifdef USE_PTHREAD_LOCK_ONLY_IF_LOADED # define K5_OS_MUTEX_PARTIAL_INITIALIZER \ @@ -435,14 +443,21 @@ typedef struct { ? pthread_mutex_destroy(&(M)->p) \ : 0)) -# define k5_os_mutex_lock(M) \ - (K5_PTHREADS_LOADED \ - ? pthread_mutex_lock(&(M)->p) \ - : k5_os_nothread_mutex_lock(&(M)->n)) -# define k5_os_mutex_unlock(M) \ - (K5_PTHREADS_LOADED \ - ? pthread_mutex_unlock(&(M)->p) \ - : k5_os_nothread_mutex_unlock(&(M)->n)) +static inline int k5_os_mutex_lock(k5_os_mutex *m) +{ + int r; + if (K5_PTHREADS_LOADED) + r = pthread_mutex_lock(&m->p); + else + r = k5_os_nothread_mutex_lock(&m->n); + MAYBE_SCHED_YIELD(); + return r; +} +# define k5_os_mutex_unlock(M) \ + (MAYBE_SCHED_YIELD(), \ + (K5_PTHREADS_LOADED \ + ? pthread_mutex_unlock(&(M)->p) \ + : k5_os_nothread_mutex_unlock(&(M)->n))) # define k5_os_mutex_assert_unlocked(M) \ (K5_PTHREADS_LOADED \ @@ -462,8 +477,13 @@ typedef struct { # define k5_os_mutex_init(M) pthread_mutex_init(&(M)->p, 0) # define k5_os_mutex_destroy(M) pthread_mutex_destroy(&(M)->p) -# define k5_os_mutex_lock(M) pthread_mutex_lock(&(M)->p) -# define k5_os_mutex_unlock(M) pthread_mutex_unlock(&(M)->p) +static inline int k5_os_mutex_lock(k5_os_mutex *m) +{ + int r = pthread_mutex_lock(&m->p); + MAYBE_SCHED_YIELD(); + return r; +} +# define k5_os_mutex_unlock(M) (MAYBE_SCHED_YIELD(),pthread_mutex_unlock(&(M)->p)) # define k5_os_mutex_assert_unlocked(M) k5_pthread_assert_unlocked(&(M)->p) # define k5_os_mutex_assert_locked(M) k5_pthread_assert_locked(&(M)->p)