123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #include <pte_osal.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "pthread.h"
- #include "implement.h"
- #define TEST_IE InterlockedExchange
- int
- pthread_mutex_unlock (pthread_mutex_t * mutex)
- {
- int result = 0;
- pthread_mutex_t mx;
-
- if (*mutex == NULL)
- {
- return EINVAL;
- }
- mx = *mutex;
-
- if (mx < PTHREAD_ERRORCHECK_MUTEX_INITIALIZER)
- {
- if (mx->kind == PTHREAD_MUTEX_NORMAL)
- {
- int idx;
- idx = PTE_ATOMIC_EXCHANGE (&mx->lock_idx,0);
- if (idx != 0)
- {
- if (idx < 0)
- {
-
- if (pte_osSemaphorePost(mx->handle,1) != PTE_OS_OK)
- {
- result = EINVAL;
- }
- }
- }
- else
- {
-
- result = EPERM;
- }
- }
- else
- {
- if (pthread_equal (mx->ownerThread, pthread_self ()))
- {
- if (mx->kind != PTHREAD_MUTEX_RECURSIVE
- || 0 == --mx->recursive_count)
- {
- mx->ownerThread = NULL;
- if (PTE_ATOMIC_EXCHANGE (&mx->lock_idx,0) < 0)
- {
- if (pte_osSemaphorePost(mx->handle,1) != PTE_OS_OK)
- {
- result = EINVAL;
- }
- }
- }
- }
- else
- {
- result = EPERM;
- }
- }
- }
- else
- {
- result = EINVAL;
- }
- return (result);
- }
|