1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_mutex_trylock (pthread_mutex_t * mutex)
- {
- int result = 0;
- pthread_mutex_t mx;
-
-
- if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER)
- {
- if ((result = pte_mutex_check_need_init (mutex)) != 0)
- {
- return (result);
- }
- }
- mx = *mutex;
- if (0 == PTE_ATOMIC_COMPARE_EXCHANGE (&mx->lock_idx,1,0))
- {
- if (mx->kind != PTHREAD_MUTEX_NORMAL)
- {
- mx->recursive_count = 1;
- mx->ownerThread = pthread_self ();
- }
- }
- else
- {
- if (mx->kind == PTHREAD_MUTEX_RECURSIVE &&
- pthread_equal (mx->ownerThread, pthread_self ()))
- {
- mx->recursive_count++;
- }
- else
- {
- result = EBUSY;
- }
- }
- return (result);
- }
|