* k5-thread.h [HAVE_PTHREAD]: Include sched.h if DEBUG_THREADS_SLOW is defined.
authorKen Raeburn <raeburn@mit.edu>
Thu, 5 Aug 2004 07:42:46 +0000 (07:42 +0000)
committerKen Raeburn <raeburn@mit.edu>
Thu, 5 Aug 2004 07:42:46 +0000 (07:42 +0000)
(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

src/include/ChangeLog
src/include/k5-thread.h

index 9ebf8d097f96f2d11843c484b18e7cd049432abd..74894bb21b34818f8064ed7801153da8f39094c5 100644 (file)
@@ -1,3 +1,13 @@
+2004-08-05  Ken Raeburn  <raeburn@mit.edu>
+
+       * 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  <raeburn@mit.edu>
 
        * configure.in: Actually check for pthread_mutex_lock.
index 97247c5b8fb81af0a099d0475fc226b2ff4e8330..f9c39ef370581c90c2ca10f767ab40a36cf79bff 100644 (file)
 
 #define DEBUG_THREADS
 #define DEBUG_THREADS_LOC
+#define DEBUG_THREADS_SLOW /* permit debugging stuff that'll slow things down */
 #undef DEBUG_THREADS_STATS
 
 #include <assert.h>
@@ -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 <sched.h>
+# 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)