Main Page | Class Hierarchy | Class List | File List | Class Members

sync.h

00001 //-< SYNC.H >--------------------------------------------------------*--------*
00002 // FastDB                    Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Main Memory Database Management System)                          *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:     20-Nov-98    K.A. Knizhnik  * / [] \ *
00006 //                          Last update: 20-Dec-98    K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // Intertask synchonization primitives
00009 //-------------------------------------------------------------------*--------*
00010 
00011 #ifndef __SYNC_H__
00012 #define __SYNC_H__
00013 
00014 class FASTDB_DLL_ENTRY dbSystem { 
00015   public:
00016     static unsigned getCurrentTimeMsec();
00017 };
00018 
00019 #ifdef _WIN32
00020 #include "sync_w32.h"    
00021 #else // Unix
00022 #include "sync_unix.h"
00023 #endif
00024 
00025 // Common decls for all platforms
00026 class FASTDB_DLL_ENTRY dbCriticalSection { 
00027   private:
00028     dbMutex& mutex;
00029   public:
00030     dbCriticalSection(dbMutex& guard) : mutex(guard) {
00031         mutex.lock();
00032     }
00033     ~dbCriticalSection() { 
00034         mutex.unlock();
00035     }
00036 };
00037         
00038 #define SMALL_BUF_SIZE 512
00039 
00040 class FASTDB_DLL_ENTRY dbSmallBuffer { 
00041   protected:
00042     char   smallBuf[SMALL_BUF_SIZE];
00043     char*  buf;
00044     size_t used;
00045 
00046   public:
00047     dbSmallBuffer(size_t size) { 
00048         if (size > SMALL_BUF_SIZE) { 
00049             buf = new char[size];
00050         } else { 
00051             buf = smallBuf;
00052         }
00053         used = size;
00054     }
00055 
00056     dbSmallBuffer() { 
00057         used = 0;
00058         buf = smallBuf;
00059     }
00060 
00061     void put(size_t size) { 
00062         if (size > SMALL_BUF_SIZE && size > used) { 
00063             if (buf != smallBuf) { 
00064                 delete[] buf;
00065             }
00066             buf = new char[size];
00067             used = size;
00068         }
00069     }
00070 
00071     operator char*() { return buf; }
00072     char* base() { return buf; }
00073 
00074     ~dbSmallBuffer() { 
00075         if (buf != smallBuf) { 
00076             delete[] buf;
00077         }
00078     }
00079 };
00080 
00081 
00082 class FASTDB_DLL_ENTRY dbPooledThread { 
00083   private:
00084     friend class dbThreadPool;
00085 
00086     dbThread                thread;
00087     dbThreadPool*           pool;
00088     dbPooledThread*         next;
00089     dbThread::thread_proc_t f;
00090     void*                   arg;
00091     bool                    running;
00092     dbLocalSemaphore        startSem;
00093     dbLocalSemaphore        readySem;
00094     
00095     static void thread_proc  pooledThreadFunc(void* arg);
00096 
00097     void run();
00098     void stop();
00099 
00100     dbPooledThread(dbThreadPool* threadPool); 
00101     ~dbPooledThread(); 
00102 };
00103 
00104 class FASTDB_DLL_ENTRY dbThreadPool { 
00105     friend class dbPooledThread;
00106     dbPooledThread* freeThreads;
00107     dbMutex         mutex;
00108 
00109   public:
00110     dbPooledThread* create(dbThread::thread_proc_t f, void* arg);
00111     void join(dbPooledThread* thr);
00112     dbThreadPool();
00113     ~dbThreadPool();
00114 };    
00115     
00116 #endif // __SYNC_H__
00117 
00118 

Generated on Thu Feb 12 13:04:48 2004 for FastDB by doxygen 1.3.5