#include "llvm/Config/config.h"
#include "llvm/System/RWMutex.h"
+#include <cstring>
//===----------------------------------------------------------------------===//
//=== WARNING: Implementation here must contain only TRULY operating system
// Define all methods as no-ops if threading is explicitly disabled
namespace llvm {
using namespace sys;
-RWMutex::RWMutex( bool recursive) { }
-RWMutex::~RWMutex() { }
-bool RWMutex::reader_acquire() { return true; }
-bool RWMutex::reader_release() { return true; }
-bool RWMutex::writer_acquire() { return true; }
-bool RWMutex::writer_release() { return true; }
+RWMutexImpl::RWMutexImpl() { }
+RWMutexImpl::~RWMutexImpl() { }
+bool RWMutexImpl::reader_acquire() { return true; }
+bool RWMutexImpl::reader_release() { return true; }
+bool RWMutexImpl::writer_acquire() { return true; }
+bool RWMutexImpl::writer_release() { return true; }
}
#else
static const bool pthread_enabled = true;
// Construct a RWMutex using pthread calls
-RWMutex::RWMutex()
+RWMutexImpl::RWMutexImpl()
: data_(0)
{
if (pthread_enabled)
// Declare the pthread_rwlock data structures
pthread_rwlock_t* rwlock =
static_cast<pthread_rwlock_t*>(malloc(sizeof(pthread_rwlock_t)));
- pthread_rwlockattr_t attr;
- // Initialize the rwlock attributes
- int errorcode = pthread_rwlockattr_init(&attr);
- assert(errorcode == 0);
-
-#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
- // Make it a process local rwlock
- errorcode = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);
+#ifdef __APPLE__
+ // Workaround a bug/mis-feature in Darwin's pthread_rwlock_init.
+ bzero(rwlock, sizeof(pthread_rwlock_t));
#endif
// Initialize the rwlock
- errorcode = pthread_rwlock_init(rwlock, &attr);
- assert(errorcode == 0);
-
- // Destroy the attributes
- errorcode = pthread_rwlockattr_destroy(&attr);
+ int errorcode = pthread_rwlock_init(rwlock, NULL);
+ (void)errorcode;
assert(errorcode == 0);
// Assign the data member
}
// Destruct a RWMutex
-RWMutex::~RWMutex()
+RWMutexImpl::~RWMutexImpl()
{
if (pthread_enabled)
{
}
bool
-RWMutex::reader_acquire()
+RWMutexImpl::reader_acquire()
{
if (pthread_enabled)
{
int errorcode = pthread_rwlock_rdlock(rwlock);
return errorcode == 0;
- }
- return false;
+ } else return false;
}
bool
-RWMutex::reader_release()
+RWMutexImpl::reader_release()
{
if (pthread_enabled)
{
int errorcode = pthread_rwlock_unlock(rwlock);
return errorcode == 0;
- }
- return false;
+ } else return false;
}
bool
-RWMutex::writer_acquire()
+RWMutexImpl::writer_acquire()
{
if (pthread_enabled)
{
int errorcode = pthread_rwlock_wrlock(rwlock);
return errorcode == 0;
- }
- return false;
+ } else return false;
}
bool
-RWMutex::writer_release()
+RWMutexImpl::writer_release()
{
if (pthread_enabled)
{
int errorcode = pthread_rwlock_unlock(rwlock);
return errorcode == 0;
- }
- return false;
+ } else return false;
}
}
#warning Neither LLVM_ON_UNIX nor LLVM_ON_WIN32 was set in System/Mutex.cpp
#endif
#endif
-