Commit 8f09af4d authored by Julien Jerphanion's avatar Julien Jerphanion Committed by Xavier Thompson

Remove logging on contention

This also remove the associated mutex from the CyLock class.
parent 32727915
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
#define CyObject_CONTENDING_WRITER_FLAG (1 << 0) #define CyObject_CONTENDING_WRITER_FLAG (1 << 0)
#define CyObject_CONTENDING_READER_FLAG (1 << 1) #define CyObject_CONTENDING_READER_FLAG (1 << 1)
#define CyObject_RAISE_ON_CONTENTION 0
#include <atomic> #include <atomic>
#include <pthread.h> #include <pthread.h>
...@@ -37,7 +35,6 @@ ...@@ -37,7 +35,6 @@
#include <type_traits> #include <type_traits>
class CyLock { class CyLock {
static pthread_mutex_t log_guard;
protected: protected:
pthread_mutex_t guard; pthread_mutex_t guard;
pthread_cond_t readers_have_left; pthread_cond_t readers_have_left;
...@@ -67,9 +64,6 @@ ...@@ -67,9 +64,6 @@
int tryrlock(); int tryrlock();
int trywlock(); int trywlock();
}; };
#if CyObject_RAISE_ON_CONTENTION == 0
pthread_mutex_t CyLock::log_guard = PTHREAD_MUTEX_INITIALIZER;
#endif
struct CyPyObject { struct CyPyObject {
PyObject_HEAD PyObject_HEAD
...@@ -724,37 +718,6 @@ void CyLock::rlock(const char *context) { ...@@ -724,37 +718,6 @@ void CyLock::rlock(const char *context) {
pthread_mutex_lock(&this->guard); pthread_mutex_lock(&this->guard);
if (this->write_count > 0) {
#if CyObject_RAISE_ON_CONTENTION
pid_t owner_id = this->owner_id;
std::ostringstream msg;
msg << "Data Race between [this] reader #" << caller_id
<< " and [other] writer #" << owner_id
<< " on lock " << this;
if (context != NULL) {
msg << std::endl << "In [this] context: " << context;
}
if (this->owner_context != NULL) {
msg << std::endl << "In [other] context: " << this->owner_context;
}
throw std::runtime_error(msg.str());
#else
pid_t owner_id = this->owner_id;
pthread_mutex_lock(&(CyLock::log_guard));
std::cerr
<< "Data Race between [this] reader #" << caller_id
<< " and [other] writer #" << owner_id
<< " on lock " << this << std::endl;
if (context != NULL) {
std::cerr << "In [this] context: " << context << std::endl;
}
if (this->owner_context != NULL) {
std::cerr << "In [other] context: " << this->owner_context << std::endl;
}
pthread_mutex_unlock(&(CyLock::log_guard));
#endif
}
while (this->write_count > 0) { while (this->write_count > 0) {
pthread_cond_wait(&this->writer_has_left, &this->guard); pthread_cond_wait(&this->writer_has_left, &this->guard);
} }
...@@ -824,70 +787,10 @@ void CyLock::wlock(const char *context) { ...@@ -824,70 +787,10 @@ void CyLock::wlock(const char *context) {
// Since we use a reader-preferring approach, we wait first for all readers to leave, and then all writers. // Since we use a reader-preferring approach, we wait first for all readers to leave, and then all writers.
// The other way around could result in several writers acquiring the lock. // The other way around could result in several writers acquiring the lock.
if (this->readers_nb > 0) {
#if CyObject_RAISE_ON_CONTENTION
pid_t owner_id = this->owner_id;
std::ostringstream msg;
msg << "Data Race between [this] writer #" << caller_id
<< " and [other] reader #" << owner_id
<< " on lock " << this;
if (context != NULL) {
msg << std::endl << "In [this] context: " << context;
}
if (this->owner_context != NULL) {
msg << std::endl << "In [other] context: " << this->owner_context;
}
throw std::runtime_error(msg.str());
#else
pthread_mutex_lock(&(CyLock::log_guard));
std::cerr
<< "Data Race between [this] writer #" << caller_id
<< " and [other] reader #" << owner_id
<< " on lock " << this << std::endl;
if (context != NULL) {
std::cerr << "In [this] context: " << context << std::endl;
}
if (this->owner_context != NULL) {
std::cerr << "In [other] context: " << this->owner_context << std::endl;
}
pthread_mutex_unlock(&(CyLock::log_guard));
#endif
}
while (this->readers_nb > 0) { while (this->readers_nb > 0) {
pthread_cond_wait(&this->readers_have_left, &this->guard); pthread_cond_wait(&this->readers_have_left, &this->guard);
} }
if (this->write_count > 0) {
#if CyObject_RAISE_ON_CONTENTION
pid_t owner_id = this->owner_id;
std::ostringstream msg;
msg << "Data Race between [this] writer #" << caller_id
<< " and [other] writer #" << owner_id
<< " on lock " << this;
if (context != NULL) {
msg << std::endl << "In [this] context: " << context;
}
if (this->owner_context != NULL) {
msg << std::endl << "In [other] context: " << this->owner_context;
}
throw std::runtime_error(msg.str());
#else
pthread_mutex_lock(&(CyLock::log_guard));
std::cerr
<< "Data Race between [this] writer #" << caller_id
<< " and [other] writer #" << owner_id
<< " on lock " << this << std::endl;
if (context != NULL) {
std::cerr << "In [this] context: " << context << std::endl;
}
if (this->owner_context != NULL) {
std::cerr << "In [other] context: " << this->owner_context << std::endl;
}
pthread_mutex_unlock(&(CyLock::log_guard));
#endif
}
while (this->write_count > 0) { while (this->write_count > 0) {
pthread_cond_wait(&this->writer_has_left, &this->guard); pthread_cond_wait(&this->writer_has_left, &this->guard);
} }
......
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