ReactOS  0.4.14-dev-98-gb0d4763
reentrant.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 1997,98 The NetBSD Foundation, Inc.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to The NetBSD Foundation
6  * by J.T. Conklin.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * 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.
16  * 3. All advertising materials mentioning features or use of this software
17  * must display the following acknowledgement:
18  * This product includes software developed by the NetBSD
19  * Foundation, Inc. and its contributors.
20  * 4. Neither the name of The NetBSD Foundation nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $FreeBSD: src/lib/libc/include/reentrant.h,v 1.2 2002/11/01 09:37:17 dfr Exp $
37  */
38 
39 /*
40  * Requirements:
41  *
42  * 1. The thread safe mechanism should be lightweight so the library can
43  * be used by non-threaded applications without unreasonable overhead.
44  *
45  * 2. There should be no dependency on a thread engine for non-threaded
46  * applications.
47  *
48  * 3. There should be no dependency on any particular thread engine.
49  *
50  * 4. The library should be able to be compiled without support for thread
51  * safety.
52  *
53  *
54  * Rationale:
55  *
56  * One approach for thread safety is to provide discrete versions of the
57  * library: one thread safe, the other not. The disadvantage of this is
58  * that libc is rather large, and two copies of a library which are 99%+
59  * identical is not an efficent use of resources.
60  *
61  * Another approach is to provide a single thread safe library. However,
62  * it should not add significant run time or code size overhead to non-
63  * threaded applications.
64  *
65  * Since the NetBSD C library is used in other projects, it should be
66  * easy to replace the mutual exclusion primitives with ones provided by
67  * another system. Similarly, it should also be easy to remove all
68  * support for thread safety completely if the target environment does
69  * not support threads.
70  *
71  *
72  * Implementation Details:
73  *
74  * The mutex primitives used by the library (mutex_t, mutex_lock, etc.)
75  * are macros which expand to the cooresponding primitives provided by
76  * the thread engine or to nothing. The latter is used so that code is
77  * not unreasonably cluttered with #ifdefs when all thread safe support
78  * is removed.
79  *
80  * The mutex macros can be directly mapped to the mutex primitives from
81  * pthreads, however it should be reasonably easy to wrap another mutex
82  * implementation so it presents a similar interface.
83  *
84  * Stub implementations of the mutex functions are provided with *weak*
85  * linkage. These functions simply return success. When linked with a
86  * thread library (i.e. -lpthread), the functions will override the
87  * stubs.
88  */
89 
90 /* NFSv4.1 client for Windows
91  * Copyright 2012 The Regents of the University of Michigan
92  *
93  * Olga Kornievskaia <aglo@umich.edu>
94  * Casey Bodley <cbodley@umich.edu>
95  *
96  * This library is free software; you can redistribute it and/or modify it
97  * under the terms of the GNU Lesser General Public License as published by
98  * the Free Software Foundation; either version 2.1 of the License, or (at
99  * your option) any later version.
100  *
101  * This library is distributed in the hope that it will be useful, but
102  * without any warranty; without even the implied warranty of merchantability
103  * or fitness for a particular purpose. See the GNU Lesser General Public
104  * License for more details.
105  *
106  * You should have received a copy of the GNU Lesser General Public License
107  * along with this library; if not, write to the Free Software Foundation,
108  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
109  */
110 
111 #ifndef _REENTRANT_H
112 #define _REENTRANT_H
113 //#include <pthread.h>
114 #include <libc_private.h>
115 
116 #include <stdlib.h>
117 
118 
119 #define mutex_t CRITICAL_SECTION
120 #define cond_t CONDITION_VARIABLE
121 #define rwlock_t SRWLOCK
122 
123 
124 #define thread_key_t DWORD
125 #define MUTEX_INITIALIZER -1 /*THIS_NEEDS_HELP*/
126 #define RWLOCK_INITIALIZER -1 /*THIS_NEEDS_HELP*/
127 #define mutex_init(m, a) InitializeCriticalSection(m)
128 #define mutex_lock(m) EnterCriticalSection(m)
129 #define mutex_unlock(m) LeaveCriticalSection(m)
130 #define mutex_trylock(m) TryEnterCriticalSection(m)
131 
132 #define cond_init(c, a, p) InitializeConditionVariable(c)
133 #define cond_signal(m) WakeConditionVariable(m)
134 #define cond_broadcast(m) WakeAllConditionVariable(m)
135 #define cond_wait(c, m) SleepConditionVariableCS(c, m, INFINITE)
136 #define cond_wait_timed(c, m, t) SleepConditionVariableCS(c, m, t)
137 
138 #define rwlock_init(l, a) InitializeSRWLock(l)
139 #define rwlock_rdlock(l) AcquireSRWLockShared(l)
140 #define rwlock_wrlock(l) AcquireSRWLockExclusive(l)
141 /* XXX Code will have to be changed to release the right kind!!! XXX */
142 #define rwlock_unlock(l) ReleaseSRWLockExclusive(l)
143 
144 #define thr_keycreate(k, d) ((*k) = TlsAlloc())
145 #define thr_keydelete(k) TlsFree(k)
146 #define thr_setspecific(k, p) TlsSetValue(k, p)
147 #define thr_getspecific(k) TlsGetValue(k)
148 #define thr_sigsetmask(f, n, o) dunno_sigmask(f, n, o)
149 
150 #define thr_self() GetCurrentThreadId()
151 #define thr_exit(x) ExitThread(x)
152 
153 /*
154 #define mutex_t pthread_mutex_t
155 #define cond_t pthread_cond_t
156 #define rwlock_t pthread_rwlock_t
157 
158 #define thread_key_t pthread_key_t
159 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
160 #define RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
161 #define mutex_init(m, a) pthread_mutex_init(m, a)
162 #define mutex_lock(m) pthread_mutex_lock(m)
163 #define mutex_unlock(m) pthread_mutex_unlock(m)
164 #define mutex_trylock(m) pthread_mutex_trylock(m)
165 
166 #define cond_init(c, a, p) pthread_cond_init(c, a)
167 #define cond_signal(m) pthread_cond_signal(m)
168 #define cond_broadcast(m) pthread_cond_broadcast(m)
169 #define cond_wait(c, m) pthread_cond_wait(c, m)
170 
171 #define rwlock_init(l, a) pthread_rwlock_init(l, a)
172 #define rwlock_rdlock(l) pthread_rwlock_rdlock(l)
173 #define rwlock_wrlock(l) pthread_rwlock_wrlock(l)
174 #define rwlock_unlock(l) pthread_rwlock_unlock(l)
175 
176 #define thr_keycreate(k, d) pthread_key_create(k, d)
177 #define thr_keydelete(k) pthread_key_delete(k)
178 #define thr_setspecific(k, p) pthread_setspecific(k, p)
179 #define thr_getspecific(k) pthread_getspecific(k)
180 #define thr_sigsetmask(f, n, o) pthread_sigmask(f, n, o)
181 
182 #define thr_self() pthread_self()
183 #define thr_exit(x) pthread_exit(x)
184 */
185 #endif /* reentrant.h */