Lines Matching refs:tok

178     xmlMutexPtr tok;
180 if ((tok = malloc(sizeof(xmlMutex))) == NULL)
184 pthread_mutex_init(&tok->lock, NULL);
186 tok->mutex = CreateMutex(NULL, FALSE, NULL);
188 if ((tok->sem = create_sem(1, "xmlMutex")) < B_OK) {
189 free(tok);
192 tok->tid = -1;
194 return (tok);
199 * @tok: the simple mutex
205 xmlFreeMutex(xmlMutexPtr tok)
207 if (tok == NULL) return;
211 pthread_mutex_destroy(&tok->lock);
213 CloseHandle(tok->mutex);
215 delete_sem(tok->sem);
217 free(tok);
222 * @tok: the simple mutex
227 xmlMutexLock(xmlMutexPtr tok)
229 if (tok == NULL)
233 pthread_mutex_lock(&tok->lock);
235 WaitForSingleObject(tok->mutex, INFINITE);
237 if (acquire_sem(tok->sem) != B_NO_ERROR) {
243 tok->tid = find_thread(NULL);
250 * @tok: the simple mutex
255 xmlMutexUnlock(xmlMutexPtr tok)
257 if (tok == NULL)
261 pthread_mutex_unlock(&tok->lock);
263 ReleaseMutex(tok->mutex);
265 if (tok->tid == find_thread(NULL)) {
266 tok->tid = -1;
267 release_sem(tok->sem);
285 xmlRMutexPtr tok;
287 if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
291 pthread_mutex_init(&tok->lock, NULL);
292 tok->held = 0;
293 tok->waiters = 0;
294 pthread_cond_init(&tok->cv, NULL);
297 InitializeCriticalSection(&tok->cs);
298 tok->count = 0;
300 if ((tok->lock = xmlNewMutex()) == NULL) {
301 free(tok);
304 tok->count = 0;
306 return (tok);
311 * @tok: the reentrant mutex
317 xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
319 if (tok == NULL)
323 pthread_mutex_destroy(&tok->lock);
325 DeleteCriticalSection(&tok->cs);
327 xmlFreeMutex(tok->lock);
329 free(tok);
334 * @tok: the reentrant mutex
339 xmlRMutexLock(xmlRMutexPtr tok)
341 if (tok == NULL)
347 pthread_mutex_lock(&tok->lock);
348 if (tok->held) {
349 if (pthread_equal(tok->tid, pthread_self())) {
350 tok->held++;
351 pthread_mutex_unlock(&tok->lock);
354 tok->waiters++;
355 while (tok->held)
356 pthread_cond_wait(&tok->cv, &tok->lock);
357 tok->waiters--;
360 tok->tid = pthread_self();
361 tok->held = 1;
362 pthread_mutex_unlock(&tok->lock);
364 EnterCriticalSection(&tok->cs);
365 ++tok->count;
367 if (tok->lock->tid == find_thread(NULL)) {
368 tok->count++;
371 xmlMutexLock(tok->lock);
372 tok->count = 1;
379 * @tok: the reentrant mutex
384 xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
386 if (tok == NULL)
392 pthread_mutex_lock(&tok->lock);
393 tok->held--;
394 if (tok->held == 0) {
395 if (tok->waiters)
396 pthread_cond_signal(&tok->cv);
397 tok->tid = 0;
399 pthread_mutex_unlock(&tok->lock);
401 if (!--tok->count)
402 LeaveCriticalSection(&tok->cs);
404 if (tok->lock->tid == find_thread(NULL)) {
405 tok->count--;
406 if (tok->count == 0) {
407 xmlMutexUnlock(tok->lock);