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 /* Block signals to child threads. */
22 #include <afs/pthread_nosigs.h>
31 typedef pthread_mutex_t afs_kmutex_t;
32 typedef pthread_cond_t afs_kcondvar_t;
33 #ifdef RX_ENABLE_LOCKS
34 #define MUTEX_ISMINE(l) (pthread_mutex_trylock(l) == EDEADLK)
36 #define MUTEX_ISMINE(l) (1)
39 #define pthread_yield() Sleep(0)
41 #else /* AFS_NT40_ENV */
44 typedef pthread_mutex_t afs_kmutex_t;
45 typedef pthread_cond_t afs_kcondvar_t;
47 #if !defined(pthread_yield) && defined(AFS_SUN5_ENV)
48 #define pthread_yield() thr_yield()
50 #if !defined(pthread_yield) && !defined(AFS_AIX_ENV)
51 #define pthread_yield() sleep(0)
53 #if !defined(pthread_yield) && (_XOPEN_SOURCE + 0) >= 500
54 #define pthread_yield() sched_yield()
59 /* Only used for debugging. */
61 /* synch.h says mutex_t and pthread_mutex_t are always the same */
63 #define MUTEX_ISMINE(l) MUTEX_HELD((mutex_t *) l)
64 #else /* AFS_SUN5_ENV */
65 #define MUTEX_ISMINE(l) (1)
66 #endif /* AFS_SUN5_ENV */
67 #endif /* !MUTEX_ISMINE */
68 #endif /* AFS_NT40_ENV */
70 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
72 #ifdef AFS_PTHREAD_ENV
76 #define MUTEX_INIT(a, b, c, d) opr_Verify(pthread_mutex_init(a, NULL) == 0)
81 #define MUTEX_DESTROY(l) opr_Verify(pthread_mutex_destroy(l) == 0)
86 #define MUTEX_ENTER(l) opr_Verify(pthread_mutex_lock(l) == 0)
91 #define MUTEX_TRYENTER(l) pthread_mutex_trylock(l) ? 0 : 1
96 #define MUTEX_EXIT(l) opr_Verify(pthread_mutex_unlock(l) == 0)
101 #define CV_INIT(cv, a, b, c) opr_Verify(pthread_cond_init(cv, NULL) == 0)
106 #define CV_DESTROY(cv) opr_Verify(pthread_cond_destroy(cv) == 0)
111 #define CV_WAIT(cv, l) opr_Verify(pthread_cond_wait(cv, l) == 0)
116 #define CV_TIMEDWAIT(cv, l, t) pthread_cond_timedwait(cv, l, t)
121 #define CV_SIGNAL(cv) opr_Verify(pthread_cond_signal(cv) == 0)
126 #define CV_BROADCAST(cv) opr_Verify(pthread_cond_broadcast(cv) == 0)
128 #endif /* AFS_PTHREAD_ENV */
131 #endif /* RX_PTHREAD_H */