⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sync.h

📁 FastDb是高效的内存数据库系统
💻 H
字号:
//-< SYNC.H >--------------------------------------------------------*--------*// FastDB                    Version 1.0         (c) 1999  GARRET    *     ?  *// (Main Memory Database Management System)                          *   /\|  *//                                                                   *  /  \  *//                          Created:     20-Nov-98    K.A. Knizhnik  * / [] \ *//                          Last update: 20-Dec-98    K.A. Knizhnik  * GARRET *//-------------------------------------------------------------------*--------*// Intertask synchonization primitives//-------------------------------------------------------------------*--------*#ifndef __SYNC_H__#define __SYNC_H__#ifdef _WIN32#include "sync_w32.h"    #else // Unix#include "sync_unix.h"#endifBEGIN_FASTDB_NAMESPACEclass FASTDB_DLL_ENTRY dbSystem {   public:    static unsigned getCurrentTimeMsec();};// Common decls for all platformsclass FASTDB_DLL_ENTRY dbCriticalSection {   private:    dbMutex& mutex;  public:    dbCriticalSection(dbMutex& guard) : mutex(guard) {        mutex.lock();    }    ~dbCriticalSection() {         mutex.unlock();    }};        #define SMALL_BUF_SIZE 512class FASTDB_DLL_ENTRY dbSmallBuffer {   protected:    char   smallBuf[SMALL_BUF_SIZE];    char*  buf;    size_t used;  public:    dbSmallBuffer(size_t size) {         if (size > SMALL_BUF_SIZE) {             buf = new char[size];        } else {             buf = smallBuf;        }        used = size;    }    dbSmallBuffer() {         used = 0;        buf = smallBuf;    }    void put(size_t size) {         if (size > SMALL_BUF_SIZE && size > used) {             if (buf != smallBuf) {                 delete[] buf;            }            buf = new char[size];            used = size;        }    }    operator char*() { return buf; }    char* base() { return buf; }    ~dbSmallBuffer() {         if (buf != smallBuf) {             delete[] buf;        }    }};class dbThreadPool;class FASTDB_DLL_ENTRY dbPooledThread {   private:    friend class dbThreadPool;    dbThread                thread;    dbThreadPool*           pool;    dbPooledThread*         next;    dbThread::thread_proc_t f;    void*                   arg;    bool                    running;    dbLocalSemaphore        startSem;    dbLocalSemaphore        readySem;        static void thread_proc  pooledThreadFunc(void* arg);    void run();    void stop();    dbPooledThread(dbThreadPool* threadPool);     ~dbPooledThread(); };class FASTDB_DLL_ENTRY dbThreadPool {     friend class dbPooledThread;    dbPooledThread* freeThreads;    dbMutex         mutex;  public:    dbPooledThread* create(dbThread::thread_proc_t f, void* arg);    void join(dbPooledThread* thr);    dbThreadPool();    ~dbThreadPool();};    END_FASTDB_NAMESPACE    #endif // __SYNC_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -