* xmlRMutexLock: * @tok: the reentrant mutex * * xmlRMutexLock() is used to lock a libxml2 token_r. */
| 295 | * xmlRMutexLock() is used to lock a libxml2 token_r. |
| 296 | */ |
| 297 | void |
| 298 | xmlRMutexLock(xmlRMutexPtr tok) |
| 299 | { |
| 300 | if (tok == NULL) |
| 301 | return; |
| 302 | #ifdef HAVE_POSIX_THREADS |
| 303 | if (XML_IS_THREADED() == 0) |
| 304 | return; |
| 305 | |
| 306 | pthread_mutex_lock(&tok->lock); |
| 307 | if (tok->held) { |
| 308 | if (pthread_equal(tok->tid, pthread_self())) { |
| 309 | tok->held++; |
| 310 | pthread_mutex_unlock(&tok->lock); |
| 311 | return; |
| 312 | } else { |
| 313 | tok->waiters++; |
| 314 | while (tok->held) |
| 315 | pthread_cond_wait(&tok->cv, &tok->lock); |
| 316 | tok->waiters--; |
| 317 | } |
| 318 | } |
| 319 | tok->tid = pthread_self(); |
| 320 | tok->held = 1; |
| 321 | pthread_mutex_unlock(&tok->lock); |
| 322 | #elif defined HAVE_WIN32_THREADS |
| 323 | EnterCriticalSection(&tok->cs); |
| 324 | #endif |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * xmlRMutexUnlock: |
no outgoing calls
no test coverage detected