NCBI C++ ToolKit
threads_man.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

00001 #ifndef NETCACHE__THREADS_MAN__HPP
00002 #define NETCACHE__THREADS_MAN__HPP
00003 /*  $Id: threads_man.hpp 54728 2012-06-06 17:59:29Z ivanovp $
00004  * ===========================================================================
00005  *
00006  *                            PUBLIC DOMAIN NOTICE
00007  *               National Center for Biotechnology Information
00008  *
00009  *  This software/database is a "United States Government Work" under the
00010  *  terms of the United States Copyright Act.  It was written as part of
00011  *  the author's official duties as a United States Government employee and
00012  *  thus cannot be copyrighted.  This software/database is freely available
00013  *  to the public for use. The National Library of Medicine and the U.S.
00014  *  Government have not placed any restriction on its use or reproduction.
00015  *
00016  *  Although all reasonable efforts have been taken to ensure the accuracy
00017  *  and reliability of the software and data, the NLM and the U.S.
00018  *  Government do not and cannot warrant the performance or results that
00019  *  may be obtained by using this software or data. The NLM and the U.S.
00020  *  Government disclaim all warranties, express or implied, including
00021  *  warranties of performance, merchantability or fitness for any particular
00022  *  purpose.
00023  *
00024  *  Please cite the author in any work or product based on this material.
00025  *
00026  * ===========================================================================
00027  *
00028  * Authors:  Pavel Ivanov
00029  *
00030  * File Description: 
00031  */
00032 
00033 
00034 #include "scheduler.hpp"
00035 
00036 #ifdef NCBI_OS_LINUX
00037 # include <pthread.h>
00038 #endif
00039 
00040 
00041 BEGIN_NCBI_SCOPE
00042 
00043 
00044 struct SMMMemPoolsSet;
00045 struct SLogData;
00046 struct SRCUInfo;
00047 struct SSchedInfo;
00048 struct SSocketsData;
00049 class CSrvStat;
00050 
00051 
00052 void InitCurThreadStorage(void);
00053 SSrvThread* GetCurThread(void);
00054 void ConfigureThreads(CNcbiRegistry* reg, CTempString section);
00055 bool InitThreadsMan(void);
00056 void RunMainThread(void);
00057 void FinalizeThreadsMan(void);
00058 void RequestThreadStart(SSrvThread* thr);
00059 void RequestThreadStop(SSrvThread* thr);
00060 void RequestThreadRevive(SSrvThread* thr);
00061 TSrvThreadNum GetCntRunningThreads(void);
00062 
00063 
00064 
00065 enum EThreadState {
00066     eThreadStarting,
00067     eThreadRunning,
00068     eThreadRevived,
00069     eThreadLockedForStop,
00070     eThreadStopped,
00071     eThreadReleased,
00072     eThreadDormant
00073 };
00074 
00075 struct SSrvThread : public CSrvRCUUser
00076 {
00077     TSrvThreadNum thread_num;
00078     Uint4 seen_jiffy;
00079     int seen_secs;
00080     EThreadState thread_state;
00081     EServerState seen_srv_state;
00082 #ifdef NCBI_OS_LINUX
00083     pthread_t thread_handle;
00084 #endif
00085     CSrvTask* cur_task;
00086     SMMMemPoolsSet* mm_pool;
00087     SSchedInfo* sched;
00088     SLogData* log_data;
00089     SRCUInfo* rcu;
00090     SSocketsData* socks;
00091     CSrvStat* stat;
00092 
00093 
00094     SSrvThread(void);
00095     virtual ~SSrvThread(void);
00096 
00097 private:
00098     virtual void ExecuteRCU(void);
00099 };
00100 
00101 
00102 enum EThreadMgrState {
00103     eThrMgrIdle,
00104     eThrMgrPreparesToStop,
00105     eThrMgrThreadExited,
00106     eThrMgrSocksMoved,
00107     eThrMgrNeedNewThread,
00108     eThrMgrStarting
00109 };
00110 
00111 
00112 //////////////////////////////////////////////////////////////////////////
00113 // Inline functions
00114 //////////////////////////////////////////////////////////////////////////
00115 
00116 inline bool
00117 IsThreadRunning(SSrvThread* thr)
00118 {
00119     return thr->thread_state <= eThreadRevived;
00120 }
00121 
00122 END_NCBI_SCOPE
00123 
00124 #endif /* NETCACHE__THREADS_MAN__HPP */
Modified on Fri Jan 30 12:48:13 2015 by modify_doxy.py rev. 426318