ThreadPoolManager.cc

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
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 }

Generated on Mon Dec 22 18:16:11 2008 for eyedb by  doxygen 1.5.3