Encapsulate the definition of Mutex into glog's internal namespace.
This will fix the issue a user in Japan reported in his blog. http://kzk9.net/blog/2009/05/deadlock_with_gflags_and_glog_2.html According to his description, when he use glog and gflags-1.1, gflags' code uses glog's Mutex, the Mutex cannot lock the pthread_mutex, and the program stops. The bug happens with the combination of gflags-1.1 and glog. It seems that the issue was caused by incompatibility of Mutex classes. Though I couldn't reproduce this issue, the reporter of this bug said that adding namespace fixes the problem and I think it is generally good idea to use namespace for this kind of common component to avoid incompatibilities. So, I check this change in now. This patch will protect glog from future changes on Mutex as well. --This line, and those below, will be ignored-- M src/base/mutex.h git-svn-id: https://google-glog.googlecode.com/svn/trunk@51 eb4d4688-79bd-11dd-afb4-1d65580434c0
This commit is contained in:
parent
7b97abb978
commit
c1995cd469
@ -99,6 +99,13 @@
|
||||
# error Need to implement mutex.h for your architecture, or #define NO_THREADS
|
||||
#endif
|
||||
|
||||
// We need to include these header files after defining _XOPEN_SOURCE
|
||||
// as they may define the _XOPEN_SOURCE macro.
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> // for abort()
|
||||
|
||||
namespace {
|
||||
|
||||
class Mutex {
|
||||
public:
|
||||
// Create a Mutex that is not held by anybody. This constructor is
|
||||
@ -149,7 +156,6 @@ class Mutex {
|
||||
// In debug mode, we assert these invariants, while in non-debug mode
|
||||
// we do nothing, for efficiency. That's why everything is in an
|
||||
// assert.
|
||||
#include <assert.h>
|
||||
|
||||
Mutex::Mutex() : mutex_(0) { }
|
||||
Mutex::~Mutex() { assert(mutex_ == 0); }
|
||||
@ -163,7 +169,6 @@ void Mutex::ReaderUnlock() { assert(mutex_-- > 0); }
|
||||
|
||||
#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
|
||||
|
||||
#include <stdlib.h> // for abort()
|
||||
#define SAFE_PTHREAD(fncall) do { if ((fncall) != 0) abort(); } while (0)
|
||||
|
||||
Mutex::Mutex() { SAFE_PTHREAD(pthread_rwlock_init(&mutex_, NULL)); }
|
||||
@ -179,7 +184,6 @@ void Mutex::ReaderUnlock() { SAFE_PTHREAD(pthread_rwlock_unlock(&mutex_)); }
|
||||
|
||||
#elif defined(HAVE_PTHREAD)
|
||||
|
||||
#include <stdlib.h> // for abort()
|
||||
#define SAFE_PTHREAD(fncall) do { if ((fncall) != 0) abort(); } while (0)
|
||||
|
||||
Mutex::Mutex() { SAFE_PTHREAD(pthread_mutex_init(&mutex_, NULL)); }
|
||||
@ -251,4 +255,6 @@ class WriterMutexLock {
|
||||
#define ReaderMutexLock(x) COMPILE_ASSERT(0, rmutex_lock_decl_missing_var_name)
|
||||
#define WriterMutexLock(x) COMPILE_ASSERT(0, wmutex_lock_decl_missing_var_name)
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif /* #define GOOGLE_MUTEX_H__ */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user