00001 00024 #ifndef GALOIS_WORKLIST_GFIFO_H 00025 #define GALOIS_WORKLIST_GFIFO_H 00026 00027 #include "Galois/Runtime/ll/PaddedLock.h" 00028 #include "Galois/gdeque.h" 00029 #include "WLCompileCheck.h" 00030 00031 namespace Galois { 00032 namespace WorkList { 00033 00034 template<typename T = int, bool Concurrent = true> 00035 struct GFIFO : private boost::noncopyable, private Runtime::LL::PaddedLock<Concurrent> { 00036 template<bool _concurrent> 00037 struct rethread { typedef GFIFO<T, _concurrent> type; }; 00038 00039 template<typename _T> 00040 struct retype { typedef GFIFO<_T, Concurrent> type; }; 00041 00042 private: 00043 gdeque<T> wl; 00044 00045 using Runtime::LL::PaddedLock<Concurrent>::lock; 00046 using Runtime::LL::PaddedLock<Concurrent>::try_lock; 00047 using Runtime::LL::PaddedLock<Concurrent>::unlock; 00048 00049 public: 00050 GFIFO() {} //required for apparent bug in clang 00051 typedef T value_type; 00052 00053 void push(const value_type& val) { 00054 lock(); 00055 wl.push_back(val); 00056 unlock(); 00057 } 00058 00059 template<typename Iter> 00060 void push(Iter b, Iter e) { 00061 lock(); 00062 while (b != e) 00063 wl.push_back(*b++); 00064 unlock(); 00065 } 00066 00067 template<typename RangeTy> 00068 void push_initial(const RangeTy& range) { 00069 if (Runtime::LL::getTID() == 0) 00070 push(range.begin(), range.end()); 00071 } 00072 00073 Galois::optional<value_type> pop() { 00074 Galois::optional<value_type> retval; 00075 lock(); 00076 if (!wl.empty()) { 00077 retval = wl.front(); 00078 wl.pop_front(); 00079 } 00080 unlock(); 00081 return retval; 00082 } 00083 }; 00084 GALOIS_WLCOMPILECHECK(GFIFO) 00085 00086 } // end namespace WorkList 00087 } // end namespace Galois 00088 00089 #endif