No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / krb5 / heim_threads.h
blob1c3dbe40d99a948210497fdeb5a7dbefe51ab1ba
1 /*
2 * Copyright (c) 2003 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 /* $Heimdal: heim_threads.h 14409 2004-12-18 16:03:38Z lha $
35 $NetBSD$ */
38 * Provide wrapper macros for thread synchronization primitives so we
39 * can use native thread functions for those operating system that
40 * supports it.
42 * This is so libkrb5.so (or more importantly, libgssapi.so) can have
43 * thread support while the program that that dlopen(3)s the library
44 * don't need to be linked to libpthread.
47 #ifndef HEIM_THREADS_H
48 #define HEIM_THREADS_H 1
50 /* assume headers already included */
52 #if defined(__NetBSD__) && __NetBSD_Version__ >= 106120000 && __NetBSD_Version__< 299001200 && defined(ENABLE_PTHREAD_SUPPORT)
54 /*
55 * NetBSD have a thread lib that we can use that part of libc that
56 * works regardless if application are linked to pthreads or not.
57 * NetBSD newer then 2.99.11 just use pthread.h, and the same thing
58 * will happen.
60 #include <threadlib.h>
62 #define HEIMDAL_MUTEX mutex_t
63 #define HEIMDAL_MUTEX_INITIALIZER MUTEX_INITIALIZER
64 #define HEIMDAL_MUTEX_init(m) mutex_init(m, NULL)
65 #define HEIMDAL_MUTEX_lock(m) mutex_lock(m)
66 #define HEIMDAL_MUTEX_unlock(m) mutex_unlock(m)
67 #define HEIMDAL_MUTEX_destroy(m) mutex_destroy(m)
69 #define HEIMDAL_RWLOCK rwlock_t
70 #define HEIMDAL_RWLOCK_INITIALIZER RWLOCK_INITIALIZER
71 #define HEIMDAL_RWLOCK_init(l) rwlock_init(l, NULL)
72 #define HEIMDAL_RWLOCK_rdlock(l) rwlock_rdlock(l)
73 #define HEIMDAL_RWLOCK_wrlock(l) rwlock_wrlock(l)
74 #define HEIMDAL_RWLOCK_tryrdlock(l) rwlock_tryrdlock(l)
75 #define HEIMDAL_RWLOCK_trywrlock(l) rwlock_trywrlock(l)
76 #define HEIMDAL_RWLOCK_unlock(l) rwlock_unlock(l)
77 #define HEIMDAL_RWLOCK_destroy(l) rwlock_destroy(l)
79 #define HEIMDAL_thread_key thread_key_t
80 #define HEIMDAL_key_create(k,d,r) do { r = thr_keycreate(k,d); } while(0)
81 #define HEIMDAL_setspecific(k,s,r) do { r = thr_setspecific(k,s); } while(0)
82 #define HEIMDAL_getspecific(k) thr_getspecific(k)
83 #define HEIMDAL_key_delete(k) thr_keydelete(k)
85 #elif defined(ENABLE_PTHREAD_SUPPORT) && (!defined(__NetBSD__) || __NetBSD_Version__ >= 299001200)
87 #include <pthread.h>
89 #define HEIMDAL_MUTEX pthread_mutex_t
90 #define HEIMDAL_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
91 #define HEIMDAL_MUTEX_init(m) pthread_mutex_init(m, NULL)
92 #define HEIMDAL_MUTEX_lock(m) pthread_mutex_lock(m)
93 #define HEIMDAL_MUTEX_unlock(m) pthread_mutex_unlock(m)
94 #define HEIMDAL_MUTEX_destroy(m) pthread_mutex_destroy(m)
96 #define HEIMDAL_RWLOCK rwlock_t
97 #define HEIMDAL_RWLOCK_INITIALIZER RWLOCK_INITIALIZER
98 #define HEIMDAL_RWLOCK_init(l) pthread_rwlock_init(l, NULL)
99 #define HEIMDAL_RWLOCK_rdlock(l) pthread_rwlock_rdlock(l)
100 #define HEIMDAL_RWLOCK_wrlock(l) pthread_rwlock_wrlock(l)
101 #define HEIMDAL_RWLOCK_tryrdlock(l) pthread_rwlock_tryrdlock(l)
102 #define HEIMDAL_RWLOCK_trywrlock(l) pthread_rwlock_trywrlock(l)
103 #define HEIMDAL_RWLOCK_unlock(l) pthread_rwlock_unlock(l)
104 #define HEIMDAL_RWLOCK_destroy(l) pthread_rwlock_destroy(l)
106 #define HEIMDAL_thread_key pthread_key_t
107 #define HEIMDAL_key_create(k,d,r) do { r = pthread_key_create(k,d); } while(0)
108 #define HEIMDAL_setspecific(k,s,r) do { r = pthread_setspecific(k,s); } while(0)
109 #define HEIMDAL_getspecific(k) pthread_getspecific(k)
110 #define HEIMDAL_key_delete(k) pthread_key_delete(k)
112 #elif defined(HEIMDAL_DEBUG_THREADS)
114 /* no threads support, just do consistency checks */
115 #include <stdlib.h>
117 #define HEIMDAL_MUTEX int
118 #define HEIMDAL_MUTEX_INITIALIZER 0
119 #define HEIMDAL_MUTEX_init(m) do { (*(m)) = 0; } while(0)
120 #define HEIMDAL_MUTEX_lock(m) do { if ((*(m))++ != 0) abort(); } while(0)
121 #define HEIMDAL_MUTEX_unlock(m) do { if ((*(m))-- != 1) abort(); } while(0)
122 #define HEIMDAL_MUTEX_destroy(m) do {if ((*(m)) != 0) abort(); } while(0)
124 #define HEIMDAL_RWLOCK rwlock_t int
125 #define HEIMDAL_RWLOCK_INITIALIZER 0
126 #define HEIMDAL_RWLOCK_init(l) do { } while(0)
127 #define HEIMDAL_RWLOCK_rdlock(l) do { } while(0)
128 #define HEIMDAL_RWLOCK_wrlock(l) do { } while(0)
129 #define HEIMDAL_RWLOCK_tryrdlock(l) do { } while(0)
130 #define HEIMDAL_RWLOCK_trywrlock(l) do { } while(0)
131 #define HEIMDAL_RWLOCK_unlock(l) do { } while(0)
132 #define HEIMDAL_RWLOCK_destroy(l) do { } while(0)
134 #define HEIMDAL_internal_thread_key 1
136 #else /* no thread support, no debug case */
138 #define HEIMDAL_MUTEX int
139 #define HEIMDAL_MUTEX_INITIALIZER 0
140 #define HEIMDAL_MUTEX_init(m) do { (void)(m); } while(0)
141 #define HEIMDAL_MUTEX_lock(m) do { (void)(m); } while(0)
142 #define HEIMDAL_MUTEX_unlock(m) do { (void)(m); } while(0)
143 #define HEIMDAL_MUTEX_destroy(m) do { (void)(m); } while(0)
145 #define HEIMDAL_RWLOCK rwlock_t int
146 #define HEIMDAL_RWLOCK_INITIALIZER 0
147 #define HEIMDAL_RWLOCK_init(l) do { } while(0)
148 #define HEIMDAL_RWLOCK_rdlock(l) do { } while(0)
149 #define HEIMDAL_RWLOCK_wrlock(l) do { } while(0)
150 #define HEIMDAL_RWLOCK_tryrdlock(l) do { } while(0)
151 #define HEIMDAL_RWLOCK_trywrlock(l) do { } while(0)
152 #define HEIMDAL_RWLOCK_unlock(l) do { } while(0)
153 #define HEIMDAL_RWLOCK_destroy(l) do { } while(0)
155 #define HEIMDAL_internal_thread_key 1
157 #endif /* no thread support */
159 #ifdef HEIMDAL_internal_thread_key
161 typedef struct heim_thread_key {
162 void *value;
163 void (*destructor)(void *);
164 } heim_thread_key;
166 #define HEIMDAL_thread_key heim_thread_key
167 #define HEIMDAL_key_create(k,d,r) \
168 do { (k)->value = NULL; (k)->destructor = (d); r = 0; } while(0)
169 #define HEIMDAL_setspecific(k,s,r) do { (k).value = s ; r = 0; } while(0)
170 #define HEIMDAL_getspecific(k) ((k).value)
171 #define HEIMDAL_key_delete(k) do { (*(k).destructor)((k).value); } while(0)
173 #undef HEIMDAL_internal_thread_key
174 #endif /* HEIMDAL_internal_thread_key */
176 #endif /* HEIM_THREADS_H */