00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "eyedb/eyedb.h"
00026 #include "ThreadPoolManager.h"
00027
00028 eyedblib::ThreadPool *ThreadPoolManager::thrpool = 0;
00029
00030 #define DEFERRED_CONSTRUCT
00031
00032 namespace eyedbsm {
00033 extern void setThreadPool(eyedblib::ThreadPool *);
00034 extern void setThreadPoolGet(eyedblib::ThreadPool *(*)());
00035 }
00036
00037 static eyedblib::ThreadPool *
00038 get_thread_pool()
00039 {
00040 return ThreadPoolManager::getThrPool();
00041 }
00042
00043 void
00044 ThreadPoolManager::init()
00045 {
00046 #ifdef DEFERRED_CONSTRUCT
00047 eyedbsm::setThreadPoolGet(get_thread_pool);
00048 #else
00049 delete thrpool;
00050
00051 unsigned int thrcnt;
00052 const char *thrcnt_str = eyedb::getConfigValue("thread_count");
00053 thrcnt = thrcnt_str ? atoi(thrcnt_str) : 1;
00054
00055 Thread::initCallingThread();
00056 thrpool = new eyedblib::ThreadPool(thrcnt);
00057
00058 const char *thrprofile_str = eyedb::getConfigValue("thread_profile");
00059 bool thrprofile = (thrprofile_str && !strcasecmp(thrprofile_str, "true"));
00060
00061 if (thrprofile)
00062 thrpool->setProfile(true);
00063
00064 eyedbsm::setThreadPool(thrpool);
00065 #endif
00066 }
00067
00068 eyedblib::ThreadPool *
00069 ThreadPoolManager::getThrPool()
00070 {
00071 #ifndef DEFERRED_CONSTRUCT
00072 return thrpool;
00073 #else
00074 if (thrpool) return thrpool;
00075 unsigned int thrcnt;
00076 const char *thrcnt_str = eyedb::ServerConfig::getSValue("thread_count");
00077 thrcnt = thrcnt_str ? atoi(thrcnt_str) : 1;
00078
00079 eyedblib::Thread::initCallingThread();
00080 thrpool = new eyedblib::ThreadPool(thrcnt);
00081
00082 const char *thrprofile_str = eyedb::ServerConfig::getSValue("thread_profile");
00083 bool thrprofile = (thrprofile_str && !strcasecmp(thrprofile_str, "true"));
00084
00085 if (thrprofile)
00086 thrpool->setProfile(true);
00087
00088 eyedbsm::setThreadPool(thrpool);
00089 return thrpool;
00090 #endif
00091 }
00092
00093 void
00094 ThreadPoolManager::_release()
00095 {
00096 delete thrpool;
00097 thrpool = 0;
00098 }