Coda Distributed File System
rvm_pthread.h
Go to the documentation of this file.
1/* BLURB lgpl
2
3 Coda File System
4 Release 7
5
6 Copyright (c) 1987-2019 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU Library General Public Licence Version 2, as
11shown in the file LICENSE. The technical and financial contributors to
12Coda are listed in the file CREDITS.
13
14 Additional copyrights
15 none currently
16
17#*/
18
19#ifndef _RVM_PTHREAD_H_
20#define _RVM_PTHREAD_H_
21
22/* pthread compatibility for RVM */
23
24#include <pthread.h>
25
26/* used in pthread_create */
27extern pthread_t rvm_pthreadid;
28
29/* used in pthread_join */
30extern void *rvm_ptstat;
31extern int rvm_join_res;
32
33#define BOGUSCODE (BOGUS_USE_OF_PTHREADS) /* force compilation error */
34
35#define RVM_MUTEX pthread_mutex_t
36#define RVM_CONDITION pthread_cond_t
37
38/*
39 * Unfortunately, pthread mutexes cannot be initialized statically: they
40 * must be initialized by a call to pthread_mutex_init. Oh well.
41 * This means that some locking situations won't work properly.
42 * I'll define MUTEX_INITIALIZER to be BOGUSCODE to make this more
43 * explicit to pthreads clients.
44 */
45
46/* That's nonsense, the following is from pthread_mutex(3):
47 *
48 * Variables of type pthread_mutex_t can also be initialized statically
49 * using the constants PTHREAD_MUTEX_INITIALIZER (for fast mutexes),
50 * PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP (for recursive mutexes), and
51 * PTHREADS_ERRORCHECK_MUTEX_INITIALIZER_MP (for error checking mutexes).
52 *
53 * --JH
54 */
55
56#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
57
58/* Supported cthread definitions: */
59
60#define cthread_t pthread_t *
61
62#define cthread_fork(fname, arg) \
63 (pthread_create(&rvm_pthreadid, NULL, (void *(*)(void *))(fname), (arg)), \
64 &rvm_pthreadid)
65
66/*
67 * Returns either NULL or the address of the pthread_status block.
68 * Unfortunately, it appears that chtread_join didn't have a way of
69 * saying "badthread, can't do it," so I'm not sure of the best way to
70 * do this.
71 */
72#define cthread_join(t) \
73 (rvm_join_res = pthread_join(*(t), &rvm_ptstat), \
74 (rvm_join_res) ? NULL : rvm_ptstat)
75
76#define cthread_init() \
77 do { \
78 } while (0)
79
80#define cthread_uninit(retval) \
81 { \
82 } /* nop */
83
84#define cthread_exit(retval) (pthread_exit((void *)(retval)))
85
86#define cthread_yield() \
87 do { \
88 } while (0)
89
90#define condition_wait(c, m) (pthread_cond_wait((c), (m)))
91
92#define condition_signal(c) (pthread_cond_signal((c)))
93
94#define condition_broadcast(c) (pthread_cond_broadcast((c)))
95
96/* This is defined just as in rvm_lwp.h, but is almost surely a bug */
97#define condition_clear(c) /* nop */
98
99#define condition_init(c) (pthread_cond_init((c), NULL))
100
101#define mutex_init(m) (pthread_mutex_init((m), NULL))
102#define mutex_clear(m) (pthread_mutex_destroy(m), NULL)
103
104/* This doesn't work for some reason... */
105/*
106#define LOCK_FREE(m) (rvm_ptlocked = pthread_mutex_trylock(&(m)), \
107 if (rvm_ptlocked) {pthread_mutex_unlock(&(m))}, \
108 rvm_ptlocked)
109*/
110/* defined in rvm_pthread.c */
111extern int rvm_lock_free(pthread_mutex_t *m);
112#define LOCK_FREE(m) (rvm_lock_free(&(m)))
113
114#define cthread_self() (rvm_pthreadid = pthread_self(), &rvm_pthreadid)
115
116#ifdef DEBUGRVM
117#define mutex_lock(m) \
118 do { \
119 printf("mutex_lock OL(0x%x)%s:%d...", (m), __FILE__, __LINE__); \
120 pthread_mutex_lock((m)); \
121 printf("done\n"); \
122 } while (0)
123#define mutex_unlock(m) \
124 do { \
125 printf("mutex_unlock RL(0x%x)%s:%d...", (m), __FILE__, __LINE__); \
126 pthread_mutex_unlock((m)); \
127 printf("done\n"); \
128 } while (0)
129#else /* DEBUGRVM */
130#define mutex_lock(m) (pthread_mutex_lock((m)))
131#define mutex_unlock(m) (pthread_mutex_unlock((m)))
132#endif /* DEBUGRVM */
133
134/* Unsupported cthread calls */
135
136#define mutex_alloc() BOGUSCODE
137#define mutex_set_name(m, x) BOGUSCODE
138#define mutex_name(m) BOGUSCODE
139#define mutex_free(m) BOGUSCODE
140
141#define condition_alloc() BOGUSCODE
142#define condition_set_name(c, x) BOGUSCODE
143#define condition_name(c) BOGUSCODE
144#define condition_free(c) BOGUSCODE
145
146#define cthread_detach() BOGUSCODE
147#define cthread_sp() BOGUSCODE
148#define cthread_assoc(id, t) BOGUSCODE
149#define cthread_set_name BOGUSCODE
150#define cthread_name BOGUSCODE
151#define cthread_count() BOGUSCODE
152#define cthread_set_limit BOGUSCODE
153#define cthread_limit() BOGUSCODE
154#define cthread_set_data(t, x) BOGUSCODE
155#define cthread_data(t) BOGUSCODE
156
157#endif /* _RVM_PTHREAD_H_ */
int rvm_lock_free(pthread_mutex_t *m)
Definition: rvm_pthread.c:26
void * rvm_ptstat
Definition: rvm_pthread.c:23
pthread_t rvm_pthreadid
Definition: rvm_pthread.c:22
int rvm_join_res
Definition: rvm_pthread.c:24