Lines Matching refs:tok
179 xmlMutexPtr tok; in xmlNewMutex() local
181 if ((tok = malloc(sizeof(xmlMutex))) == NULL) in xmlNewMutex()
185 pthread_mutex_init(&tok->lock, NULL); in xmlNewMutex()
187 tok->mutex = CreateMutex(NULL, FALSE, NULL); in xmlNewMutex()
189 if ((tok->sem = create_sem(1, "xmlMutex")) < B_OK) { in xmlNewMutex()
190 free(tok); in xmlNewMutex()
193 tok->tid = -1; in xmlNewMutex()
195 return (tok); in xmlNewMutex()
206 xmlFreeMutex(xmlMutexPtr tok) in xmlFreeMutex() argument
208 if (tok == NULL) in xmlFreeMutex()
213 pthread_mutex_destroy(&tok->lock); in xmlFreeMutex()
215 CloseHandle(tok->mutex); in xmlFreeMutex()
217 delete_sem(tok->sem); in xmlFreeMutex()
219 free(tok); in xmlFreeMutex()
229 xmlMutexLock(xmlMutexPtr tok) in xmlMutexLock() argument
231 if (tok == NULL) in xmlMutexLock()
235 pthread_mutex_lock(&tok->lock); in xmlMutexLock()
237 WaitForSingleObject(tok->mutex, INFINITE); in xmlMutexLock()
239 if (acquire_sem(tok->sem) != B_NO_ERROR) { in xmlMutexLock()
245 tok->tid = find_thread(NULL); in xmlMutexLock()
257 xmlMutexUnlock(xmlMutexPtr tok) in xmlMutexUnlock() argument
259 if (tok == NULL) in xmlMutexUnlock()
263 pthread_mutex_unlock(&tok->lock); in xmlMutexUnlock()
265 ReleaseMutex(tok->mutex); in xmlMutexUnlock()
267 if (tok->tid == find_thread(NULL)) { in xmlMutexUnlock()
268 tok->tid = -1; in xmlMutexUnlock()
269 release_sem(tok->sem); in xmlMutexUnlock()
287 xmlRMutexPtr tok; in xmlNewRMutex() local
289 if ((tok = malloc(sizeof(xmlRMutex))) == NULL) in xmlNewRMutex()
293 pthread_mutex_init(&tok->lock, NULL); in xmlNewRMutex()
294 tok->held = 0; in xmlNewRMutex()
295 tok->waiters = 0; in xmlNewRMutex()
296 pthread_cond_init(&tok->cv, NULL); in xmlNewRMutex()
299 InitializeCriticalSection(&tok->cs); in xmlNewRMutex()
300 tok->count = 0; in xmlNewRMutex()
302 if ((tok->lock = xmlNewMutex()) == NULL) { in xmlNewRMutex()
303 free(tok); in xmlNewRMutex()
306 tok->count = 0; in xmlNewRMutex()
308 return (tok); in xmlNewRMutex()
319 xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED) in xmlFreeRMutex()
321 if (tok == NULL) in xmlFreeRMutex()
325 pthread_mutex_destroy(&tok->lock); in xmlFreeRMutex()
326 pthread_cond_destroy(&tok->cv); in xmlFreeRMutex()
329 DeleteCriticalSection(&tok->cs); in xmlFreeRMutex()
331 xmlFreeMutex(tok->lock); in xmlFreeRMutex()
333 free(tok); in xmlFreeRMutex()
343 xmlRMutexLock(xmlRMutexPtr tok) in xmlRMutexLock() argument
345 if (tok == NULL) in xmlRMutexLock()
351 pthread_mutex_lock(&tok->lock); in xmlRMutexLock()
352 if (tok->held) { in xmlRMutexLock()
353 if (pthread_equal(tok->tid, pthread_self())) { in xmlRMutexLock()
354 tok->held++; in xmlRMutexLock()
355 pthread_mutex_unlock(&tok->lock); in xmlRMutexLock()
358 tok->waiters++; in xmlRMutexLock()
359 while (tok->held) in xmlRMutexLock()
360 pthread_cond_wait(&tok->cv, &tok->lock); in xmlRMutexLock()
361 tok->waiters--; in xmlRMutexLock()
364 tok->tid = pthread_self(); in xmlRMutexLock()
365 tok->held = 1; in xmlRMutexLock()
366 pthread_mutex_unlock(&tok->lock); in xmlRMutexLock()
368 EnterCriticalSection(&tok->cs); in xmlRMutexLock()
369 tok->count++; in xmlRMutexLock()
371 if (tok->lock->tid == find_thread(NULL)) { in xmlRMutexLock()
372 tok->count++; in xmlRMutexLock()
375 xmlMutexLock(tok->lock); in xmlRMutexLock()
376 tok->count = 1; in xmlRMutexLock()
388 xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED) in xmlRMutexUnlock()
390 if (tok == NULL) in xmlRMutexUnlock()
396 pthread_mutex_lock(&tok->lock); in xmlRMutexUnlock()
397 tok->held--; in xmlRMutexUnlock()
398 if (tok->held == 0) { in xmlRMutexUnlock()
399 if (tok->waiters) in xmlRMutexUnlock()
400 pthread_cond_signal(&tok->cv); in xmlRMutexUnlock()
401 memset(&tok->tid, 0, sizeof(tok->tid)); in xmlRMutexUnlock()
403 pthread_mutex_unlock(&tok->lock); in xmlRMutexUnlock()
405 if (tok->count > 0) { in xmlRMutexUnlock()
406 tok->count--; in xmlRMutexUnlock()
407 LeaveCriticalSection(&tok->cs); in xmlRMutexUnlock()
410 if (tok->lock->tid == find_thread(NULL)) { in xmlRMutexUnlock()
411 tok->count--; in xmlRMutexUnlock()
412 if (tok->count == 0) { in xmlRMutexUnlock()
413 xmlMutexUnlock(tok->lock); in xmlRMutexUnlock()