00001 00028 #ifndef GALOIS_THREAD_RW_LOCK_H 00029 #define GALOIS_THREAD_RW_LOCK_H 00030 00031 #include "Galois/Runtime/ll/PaddedLock.h" 00032 #include "Galois/Runtime/PerThreadStorage.h" 00033 00034 namespace Galois { 00035 namespace Runtime { 00036 namespace LL { 00037 00038 //FIXME: nothing in LL should depend on Runtime 00039 00040 class ThreadRWlock { 00041 00042 typedef PaddedLock<true> Lock_ty; 00043 // typedef Galois::Runtime::LL::SimpleLock<true> Lock_ty; 00044 typedef PerThreadStorage<Lock_ty> PerThreadLock; 00045 00046 PerThreadLock locks; 00047 00048 public: 00049 00050 00051 void readLock () { 00052 locks.getLocal ()->lock (); 00053 } 00054 00055 void readUnlock () { 00056 locks.getLocal ()->unlock (); 00057 } 00058 00059 void writeLock () { 00060 for (unsigned i = 0; i < locks.size (); ++i) { 00061 locks.getRemote (i)->lock (); 00062 } 00063 } 00064 00065 void writeUnlock () { 00066 for (unsigned i = 0; i < locks.size (); ++i) { 00067 locks.getRemote (i)->unlock (); 00068 } 00069 } 00070 00071 00072 }; 00073 00074 00075 } // end namespace LL 00076 } // end namespace Runtime 00077 } // end namespace Galois 00078 00079 00080 00081 #endif // GALOIS_THREAD_RW_LOCK_H