Lines Matching refs:tok

182     xmlMutexPtr tok;
184 if ((tok = malloc(sizeof(xmlMutex))) == NULL)
188 pthread_mutex_init(&tok->lock, NULL);
190 tok->mutex = CreateMutex(NULL, FALSE, NULL);
192 if ((tok->sem = create_sem(1, "xmlMutex")) < B_OK) {
193 free(tok);
196 tok->tid = -1;
198 return (tok);
203 * @tok: the simple mutex
209 xmlFreeMutex(xmlMutexPtr tok)
211 if (tok == NULL) return;
215 pthread_mutex_destroy(&tok->lock);
217 CloseHandle(tok->mutex);
219 delete_sem(tok->sem);
221 free(tok);
226 * @tok: the simple mutex
231 xmlMutexLock(xmlMutexPtr tok)
233 if (tok == NULL)
237 pthread_mutex_lock(&tok->lock);
239 WaitForSingleObject(tok->mutex, INFINITE);
241 if (acquire_sem(tok->sem) != B_NO_ERROR) {
247 tok->tid = find_thread(NULL);
254 * @tok: the simple mutex
259 xmlMutexUnlock(xmlMutexPtr tok)
261 if (tok == NULL)
265 pthread_mutex_unlock(&tok->lock);
267 ReleaseMutex(tok->mutex);
269 if (tok->tid == find_thread(NULL)) {
270 tok->tid = -1;
271 release_sem(tok->sem);
289 xmlRMutexPtr tok;
291 if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
295 pthread_mutex_init(&tok->lock, NULL);
296 tok->held = 0;
297 tok->waiters = 0;
298 pthread_cond_init(&tok->cv, NULL);
301 InitializeCriticalSection(&tok->cs);
302 tok->count = 0;
304 if ((tok->lock = xmlNewMutex()) == NULL) {
305 free(tok);
308 tok->count = 0;
310 return (tok);
315 * @tok: the reentrant mutex
321 xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
323 if (tok == NULL)
327 pthread_mutex_destroy(&tok->lock);
328 pthread_cond_destroy(&tok->cv);
331 DeleteCriticalSection(&tok->cs);
333 xmlFreeMutex(tok->lock);
335 free(tok);
340 * @tok: the reentrant mutex
345 xmlRMutexLock(xmlRMutexPtr tok)
347 if (tok == NULL)
353 pthread_mutex_lock(&tok->lock);
354 if (tok->held) {
355 if (pthread_equal(tok->tid, pthread_self())) {
356 tok->held++;
357 pthread_mutex_unlock(&tok->lock);
360 tok->waiters++;
361 while (tok->held)
362 pthread_cond_wait(&tok->cv, &tok->lock);
363 tok->waiters--;
366 tok->tid = pthread_self();
367 tok->held = 1;
368 pthread_mutex_unlock(&tok->lock);
370 EnterCriticalSection(&tok->cs);
371 ++tok->count;
373 if (tok->lock->tid == find_thread(NULL)) {
374 tok->count++;
377 xmlMutexLock(tok->lock);
378 tok->count = 1;
385 * @tok: the reentrant mutex
390 xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
392 if (tok == NULL)
398 pthread_mutex_lock(&tok->lock);
399 tok->held--;
400 if (tok->held == 0) {
401 if (tok->waiters)
402 pthread_cond_signal(&tok->cv);
403 tok->tid = 0;
405 pthread_mutex_unlock(&tok->lock);
407 if (!--tok->count)
408 LeaveCriticalSection(&tok->cs);
410 if (tok->lock->tid == find_thread(NULL)) {
411 tok->count--;
412 if (tok->count == 0) {
413 xmlMutexUnlock(tok->lock);