File: synch.tex

package info (click to toggle)
oskit 0.97.20000202-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 58,008 kB
  • ctags: 172,612
  • sloc: ansic: 832,827; asm: 7,640; sh: 3,920; yacc: 3,664; perl: 1,457; lex: 427; makefile: 337; csh: 141; awk: 78
file content (256 lines) | stat: -rw-r--r-- 7,836 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
%
% Copyright (c) 1997-1999 University of Utah and the Flux Group.
% All rights reserved.
% 
% The University of Utah grants you the right to copy and reproduce this
% document or portions thereof for academic, research, evaluation, and
% personal use only, provided that (1) the title page appears prominently,
% and (2) these copyright and permission notices are retained in all copies.
% To arrange for alternate terms, contact the University of Utah at
% csl-dist@cs.utah.edu or +1-801-585-3271.
%
\label{synch}

\apiintf{oskit_lock}{Thread-safe lock interface}

The {\tt oskit_lock} COM interface allows components to protect data
structures from concurrent access by multiple threads. The interface is
intended to be generic so that components do not need to know the specifics
of any particular thread system. The user of a lock should be prepared for
the possibility that the thread will be put to sleep if the lock cannot be
granted. There are two variants supported; a regular lock and a critical
lock. A critical lock differs only in that interrupts are blocked while the
lock is held. The {\tt oskit_lock} COM interface inherits from {\tt
oskit_iunknown}, and has the following additional methods:

\begin{icsymlist}
\item[lock]
	Lock a lock.
\item[unlock]
	Unlock a lock.
\end{icsymlist}

\api{lock}{Lock a lock}
\begin{apisyn}
	\cinclude{oskit/com/lock.h}

	\funcproto OSKIT_COMDECL
	oskit_lock_lock(oskit_lock_t *lock);
\end{apisyn}
\begin{apidesc}
	This method attempts to lock {\tt lock}. If the lock cannot be
	immediately granted, the current thread is put to sleep until the
	lock can be granted.
\end{apidesc}
\begin{apiparm}
	\item[lock]
		The {\tt oskit_lock} COM interface for the lock.
\end{apiparm}
\begin{apiret}
	Returns 0 on success, or an error code specified in
	{\tt <oskit/error.h>}, on error.
\end{apiret}


\api{lock}{Unlock a lock}
\begin{apisyn}
	\cinclude{oskit/com/lock.h}

	\funcproto OSKIT_COMDECL
	oskit_lock_unlock(oskit_lock_t *lock);
\end{apisyn}
\begin{apidesc}
	This method unlocks {\tt lock}. If there are any threads waiting for
	the lock, one will be woken up and granted the lock.
\end{apidesc}
\begin{apiparm}
	\item[lock]
		The {\tt oskit_lock} COM interface for the lock.
\end{apiparm}
\begin{apiret}
	Returns 0 on success, or an error code specified in
	{\tt <oskit/error.h>}, on error.
\end{apiret}


\apiintf{oskit_condvar}{Condition variable interface}

The {\tt oskit_condvar} COM interface allows components to wait for
conditions. The interface is intended to be generic so that components do
not need to know the specifics of any particular thread system. A condition
is typically combined with an {\tt oskit_lock} object to facilitate building
monitor type objects. Attempting to wait on a condition without supplying a
locked {\tt oskit_lock} object results in undefined behavior. The {\tt
oskit_lock} COM interface inherits from {\tt oskit_iunknown}, and has the
following additional methods:

\begin{icsymlist}
\item[wait]
	Wait on a condition variable.
\item[signal]
	Signal a condition variable.
\item[broadcast]
	Broadcast a condition variable.
\end{icsymlist}

\api{wait}{Wait on a condition variable}
\begin{apisyn}
	\cinclude{oskit/com/condvar.h}

	\funcproto OSKIT_COMDECL
	oskit_condvar_wait(oskit_condvar_t *condvar, oskit_lock_t *lock);
\end{apisyn}
\begin{apidesc}
	This method causes the current thread is to wait until the
	condition variable is signaled or broadcast. The {\tt oskit_lock}
	object must be locked when called. The lock is released prior to
	waiting, and reacquired before returning.
\end{apidesc}
\begin{apiparm}
	\item[condvar]
		The {\tt oskit_condvar} COM interface for the condition
		variable.
	\item[lock]
		The {\tt oskit_lock} COM interface for the lock.
\end{apiparm}
\begin{apiret}
	Returns 0 on success, or an error code specified in
	{\tt <oskit/error.h>}, on error.
\end{apiret}

