Commit 7622061d authored by Xavier Thompson's avatar Xavier Thompson

Add the context of the other thread in cypclass data race logging

parent f9861598
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
atomic<pid_t> owner_id; atomic<pid_t> owner_id;
atomic_int32_t readers_nb; atomic_int32_t readers_nb;
uint32_t write_count; uint32_t write_count;
const char *owner_context;
public: public:
CyLock() { CyLock() {
pthread_mutex_init(&this->guard, NULL); pthread_mutex_init(&this->guard, NULL);
...@@ -336,7 +337,10 @@ void CyLock::rlock(const char *context) { ...@@ -336,7 +337,10 @@ void CyLock::rlock(const char *context) {
<< " and [other] writer #" << owner_id << " and [other] writer #" << owner_id
<< " on lock " << this; << " on lock " << this;
if (context != NULL) { if (context != NULL) {
msg << std::endl << "In: " << context; 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()); throw std::runtime_error(msg.str());
#else #else
...@@ -347,7 +351,10 @@ void CyLock::rlock(const char *context) { ...@@ -347,7 +351,10 @@ void CyLock::rlock(const char *context) {
<< " and [other] writer #" << owner_id << " and [other] writer #" << owner_id
<< " on lock " << this << std::endl; << " on lock " << this << std::endl;
if (context != NULL) { if (context != NULL) {
std::cout << "In: " << context << std::endl; std::cout << "In [this] context: " << context << std::endl;
}
if (this->owner_context != NULL) {
std::cout << "In [other] context: " << this->owner_context << std::endl;
} }
pthread_mutex_unlock(&(CyLock::log_guard)); pthread_mutex_unlock(&(CyLock::log_guard));
#endif #endif
...@@ -359,6 +366,8 @@ void CyLock::rlock(const char *context) { ...@@ -359,6 +366,8 @@ void CyLock::rlock(const char *context) {
this->owner_id = this->readers_nb++ ? CyObject_MANY_OWNERS : caller_id; this->owner_id = this->readers_nb++ ? CyObject_MANY_OWNERS : caller_id;
this->owner_context = context;
pthread_mutex_unlock(&this->guard); pthread_mutex_unlock(&this->guard);
} }
...@@ -428,7 +437,10 @@ void CyLock::wlock(const char *context) { ...@@ -428,7 +437,10 @@ void CyLock::wlock(const char *context) {
<< " and [other] reader #" << owner_id << " and [other] reader #" << owner_id
<< " on lock " << this; << " on lock " << this;
if (context != NULL) { if (context != NULL) {
msg << std::endl << "In: " << context; 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()); throw std::runtime_error(msg.str());
#else #else
...@@ -437,7 +449,10 @@ void CyLock::wlock(const char *context) { ...@@ -437,7 +449,10 @@ void CyLock::wlock(const char *context) {
<< " and [other] reader #" << owner_id << " and [other] reader #" << owner_id
<< " on lock " << this << std::endl; << " on lock " << this << std::endl;
if (context != NULL) { if (context != NULL) {
std::cout << "In: " << context << std::endl; std::cout << "In [this] context: " << context << std::endl;
}
if (this->owner_context != NULL) {
std::cout << "In [other] context: " << this->owner_context << std::endl;
} }
#endif #endif
} }
...@@ -454,7 +469,10 @@ void CyLock::wlock(const char *context) { ...@@ -454,7 +469,10 @@ void CyLock::wlock(const char *context) {
<< " and [other] writer #" << owner_id << " and [other] writer #" << owner_id
<< " on lock " << this; << " on lock " << this;
if (context != NULL) { if (context != NULL) {
msg << std::endl << "In: " << context; 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()); throw std::runtime_error(msg.str());
#else #else
...@@ -464,7 +482,10 @@ void CyLock::wlock(const char *context) { ...@@ -464,7 +482,10 @@ void CyLock::wlock(const char *context) {
<< " and [other] writer #" << owner_id << " and [other] writer #" << owner_id
<< " on lock " << this << std::endl; << " on lock " << this << std::endl;
if (context != NULL) { if (context != NULL) {
std::cout << "In: " << context << std::endl; std::cout << "In [this] context: " << context << std::endl;
}
if (this->owner_context != NULL) {
std::cout << "In [other] context: " << this->owner_context << std::endl;
} }
pthread_mutex_unlock(&(CyLock::log_guard)); pthread_mutex_unlock(&(CyLock::log_guard));
#endif #endif
...@@ -479,6 +500,8 @@ void CyLock::wlock(const char *context) { ...@@ -479,6 +500,8 @@ void CyLock::wlock(const char *context) {
this->write_count = 1; this->write_count = 1;
this->owner_context = context;
pthread_mutex_unlock(&this->guard); pthread_mutex_unlock(&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