2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* rx_pthread.h defines the lock and cv primitives required for a thread
11 * safe user mode rx. The current implemenation is only tested on Solaris.
17 #ifndef RX_ENABLE_LOCKS
18 #define RX_ENABLE_LOCKS 1
21 /* This turns out to be necessary even for fine grain locking. */
22 #ifndef AFS_GLOBAL_RXLOCK_KERNEL
23 #define AFS_GLOBAL_RXLOCK_KERNEL 1
26 /* Block signals to child threads. */
27 #include <afs/pthread_nosigs.h>
35 typedef pthread_mutex_t afs_kmutex_t;
36 typedef pthread_cond_t afs_kcondvar_t;
37 #ifdef RX_ENABLE_LOCKS
38 #define MUTEX_ISMINE(l) (pthread_mutex_trylock(l) == EDEADLK)
40 #define MUTEX_ISMINE(l) (1)
43 #define pthread_yield() Sleep(0)
45 #else /* AFS_NT40_ENV */
48 typedef pthread_mutex_t afs_kmutex_t;
49 typedef pthread_cond_t afs_kcondvar_t;
51 #if !defined(pthread_yield) && defined(AFS_SUN5_ENV)
52 #define pthread_yield() thr_yield()
54 #if !defined(pthread_yield) && !defined(AFS_AIX_ENV)
55 #define pthread_yield() sleep(0)
57 #if !defined(pthread_yield) && (_XOPEN_SOURCE + 0) >= 500
58 #define pthread_yield() sched_yield()
63 /* Only used for debugging. */
65 /* synch.h says mutex_t and pthread_mutex_t are always the same */
67 #define MUTEX_ISMINE(l) MUTEX_HELD((mutex_t *) l)
68 #else /* AFS_SUN5_ENV */
69 #define MUTEX_ISMINE(l) (1)
70 #endif /* AFS_SUN5_ENV */
71 #endif /* !MUTEX_ISMINE */
72 #endif /* AFS_NT40_ENV */
74 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
76 #ifdef AFS_PTHREAD_ENV
80 #define MUTEX_INIT(a, b, c, d) osi_Assert(pthread_mutex_init(a, NULL) == 0)
85 #define MUTEX_DESTROY(l) osi_Assert(pthread_mutex_destroy(l) == 0)
90 #define MUTEX_ENTER(l) osi_Assert(pthread_mutex_lock(l) == 0)
95 #define MUTEX_TRYENTER(l) pthread_mutex_trylock(l) ? 0 : 1
100 #define MUTEX_EXIT(l) osi_Assert(pthread_mutex_unlock(l) == 0)
105 #define CV_INIT(cv, a, b, c) osi_Assert(pthread_cond_init(cv, NULL) == 0)
110 #define CV_DESTROY(cv) osi_Assert(pthread_cond_destroy(cv) == 0)
115 #define CV_WAIT(cv, l) osi_Assert(pthread_cond_wait(cv, l) == 0)
120 #define CV_SIGNAL(cv) osi_Assert(pthread_cond_signal(cv) == 0)
125 #define CV_BROADCAST(cv) osi_Assert(pthread_cond_broadcast(cv) == 0)
127 #endif /* AFS_PTHREAD_ENV */
130 #endif /* RX_PTHREAD_H */