<div>constructore is mismatch between declare and implementation:</div>
<div>+RWMutex::RWMutex( bool recursive) { }</div>
<div> ^^^^^^^^^^^^^^</div>
<div> </div>
<div>Also you forgot to update CMakefile.txt.</div>
<div><br><br> </div>
<div class="gmail_quote">On Wed, Jun 17, 2009 at 4:19 AM, Owen Anderson <span dir="ltr"><<a href="mailto:resistor@mac.com">resistor@mac.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Author: resistor<br>Date: Tue Jun 16 15:19:28 2009<br>New Revision: 73545<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=73545&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=73545&view=rev</a><br>
Log:<br>Add a portable wrapper for reader-writer locks.<br><br>Added:<br> llvm/trunk/include/llvm/System/RWMutex.h<br> llvm/trunk/lib/System/RWMutex.cpp<br> llvm/trunk/lib/System/Unix/RWMutex.inc<br> llvm/trunk/lib/System/Win32/RWMutex.inc<br>
Modified:<br> llvm/trunk/lib/System/Win32/Mutex.inc<br><br>Added: llvm/trunk/include/llvm/System/RWMutex.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/RWMutex.h?rev=73545&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/RWMutex.h?rev=73545&view=auto</a><br>
<br>==============================================================================<br>--- llvm/trunk/include/llvm/System/RWMutex.h (added)<br>+++ llvm/trunk/include/llvm/System/RWMutex.h Tue Jun 16 15:19:28 2009<br>@@ -0,0 +1,84 @@<br>
+//===- RWMutex.h - Reader/Writer Mutual Exclusion Lock ----------*- C++ -*-===//<br>+//<br>+// The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+//<br>+// This file declares the llvm::sys::RWMutex class.<br>+//<br>+//===----------------------------------------------------------------------===//<br>
+<br>+#ifndef LLVM_SYSTEM_MUTEX_H<br>+#define LLVM_SYSTEM_MUTEX_H<br>+<br>+namespace llvm<br>+{<br>+ namespace sys<br>+ {<br>+ /// @brief Platform agnostic Mutex class.<br>+ class RWMutex<br>+ {<br>+ /// @name Constructors<br>
+ /// @{<br>+ public:<br>+<br>+ /// Initializes the lock but doesn't acquire it.<br>+ /// @brief Default Constructor.<br>+ explicit RWMutex();<br>+<br>+ /// Releases and removes the lock<br>+ /// @brief Destructor<br>
+ ~RWMutex();<br>+<br>+ /// @}<br>+ /// @name Methods<br>+ /// @{<br>+ public:<br>+<br>+ /// Attempts to unconditionally acquire the lock in reader mode. If the<br>+ /// lock is held by a writer, this method will wait until it can acquire<br>
+ /// the lock.<br>+ /// @returns false if any kind of error occurs, true otherwise.<br>+ /// @brief Unconditionally acquire the lock in reader mode.<br>+ bool reader_acquire();<br>+<br>+ /// Attempts to release the lock in reader mode.<br>
+ /// @returns false if any kind of error occurs, true otherwise.<br>+ /// @brief Unconditionally release the lock in reader mode.<br>+ bool reader_release();<br>+<br>+ /// Attempts to unconditionally acquire the lock in reader mode. If the<br>
+ /// lock is held by any readers, this method will wait until it can<br>+ /// acquire the lock.<br>+ /// @returns false if any kind of error occurs, true otherwise.<br>+ /// @brief Unconditionally acquire the lock in writer mode.<br>
+ bool writer_acquire();<br>+<br>+ /// Attempts to release the lock in writer mode.<br>+ /// @returns false if any kind of error occurs, true otherwise.<br>+ /// @brief Unconditionally release the lock in write mode.<br>
+ bool writer_release();<br>+<br>+ //@}<br>+ /// @name Platform Dependent Data<br>+ /// @{<br>+ private:<br>+#ifdef ENABLE_THREADS<br>+ void* data_; ///< We don't know what the data will be<br>
+#endif<br>+<br>+ /// @}<br>+ /// @name Do Not Implement<br>+ /// @{<br>+ private:<br>+ RWMutex(const RWMutex & original);<br>+ void operator=(const RWMutex &);<br>+ /// @}<br>+ };<br>+ }<br>
+}<br>+<br>+#endif<br><br>Added: llvm/trunk/lib/System/RWMutex.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/RWMutex.cpp?rev=73545&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/RWMutex.cpp?rev=73545&view=auto</a><br>
<br>==============================================================================<br>--- llvm/trunk/lib/System/RWMutex.cpp (added)<br>+++ llvm/trunk/lib/System/RWMutex.cpp Tue Jun 16 15:19:28 2009<br>@@ -0,0 +1,169 @@<br>
+//===- RWMutex.cpp - Reader/Writer Mutual Exclusion Lock --------*- C++ -*-===//<br>+//<br>+// The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+//<br>+// This file implements the llvm::sys::RWMutex class.<br>+//<br>+//===----------------------------------------------------------------------===//<br>
+<br>+#include "llvm/Config/config.h"<br>+#include "llvm/System/RWMutex.h"<br>+<br>+//===----------------------------------------------------------------------===//<br>+//=== WARNING: Implementation here must contain only TRULY operating system<br>
+//=== independent code.<br>+//===----------------------------------------------------------------------===//<br>+<br>+#if !defined(ENABLE_THREADS) || ENABLE_THREADS == 0<br>+// Define all methods as no-ops if threading is explicitly disabled<br>
+namespace llvm {<br>+using namespace sys;<br>+RWMutex::RWMutex( bool recursive) { }<br>+RWMutex::~RWMutex() { }<br>+bool RWMutex::reader_acquire() { return true; }<br>+bool RWMutex::reader_release() { return true; }<br>+bool RWMutex::writer_acquire() { return true; }<br>
+bool RWMutex::writer_release() { return true; }<br>+}<br>+#else<br>+<br>+#if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_RWLOCK_INIT)<br>+<br>+#include <cassert><br>+#include <pthread.h><br>+#include <stdlib.h><br>
+<br>+namespace llvm {<br>+using namespace sys;<br>+<br>+<br>+// This variable is useful for situations where the pthread library has been<br>+// compiled with weak linkage for its interface symbols. This allows the<br>+// threading support to be turned off by simply not linking against -lpthread.<br>
+// In that situation, the value of pthread_mutex_init will be 0 and<br>+// consequently pthread_enabled will be false. In such situations, all the<br>+// pthread operations become no-ops and the functions all return false. If<br>
+// pthread_rwlock_init does have an address, then rwlock support is enabled.<br>+// Note: all LLVM tools will link against -lpthread if its available since it<br>+// is configured into the LIBS variable.<br>+// Note: this line of code generates a warning if pthread_rwlock_init is not<br>
+// declared with weak linkage. It's safe to ignore the warning.<br>+static const bool pthread_enabled = true;<br>+<br>+// Construct a RWMutex using pthread calls<br>+RWMutex::RWMutex()<br>+ : data_(0)<br>+{<br>
+ if (pthread_enabled)<br>+ {<br>+ // Declare the pthread_rwlock data structures<br>+ pthread_rwlock_t* rwlock =<br>+ static_cast<pthread_rwlock_t*>(malloc(sizeof(pthread_rwlock_t)));<br>+ pthread_rwlockattr_t attr;<br>
+<br>+ // Initialize the rwlock attributes<br>+ int errorcode = pthread_rwlockattr_init(&attr);<br>+ assert(errorcode == 0);<br>+<br>+#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)<br>
+ // Make it a process local rwlock<br>+ errorcode = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);<br>+#endif<br>+<br>+ // Initialize the rwlock<br>+ errorcode = pthread_rwlock_init(rwlock, &attr);<br>
+ assert(errorcode == 0);<br>+<br>+ // Destroy the attributes<br>+ errorcode = pthread_rwlockattr_destroy(&attr);<br>+ assert(errorcode == 0);<br>+<br>+ // Assign the data member<br>+ data_ = rwlock;<br>
+ }<br>+}<br>+<br>+// Destruct a RWMutex<br>+RWMutex::~RWMutex()<br>+{<br>+ if (pthread_enabled)<br>+ {<br>+ pthread_rwlock_t* rwlock = static_cast<pthread_rwlock_t*>(data_);<br>+ assert(rwlock != 0);<br>+ pthread_rwlock_destroy(rwlock);<br>
+ free(rwlock);<br>+ }<br>+}<br>+<br>+bool<br>+RWMutex::reader_acquire()<br>+{<br>+ if (pthread_enabled)<br>+ {<br>+ pthread_rwlock_t* rwlock = static_cast<pthread_rwlock_t*>(data_);<br>+ assert(rwlock != 0);<br>
+<br>+ int errorcode = pthread_rwlock_rdlock(rwlock);<br>+ return errorcode == 0;<br>+ }<br>+ return false;<br>+}<br>+<br>+bool<br>+RWMutex::reader_release()<br>+{<br>+ if (pthread_enabled)<br>+ {<br>+ pthread_rwlock_t* rwlock = static_cast<pthread_rwlock_t*>(data_);<br>
+ assert(rwlock != 0);<br>+<br>+ int errorcode = pthread_rwlock_unlock(rwlock);<br>+ return errorcode == 0;<br>+ }<br>+ return false;<br>+}<br>+<br>+bool<br>+RWMutex::writer_acquire()<br>+{<br>+ if (pthread_enabled)<br>
+ {<br>+ pthread_rwlock_t* rwlock = static_cast<pthread_rwlock_t*>(data_);<br>+ assert(rwlock != 0);<br>+<br>+ int errorcode = pthread_rwlock_wrlock(rwlock);<br>+ return errorcode == 0;<br>+ }<br>+ return false;<br>
+}<br>+<br>+bool<br>+RWMutex::writer_release()<br>+{<br>+ if (pthread_enabled)<br>+ {<br>+ pthread_rwlock_t* rwlock = static_cast<pthread_rwlock_t*>(data_);<br>+ assert(rwlock != 0);<br>+<br>+ int errorcode = pthread_rwlock_unlock(rwlock);<br>
+ return errorcode == 0;<br>+ }<br>+ return false;<br>+}<br>+<br>+}<br>+<br>+#elif defined(LLVM_ON_UNIX)<br>+#include "Unix/RWMutex.inc"<br>+#elif defined( LLVM_ON_WIN32)<br>+#include "Win32/RWMutex.inc"<br>
+#else<br>+#warning Neither LLVM_ON_UNIX nor LLVM_ON_WIN32 was set in System/Mutex.cpp<br>+#endif<br>+#endif<br>+<br><br>Added: llvm/trunk/lib/System/Unix/RWMutex.inc<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/RWMutex.inc?rev=73545&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/RWMutex.inc?rev=73545&view=auto</a><br>
<br>==============================================================================<br>--- llvm/trunk/lib/System/Unix/RWMutex.inc (added)<br>+++ llvm/trunk/lib/System/Unix/RWMutex.inc Tue Jun 16 15:19:28 2009<br>@@ -0,0 +1,43 @@<br>
+//= llvm/System/Unix/RWMutex.inc - Unix Reader/Writer Mutual Exclusion Lock =//<br>+//<br>+// The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+//<br>+// This file implements the Unix specific (non-pthread) RWMutex class.<br>+//<br>
+//===----------------------------------------------------------------------===//<br>+<br>+//===----------------------------------------------------------------------===//<br>+//=== WARNING: Implementation here must contain only generic UNIX code that<br>
+//=== is guaranteed to work on *all* UNIX variants.<br>+//===----------------------------------------------------------------------===//<br>+<br>+namespace llvm {<br>+<br>+using namespace sys;<br>+<br>+RWMutex::RWMutex() { }<br>
+<br>+RWMutex::~RWMutex() { }<br>+<br>+bool RWMutex::reader_acquire() {<br>+ return true;<br>+}<br>+<br>+bool RWMutex::reader_release() {<br>+ return true;<br>+}<br>+<br>+bool RWMutex::writer_acquire() {<br>+ return true;<br>
+}<br>+<br>+bool RWMutex::writer_release() {<br>+ return true;<br>+}<br>+<br>+}<br><br>Modified: llvm/trunk/lib/System/Win32/Mutex.inc<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Mutex.inc?rev=73545&r1=73544&r2=73545&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Mutex.inc?rev=73545&r1=73544&r2=73545&view=diff</a><br>
<br>==============================================================================<br>--- llvm/trunk/lib/System/Win32/Mutex.inc (original)<br>+++ llvm/trunk/lib/System/Win32/Mutex.inc Tue Jun 16 15:19:28 2009<br>@@ -22,7 +22,7 @@<br>
namespace llvm {<br> using namespace sys;<br><br>-Mutex::Mutex(bool /*recursive*/)<br>+Mutex::Mutex()<br> {<br> data_ = new CRITICAL_SECTION;<br> InitializeCriticalSection((LPCRITICAL_SECTION)data_);<br><br>Added: llvm/trunk/lib/System/Win32/RWMutex.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/RWMutex.inc?rev=73545&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/RWMutex.inc?rev=73545&view=auto</a><br>
<br>==============================================================================<br>--- llvm/trunk/lib/System/Win32/RWMutex.inc (added)<br>+++ llvm/trunk/lib/System/Win32/RWMutex.inc Tue Jun 16 15:19:28 2009<br>@@ -0,0 +1,55 @@<br>
+//= llvm/System/Win32/Mutex.inc - Win32 Reader/Writer Mutual Exclusion Lock =//<br>+//<br>+// The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+//<br>+// This file implements the Win32 specific (non-pthread) RWMutex class.<br>+//<br>
+//===----------------------------------------------------------------------===//<br>+<br>+//===----------------------------------------------------------------------===//<br>+//=== WARNING: Implementation here must contain only generic Win32 code that<br>
+//=== is guaranteed to work on *all* Win32 variants.<br>+//===----------------------------------------------------------------------===//<br>+<br>+#include "Win32.h"<br>+<br>+namespace llvm {<br>+using namespace sys;<br>
+<br>+RWMutex::RWMutex() {<br>+ data_ = new PSRWLOCK;<br>+ InitializeSRWLock((PSRWLOCK*)data_);<br>+}<br>+<br>+RWMutex::~RWMutex() {<br>+ delete (PSRWLOCK*)data_;<br>+ data_ = 0;<br>+}<br>+<br>+bool RWMutex::reader_acquire() {<br>
+ AcquireSRWLockShared((PSRWLOCK*)data_);<br>+ return true;<br>+}<br>+<br>+bool RWMutex::reader_release() {<br>+ ReleaseSRWLockShared((PSRWLOCK*)data_);<br>+ return true;<br>+}<br>+<br>+bool RWMutex::writer_acquire() {<br>
+ AcquireSRWLockExclusive((PSRWLOCK*)data_);<br>+ return true;<br>+}<br>+<br>+bool RWMutex::writer_release() {<br>+ ReleaseSRWLockExclusive((PSRWLOCK*)data_);<br>+ return true;<br>+}<br>+<br>+<br>+}<br><br><br>_______________________________________________<br>
llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all">
<div></div><br>-- <br>-Howard<br>