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>
36 typedef pthread_mutex_t afs_kmutex_t;
37 typedef pthread_cond_t afs_kcondvar_t;
38 #ifdef RX_ENABLE_LOCKS
39 #define MUTEX_ISMINE(l) (pthread_mutex_trylock(l) == EDEADLK)
41 #define MUTEX_ISMINE(l) (1)
44 #define pthread_yield() Sleep(0)
46 #else /* AFS_NT40_ENV */
49 typedef pthread_mutex_t afs_kmutex_t;
50 typedef pthread_cond_t afs_kcondvar_t;
52 #if !defined(pthread_yield) && defined(AFS_SUN5_ENV)
53 #define pthread_yield() thr_yield()
55 #if !defined(pthread_yield) && !defined(AFS_AIX_ENV)
56 #define pthread_yield() sleep(0)
58 #if !defined(pthread_yield) && (_XOPEN_SOURCE + 0) >= 500
59 #define pthread_yield() sched_yield()
64 /* Only used for debugging. */
66 /* synch.h says mutex_t and pthread_mutex_t are always the same */
68 #define MUTEX_ISMINE(l) MUTEX_HELD((mutex_t *) l)
69 #else /* AFS_SUN5_ENV */
70 #define MUTEX_ISMINE(l) (1)
71 #endif /* AFS_SUN5_ENV */
72 #endif /* !MUTEX_ISMINE */
73 #endif /* AFS_NT40_ENV */
75 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
77 #ifdef AFS_PTHREAD_ENV
81 #define MUTEX_INIT(a, b, c, d) opr_Verify(pthread_mutex_init(a, NULL) == 0)
86 #define MUTEX_DESTROY(l) opr_Verify(pthread_mutex_destroy(l) == 0)
91 #define MUTEX_ENTER(l) opr_Verify(pthread_mutex_lock(l) == 0)
96 #define MUTEX_TRYENTER(l) pthread_mutex_trylock(l) ? 0 : 1
101 #define MUTEX_EXIT(l) opr_Verify(pthread_mutex_unlock(l) == 0)
106 #define CV_INIT(cv, a, b, c) opr_Verify(pthread_cond_init(cv, NULL) == 0)
111 #define CV_DESTROY(cv) opr_Verify(pthread_cond_destroy(cv) == 0)
116 #define CV_WAIT(cv, l) opr_Verify(pthread_cond_wait(cv, l) == 0)
121 #define CV_TIMEDWAIT(cv, l, t) pthread_cond_timedwait(cv, l, t)
126 #define CV_SIGNAL(cv) opr_Verify(pthread_cond_signal(cv) == 0)
131 #define CV_BROADCAST(cv) opr_Verify(pthread_cond_broadcast(cv) == 0)
133 #endif /* AFS_PTHREAD_ENV */
136 #endif /* RX_PTHREAD_H */