mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-21 12:28:26 -04:00
Added return value checking of mutex_lock() function.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6656 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
51f0726dd3
commit
60087f0ef9
1 changed files with 61 additions and 1 deletions
|
@ -30,14 +30,20 @@
|
||||||
#include <errno.h> /* for usleep() */
|
#include <errno.h> /* for usleep() */
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
#ifdef RSMUTEX_DEBUG
|
#ifdef RSMUTEX_DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*******
|
/*******
|
||||||
* #define DEBUG_THREADS 1
|
* #define DEBUG_THREADS 1
|
||||||
|
* #define RSMUTEX_ABORT 1 // Catch wrong pthreads mode.
|
||||||
*******/
|
*******/
|
||||||
|
|
||||||
|
#ifdef RSMUTEX_ABORT
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#endif
|
#endif
|
||||||
|
@ -180,11 +186,65 @@ void RsMutex::lock()
|
||||||
clock_t t1 = clock();
|
clock_t t1 = clock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int retval = 0;
|
||||||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||||
if(!trylock())
|
if(!trylock())
|
||||||
if(!pthread_equal(_thread_id,pthread_self()))
|
if(!pthread_equal(_thread_id,pthread_self()))
|
||||||
#endif
|
#endif
|
||||||
pthread_mutex_lock(&realMutex);
|
retval = pthread_mutex_lock(&realMutex);
|
||||||
|
|
||||||
|
switch(retval)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EINVAL:
|
||||||
|
std::cerr << "RsMutex::lock() pthread_mutex_lock returned EINVAL";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EBUSY:
|
||||||
|
std::cerr << "RsMutex::lock() pthread_mutex_lock returned EBUSY";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EAGAIN:
|
||||||
|
std::cerr << "RsMutex::lock() pthread_mutex_lock returned EAGAIN";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EDEADLK:
|
||||||
|
std::cerr << "RsMutex::lock() pthread_mutex_lock returned EDEADLK";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EPERM:
|
||||||
|
std::cerr << "RsMutex::lock() pthread_mutex_lock returned EPERM";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
std::cerr << "RsMutex::lock() pthread_mutex_lock returned UNKNOWN ERROR";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Here is some debugging code - to catch failed locking attempts.
|
||||||
|
* Major bug is it is ever triggered.
|
||||||
|
*/
|
||||||
|
#ifdef RSMUTEX_ABORT
|
||||||
|
|
||||||
|
if (retval != 0)
|
||||||
|
{
|
||||||
|
#ifdef RSMUTEX_DEBUG
|
||||||
|
std::cerr << "RsMutex::lock() name: " << name << std::endl;
|
||||||
|
#endif
|
||||||
|
std::cerr << "RsMutex::lock() pthread_mutex_lock returned an Error. Aborting()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
_thread_id = pthread_self() ;
|
_thread_id = pthread_self() ;
|
||||||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue