OpenAFS
OpenAFS distributed network file system
/cygdrive/c/src/openafs/openafs.git/repo/src/rx/rx_pthread.h
00001 /*
00002  * Copyright 2000, International Business Machines Corporation and others.
00003  * All Rights Reserved.
00004  *
00005  * This software has been released under the terms of the IBM Public
00006  * License.  For details, see the LICENSE file in the top-level source
00007  * directory or online at http://www.openafs.org/dl/license10.html
00008  */
00009 
00010 /* rx_pthread.h defines the lock and cv primitives required for a thread
00011  * safe user mode rx. The current implemenation is only tested on Solaris.
00012  */
00013 
00014 #ifndef RX_PTHREAD_H
00015 #define RX_PTHREAD_H
00016 
00017 #ifndef RX_ENABLE_LOCKS
00018 #define RX_ENABLE_LOCKS 1
00019 #endif
00020 
00021 /* This turns out to be necessary even for fine grain locking. */
00022 #ifndef AFS_GLOBAL_RXLOCK_KERNEL
00023 #define AFS_GLOBAL_RXLOCK_KERNEL 1
00024 #endif
00025 
00026 /* Block signals to child threads. */
00027 #include <afs/pthread_nosigs.h>
00028 #include <afs/opr.h>
00029 
00030 #ifdef AFS_NT40_ENV
00031 #include <wtypes.h>
00032 #include <winbase.h>
00033 #include <winsock2.h>
00034 #include <pthread.h>
00035 
00036 typedef pthread_mutex_t afs_kmutex_t;
00037 typedef pthread_cond_t afs_kcondvar_t;
00038 #ifdef  RX_ENABLE_LOCKS
00039 #define MUTEX_ISMINE(l) (pthread_mutex_trylock(l) == EDEADLK)
00040 #else
00041 #define MUTEX_ISMINE(l) (1)
00042 #endif
00043 
00044 #define pthread_yield() Sleep(0)
00045 
00046 #else /* AFS_NT40_ENV */
00047 
00048 #include <pthread.h>
00049 typedef pthread_mutex_t afs_kmutex_t;
00050 typedef pthread_cond_t afs_kcondvar_t;
00051 
00052 #if !defined(pthread_yield) && defined(AFS_SUN5_ENV)
00053 #define pthread_yield() thr_yield()
00054 #endif
00055 #if !defined(pthread_yield) && !defined(AFS_AIX_ENV)
00056 #define pthread_yield() sleep(0)
00057 #endif
00058 #if !defined(pthread_yield) && (_XOPEN_SOURCE + 0) >= 500
00059 #define pthread_yield() sched_yield()
00060 #endif
00061 
00062 
00063 #ifndef MUTEX_ISMINE
00064 /* Only used for debugging. */
00065 #ifdef AFS_SUN5_ENV
00066 /* synch.h says mutex_t and pthread_mutex_t are always the same */
00067 #include <synch.h>
00068 #define MUTEX_ISMINE(l) MUTEX_HELD((mutex_t *) l)
00069 #else /* AFS_SUN5_ENV */
00070 #define MUTEX_ISMINE(l) (1)
00071 #endif /* AFS_SUN5_ENV */
00072 #endif /* !MUTEX_ISMINE */
00073 #endif /* AFS_NT40_ENV */
00074 
00075 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
00076 
00077 #ifdef AFS_PTHREAD_ENV
00078 #ifdef MUTEX_INIT
00079 #undef MUTEX_INIT
00080 #endif
00081 #define MUTEX_INIT(a, b, c, d) opr_Verify(pthread_mutex_init(a, NULL) == 0)
00082 
00083 #ifdef MUTEX_DESTROY
00084 #undef MUTEX_DESTROY
00085 #endif
00086 #define MUTEX_DESTROY(l) opr_Verify(pthread_mutex_destroy(l) == 0)
00087 
00088 #ifdef MUTEX_ENTER
00089 #undef MUTEX_ENTER
00090 #endif
00091 #define MUTEX_ENTER(l) opr_Verify(pthread_mutex_lock(l) == 0)
00092 
00093 #ifdef MUTEX_TRYENTER
00094 #undef MUTEX_TRYENTER
00095 #endif
00096 #define MUTEX_TRYENTER(l) pthread_mutex_trylock(l) ? 0 : 1
00097 
00098 #ifdef MUTEX_EXIT
00099 #undef MUTEX_EXIT
00100 #endif
00101 #define MUTEX_EXIT(l) opr_Verify(pthread_mutex_unlock(l) == 0)
00102 
00103 #ifdef CV_INIT
00104 #undef CV_INIT
00105 #endif
00106 #define CV_INIT(cv, a, b, c) opr_Verify(pthread_cond_init(cv, NULL) == 0)
00107 
00108 #ifdef CV_DESTROY
00109 #undef CV_DESTROY
00110 #endif
00111 #define CV_DESTROY(cv) opr_Verify(pthread_cond_destroy(cv) == 0)
00112 
00113 #ifdef CV_WAIT
00114 #undef CV_WAIT
00115 #endif
00116 #define CV_WAIT(cv, l) opr_Verify(pthread_cond_wait(cv, l) == 0)
00117 
00118 #ifdef CV_TIMEDWAIT
00119 #undef CV_TIMEDWAIT
00120 #endif
00121 #define CV_TIMEDWAIT(cv, l, t) pthread_cond_timedwait(cv, l, t)
00122 
00123 #ifdef CV_SIGNAL
00124 #undef CV_SIGNAL
00125 #endif
00126 #define CV_SIGNAL(cv) opr_Verify(pthread_cond_signal(cv) == 0)
00127 
00128 #ifdef CV_BROADCAST
00129 #undef CV_BROADCAST
00130 #endif
00131 #define CV_BROADCAST(cv) opr_Verify(pthread_cond_broadcast(cv) == 0)
00132 
00133 #endif /* AFS_PTHREAD_ENV */
00134 
00135 
00136 #endif /* RX_PTHREAD_H */
 All Data Structures Files Functions Variables