|
Lines 420-425
Link Here
|
| 420 |
_thread_run->interrupted = 0; |
420 |
_thread_run->interrupted = 0; |
| 421 |
|
421 |
|
| 422 |
/* |
422 |
/* |
|
|
423 |
* According to: |
| 424 |
* http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_mutex_lock.html |
| 425 |
* If the mutex type is PTHREAD_MUTEX_ERRORCHECK, then error |
| 426 |
* checking is provided. If a thread attempts to relock a mutex |
| 427 |
* that it has already locked, an error will be returned. |
| 428 |
* |
| 429 |
* The pthread_mutex_lock() function may fail if: |
| 430 |
* [EDEADLK] |
| 431 |
* The current thread already owns the mutex. |
| 432 |
*/ |
| 433 |
if (((*mutex)->m_owner == _thread_run) && |
| 434 |
((*mutex)->m_type == PTHREAD_MUTEX_ERRORCHECK)) { |
| 435 |
return (EDEADLK); |
| 436 |
} |
| 437 |
|
| 438 |
/* |
| 423 |
* Enter a loop waiting to become the mutex owner. We need a |
439 |
* Enter a loop waiting to become the mutex owner. We need a |
| 424 |
* loop in case the waiting thread is interrupted by a signal |
440 |
* loop in case the waiting thread is interrupted by a signal |
| 425 |
* to execute a signal handler. It is not (currently) possible |
441 |
* to execute a signal handler. It is not (currently) possible |
|
Lines 739-744
Link Here
|
| 739 |
mutex_unlock_common(pthread_mutex_t * mutex, int add_reference) |
755 |
mutex_unlock_common(pthread_mutex_t * mutex, int add_reference) |
| 740 |
{ |
756 |
{ |
| 741 |
int ret = 0; |
757 |
int ret = 0; |
|
|
758 |
int proto; |
| 742 |
|
759 |
|
| 743 |
if (mutex == NULL || *mutex == NULL) { |
760 |
if (mutex == NULL || *mutex == NULL) { |
| 744 |
ret = EINVAL; |
761 |
ret = EINVAL; |
|
Lines 752-759
Link Here
|
| 752 |
/* Lock the mutex structure: */ |
769 |
/* Lock the mutex structure: */ |
| 753 |
_SPINLOCK(&(*mutex)->lock); |
770 |
_SPINLOCK(&(*mutex)->lock); |
| 754 |
|
771 |
|
|
|
772 |
proto = (*mutex)->m_protocol; |
| 773 |
|
| 774 |
/* |
| 775 |
* According to: |
| 776 |
* http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_mutex_lock.html |
| 777 |
* |
| 778 |
* If the mutex type is PTHREAD_MUTEX_ERRORCHECK, then |
| 779 |
* error checking is provided. If a thread attempts to |
| 780 |
* unlock a mutex that it has not locked or a mutex which |
| 781 |
* is unlocked, an error will be returned. |
| 782 |
* |
| 783 |
* The pthread_mutex_unlock() function may fail if: |
| 784 |
* [EPERM] |
| 785 |
* The current thread does not own the mutex. |
| 786 |
*/ |
| 787 |
if (((*mutex)->m_owner != _thread_run) && |
| 788 |
((*mutex)->m_type == PTHREAD_MUTEX_ERRORCHECK)) { |
| 789 |
proto = -1; |
| 790 |
ret = EPERM; |
| 791 |
} |
| 792 |
|
| 755 |
/* Process according to mutex type: */ |
793 |
/* Process according to mutex type: */ |
| 756 |
switch ((*mutex)->m_protocol) { |
794 |
switch (proto) { |
|
|
795 |
case -1: |
| 796 |
/* we've already caught an error, do nothing */ |
| 797 |
break; |
| 798 |
|
| 757 |
/* Default POSIX mutex: */ |
799 |
/* Default POSIX mutex: */ |
| 758 |
case PTHREAD_PRIO_NONE: |
800 |
case PTHREAD_PRIO_NONE: |
| 759 |
/* |
801 |
/* |