\api{signal}{Signal a condition variable}
\begin{apisyn}
	\cinclude{oskit/com/condvar.h}

	\funcproto OSKIT_COMDECL
	oskit_condvar_signal(oskit_condvar_t *condvar);
\end{apisyn}
\begin{apidesc}
	Wake up exactly one thread waiting on the condition variable object
	{\tt condvar}.
\end{apidesc}
\begin{apiparm}
	\item[condvar]
		The {\tt oskit_condvar} COM interface for the condition
		variable.
\end{apiparm}
\begin{apiret}
	Returns 0 on success, or an error code specified in
	{\tt <oskit/error.h>}, on error.
\end{apiret}

\api{broadcast}{Broadcast a condition variable}
\begin{apisyn}
	\cinclude{oskit/com/condvar.h}

	\funcproto OSKIT_COMDECL
	oskit_condvar_broadcast(oskit_condvar_t *condvar);
\end{apisyn}
\begin{apidesc}
	Wake up all threads waiting on the condition variable object
	{\tt condvar}.
\end{apidesc}
\begin{apiparm}
	\item[condvar]
		The {\tt oskit_condvar} COM interface for the condition
		variable.
\end{apiparm}
\begin{apiret}
	Returns 0 on success, or an error code specified in
	{\tt <oskit/error.h>}, on error.
\end{apiret}


\apiintf{oskit_lock_mgr}{Lock manager: Interface for creating locks and
                         condition variables}
\label{lock-mgr}

The lock manager is registered in the services registry (See
Section~\ref{oskit-services}) when the threading system (if it is included)
is initialized. Components that need to protect data structures can query
the services registry for the lock manager. Since the lock manager will
only be registered by the threading system, the client can assume that the
absence of a lock manager implies a single threaded system (locks are
unnecessary). The {\tt oskit_lock_mgr} COM interface inherits from {\tt
oskit_iunknown}, and has the following additional methods:

\begin{csymlist}
\item[allocate_lock]
	Allocate a lock object.
\item[allocate_critical_lock]
	Allocate a critical lock object.
\end{csymlist}

\api{allocate_lock}{Allocate a thread-safe lock}
\begin{apisyn}
	\cinclude{oskit/com/lock_mgr.h}

	\funcproto OSKIT_COMDECL
	oskit_lock_mgr_allocate_lock(oskit_lock_mgr_t *lmgr,
				    \outparam oskit_lock_t *out_lock);
\end{apisyn}
\begin{apidesc}
	This method returns an {\tt oskit_lock_t} COM interface in {\tt
	out_lock}.
\end{apidesc}
\begin{apiparm}
	\item[lmgr]
		The lock manager COM interface.
	\item[out_lock]
		The {\tt oskit_lock} COM interface for the new lock.
\end{apiparm}
\begin{apiret}
	Returns 0 on success, or an error code specified in
	{\tt <oskit/error.h>}, on error.
\end{apiret}


\api{allocate_critical_lock}{Allocate a critical thread-safe lock}
\begin{apisyn}
	\cinclude{oskit/com/lock_mgr.h}

	\funcproto OSKIT_COMDECL
	oskit_lock_mgr_allocate_critical_lock(oskit_lock_mgr_t *lmgr,
				    \outparam oskit_lock_t *out_lock);
\end{apisyn}
\begin{apidesc}
	This method returns an {\tt oskit_lock_t} COM interface in {\tt
	out_lock}. The lock is flagged as critical so that interrupts are
	blocked while the lock is held.
\end{apidesc}
\begin{apiparm}
	\item[lmgr]
		The lock manager COM interface.
	\item[out_lock]
		The {\tt oskit_lock} COM interface for the new lock.
\end{apiparm}
\begin{apiret}
	Returns 0 on success, or an error code specified in
	{\tt <oskit/error.h>}, on error.
\end{apiret}

\api{allocate_condvar}{Allocate a condition variable}
\begin{apisyn}
	\cinclude{oskit/com/lock_mgr.h}

	\funcproto OSKIT_COMDECL
	oskit_lock_mgr_allocate_condvar(oskit_lock_mgr_t *lmgr,
				       \outparam oskit_condvar_t *out_condvar);
\end{apisyn}
\begin{apidesc}
	This method returns an {\tt oskit_condvar_t} COM interface in {\tt
	out_condvar}. Condition variables may be used in conjunction with locks
	to form monitors.
\end{apidesc}
\begin{apiparm}
	\item[lmgr]
		The lock manager COM interface.
	\item[out_condvar]
		The {\tt oskit_condvar} COM interface for the new condition
		variable.
\end{apiparm}
\begin{apiret}
	Returns 0 on success, or an error code specified in
	{\tt <oskit/error.h>}, on error.
\end{apiret}