Commit 92b6c650 authored by Xavier Thompson's avatar Xavier Thompson

Protect contention-detection logging with a global static mutex

parent ddbf3004
...@@ -60,10 +60,12 @@ ...@@ -60,10 +60,12 @@
}; };
class LogLock : public RecursiveUpgradeableRWLock { class LogLock : public RecursiveUpgradeableRWLock {
static pthread_mutex_t log_guard;
public: public:
void wlock(); void wlock();
void rlock(); void rlock();
}; };
pthread_mutex_t LogLock::log_guard = PTHREAD_MUTEX_INITIALIZER;
struct CyPyObject { struct CyPyObject {
PyObject_HEAD PyObject_HEAD
...@@ -477,12 +479,14 @@ void LogLock::rlock() { ...@@ -477,12 +479,14 @@ void LogLock::rlock() {
if (this->write_count > 0) { if (this->write_count > 0) {
pid_t owner_id = this->owner_id; pid_t owner_id = this->owner_id;
pthread_mutex_lock(&(LogLock::log_guard));
printf( printf(
"Contention with a writer detected while rlocking lock [%p] in thread #%d:\n" "Contention with a writer detected while rlocking lock [%p] in thread #%d:\n"
" - lock was already wlocked by thread %d\n" " - lock was already wlocked by thread %d\n"
"\n" "\n"
,this, caller_id, owner_id ,this, caller_id, owner_id
); );
pthread_mutex_unlock(&(LogLock::log_guard));
} }
while (this->write_count > 0) { while (this->write_count > 0) {
...@@ -513,19 +517,23 @@ void LogLock::wlock() { ...@@ -513,19 +517,23 @@ void LogLock::wlock() {
if (this->readers_nb > 0) { if (this->readers_nb > 0) {
if (owner_id == CyObject_MANY_OWNERS) { if (owner_id == CyObject_MANY_OWNERS) {
pthread_mutex_lock(&(LogLock::log_guard));
printf( printf(
"Contention with several other reader threads detected while wlocking lock [%p] in thread #%d:\n" "Contention with several other reader threads detected while wlocking lock [%p] in thread #%d:\n"
"\n" "\n"
,this, caller_id ,this, caller_id
); );
} pthread_mutex_unlock(&(LogLock::log_guard));
}
else { else {
pthread_mutex_lock(&(LogLock::log_guard));
printf( printf(
"Contention with a reader thread detected while wlocking lock [%p] in thread #%d:\n" "Contention with a reader thread detected while wlocking lock [%p] in thread #%d:\n"
" - reader thread is %d\n" " - reader thread is %d\n"
"\n" "\n"
,this, caller_id, owner_id ,this, caller_id, owner_id
); );
pthread_mutex_unlock(&(LogLock::log_guard));
} }
} }
...@@ -534,12 +542,14 @@ void LogLock::wlock() { ...@@ -534,12 +542,14 @@ void LogLock::wlock() {
} }
if (this->write_count > 0) { if (this->write_count > 0) {
pthread_mutex_lock(&(LogLock::log_guard));
printf( printf(
"Contention with another writer detected while wlocking lock [%p] in thread #%d:\n" "Contention with another writer detected while wlocking lock [%p] in thread #%d:\n"
" - lock owner is thread %d\n" " - lock was already wlocked by thread %d\n"
"\n" "\n"
,this, caller_id, owner_id ,this, caller_id, owner_id
); );
pthread_mutex_unlock(&(LogLock::log_guard));
} }
while (this->write_count > 0) { while (this->write_count > 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment