Deleted Added
full compact
thr_cond.c (36830) thr_cond.c (40974)
1/*
2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 130 unchanged lines hidden (view full) ---

139 (rval = pthread_cond_init(cond,NULL)) == 0) {
140 /* Lock the condition variable structure: */
141 _SPINLOCK(&(*cond)->lock);
142
143 /* Process according to condition variable type: */
144 switch ((*cond)->c_type) {
145 /* Fast condition variable: */
146 case COND_TYPE_FAST:
1/*
2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 130 unchanged lines hidden (view full) ---

139 (rval = pthread_cond_init(cond,NULL)) == 0) {
140 /* Lock the condition variable structure: */
141 _SPINLOCK(&(*cond)->lock);
142
143 /* Process according to condition variable type: */
144 switch ((*cond)->c_type) {
145 /* Fast condition variable: */
146 case COND_TYPE_FAST:
147 /* Wait forever: */
148 _thread_run->wakeup_time.tv_sec = -1;
149
147 /*
148 * Queue the running thread for the condition
149 * variable:
150 */
151 _thread_queue_enq(&(*cond)->c_queue, _thread_run);
152
153 /* Unlock the mutex: */
150 /*
151 * Queue the running thread for the condition
152 * variable:
153 */
154 _thread_queue_enq(&(*cond)->c_queue, _thread_run);
155
156 /* Unlock the mutex: */
154 pthread_mutex_unlock(mutex);
157 if ((rval = pthread_mutex_unlock(mutex)) != 0) {
158 /*
159 * Cannot unlock the mutex, so remove the
160 * running thread from the condition
161 * variable queue:
162 */
163 _thread_queue_deq(&(*cond)->c_queue);
155
164
156 /* Wait forever: */
157 _thread_run->wakeup_time.tv_sec = -1;
165 /* Unlock the condition variable structure: */
166 _SPINUNLOCK(&(*cond)->lock);
167 } else {
168 /* Unlock the condition variable structure: */
169 _SPINUNLOCK(&(*cond)->lock);
158
170
159 /* Unlock the condition variable structure: */
160 _SPINUNLOCK(&(*cond)->lock);
171 /* Schedule the next thread: */
172 _thread_kern_sched_state(PS_COND_WAIT,
173 __FILE__, __LINE__);
161
174
162 /* Schedule the next thread: */
163 _thread_kern_sched_state(PS_COND_WAIT,
164 __FILE__, __LINE__);
165
166 /* Lock the condition variable structure: */
167 _SPINLOCK(&(*cond)->lock);
168
169 /* Lock the mutex: */
170 rval = pthread_mutex_lock(mutex);
175 /* Lock the mutex: */
176 rval = pthread_mutex_lock(mutex);
177 }
171 break;
172
173 /* Trap invalid condition variable types: */
174 default:
178 break;
179
180 /* Trap invalid condition variable types: */
181 default:
182 /* Unlock the condition variable structure: */
183 _SPINUNLOCK(&(*cond)->lock);
184
175 /* Return an invalid argument error: */
176 rval = EINVAL;
177 break;
178 }
179
185 /* Return an invalid argument error: */
186 rval = EINVAL;
187 break;
188 }
189
180 /* Unlock the condition variable structure: */
181 _SPINUNLOCK(&(*cond)->lock);
182 }
183
184 /* Return the completion status: */
185 return (rval);
186}
187
188int
189pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,

--- 34 unchanged lines hidden (view full) ---

224 /* Unlock the mutex: */
225 if ((rval = pthread_mutex_unlock(mutex)) != 0) {
226 /*
227 * Cannot unlock the mutex, so remove the
228 * running thread from the condition
229 * variable queue:
230 */
231 _thread_queue_deq(&(*cond)->c_queue);
190 }
191
192 /* Return the completion status: */
193 return (rval);
194}
195
196int
197pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,

--- 34 unchanged lines hidden (view full) ---

232 /* Unlock the mutex: */
233 if ((rval = pthread_mutex_unlock(mutex)) != 0) {
234 /*
235 * Cannot unlock the mutex, so remove the
236 * running thread from the condition
237 * variable queue:
238 */
239 _thread_queue_deq(&(*cond)->c_queue);
240
241 /* Unlock the condition variable structure: */
242 _SPINUNLOCK(&(*cond)->lock);
232 } else {
233 /* Unlock the condition variable structure: */
234 _SPINUNLOCK(&(*cond)->lock);
235
236 /* Schedule the next thread: */
237 _thread_kern_sched_state(PS_COND_WAIT,
238 __FILE__, __LINE__);
239
243 } else {
244 /* Unlock the condition variable structure: */
245 _SPINUNLOCK(&(*cond)->lock);
246
247 /* Schedule the next thread: */
248 _thread_kern_sched_state(PS_COND_WAIT,
249 __FILE__, __LINE__);
250
240 /* Lock the condition variable structure: */
241 _SPINLOCK(&(*cond)->lock);
242
243 /* Lock the mutex: */
244 if ((rval = pthread_mutex_lock(mutex)) != 0) {
245 }
246 /* Check if the wait timed out: */
247 else if (_thread_run->timeout) {
248 /* Return a timeout error: */
249 rval = ETIMEDOUT;
250 }
251 }
252 break;
253
254 /* Trap invalid condition variable types: */
255 default:
251 /* Lock the mutex: */
252 if ((rval = pthread_mutex_lock(mutex)) != 0) {
253 }
254 /* Check if the wait timed out: */
255 else if (_thread_run->timeout) {
256 /* Return a timeout error: */
257 rval = ETIMEDOUT;
258 }
259 }
260 break;
261
262 /* Trap invalid condition variable types: */
263 default:
264 /* Unlock the condition variable structure: */
265 _SPINUNLOCK(&(*cond)->lock);
266
256 /* Return an invalid argument error: */
257 rval = EINVAL;
258 break;
259 }
260
267 /* Return an invalid argument error: */
268 rval = EINVAL;
269 break;
270 }
271
261 /* Unlock the condition variable structure: */
262 _SPINUNLOCK(&(*cond)->lock);
263 }
264
265 /* Return the completion status: */
266 return (rval);
267}
268
269int
270pthread_cond_signal(pthread_cond_t * cond)

--- 80 unchanged lines hidden ---
272 }
273
274 /* Return the completion status: */
275 return (rval);
276}
277
278int
279pthread_cond_signal(pthread_cond_t * cond)

--- 80 unchanged lines hidden ---