RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
soa/gc/gc.h
00001 /* gc.h                                                            -*- C++ -*-
00002    Jeremy Barnes, 26 September 2011
00003    Copyright (c) 2011 Datacratic.  All rights reserved.
00004 
00005    Garbage collection basics.
00006 */
00007 
00008 #ifndef __mmap__gc_h__
00009 #define __mmap__gc_h__
00010 
00011 #include "jml/arch/exception.h"
00012 #include <boost/function.hpp>
00013 #include "jml/compiler/compiler.h"
00014 
00015 namespace Datacratic {
00016 namespace MMap {
00017 
00018 int getThreadNum() JML_PURE_FN;
00019 
00020 #if 0
00021 
00022 
00023 void readLock();
00024 void readUnlock();
00025 bool isReadLocked();
00026 
00027 struct ReadGuard {
00028     ReadGuard()
00029     {
00030         readLock();
00031     }
00032 
00033     ~ReadGuard()
00034     {
00035         readUnlock();
00036     }
00037 };
00038 
00039 struct FancyReadGuard {
00040 
00041     FancyReadGuard(bool doLock = true)
00042         : locked_(false)
00043     {
00044         if (doLock) lock();
00045     }
00046 
00047     ~FancyReadGuard()
00048     {
00049         if (locked_) unlock();
00050     }
00051 
00052     void unlock()
00053     {
00054         if (!locked_)
00055             throw ML::Exception("attempt to unlock unlocked FancyReadGuard");
00056         readUnlock();
00057         locked_ = false;
00058     }
00059 
00060     void lock()
00061     {
00062         if (locked_)
00063             throw ML::Exception("attempt to lock locked FancyReadGuard");
00064         readLock();
00065         locked_ = true;
00066     }
00067 
00068     bool locked() const { return locked_; }
00069 
00070     bool locked_;
00071 };
00072 
00073 void writeLock();
00074 void writeUnlock();
00075 bool isWriteLocked();
00076 
00077 struct WriteGuard {
00078     WriteGuard()
00079     {
00080         writeLock();
00081     }
00082     
00083     ~WriteGuard()
00084     {
00085         writeUnlock();
00086     }
00087 };
00088 
00089 // Stop the whole world, including dealing with all deferred updates
00090 void stopTheWorld();
00091 void restartTheWorld();
00092 
00093 
00094 
00095 struct StopTheWorldGuard {
00096     StopTheWorldGuard()
00097     {
00098         stopTheWorld();
00099     }
00100     
00101     ~StopTheWorldGuard()
00102     {
00103         restartTheWorld();
00104     }
00105 };
00106 
00110 void waitForGC();
00111 
00113 void deferGC(const boost::function<void ()> & work);
00114 
00115 #endif
00116 
00117 } // namespace MMap
00118 } // namespace Datacratic
00119 
00120 #endif /* __mmap__gc_h__ */
00121 
00122 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator