100 lines
3.1 KiB
C
100 lines
3.1 KiB
C
|
/****************************************************************************
|
|||
|
Copyright (c) 2011-2013,WebJet Business Division,CYOU
|
|||
|
|
|||
|
http://www.genesis-3d.com.cn
|
|||
|
|
|||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|||
|
of this software and associated documentation files (the "Software"), to deal
|
|||
|
in the Software without restriction, including without limitation the rights
|
|||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||
|
copies of the Software, and to permit persons to whom the Software is
|
|||
|
furnished to do so, subject to the following conditions:
|
|||
|
|
|||
|
The above copyright notice and this permission notice shall be included in
|
|||
|
all copies or substantial portions of the Software.
|
|||
|
|
|||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
|
THE SOFTWARE.
|
|||
|
****************************************************************************/
|
|||
|
#ifndef __ThreadRuntimeInfo_H__
|
|||
|
#define __ThreadRuntimeInfo_H__
|
|||
|
|
|||
|
#include "core/refcounted.h"
|
|||
|
|
|||
|
|
|||
|
namespace Threading
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD>ÿһ<C3BF><D2BB><EFBFBD>߳<EFBFBD><DFB3>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
const SizeT MaxThreadInstanceNum = 256;
|
|||
|
|
|||
|
class ThreadRunTimeInfo
|
|||
|
{
|
|||
|
public:
|
|||
|
ThreadRunTimeInfo(void);
|
|||
|
~ThreadRunTimeInfo(void);
|
|||
|
|
|||
|
char* GetInstance( IndexT i );
|
|||
|
|
|||
|
void SetInstance( IndexT i , char* pIns );
|
|||
|
|
|||
|
bool HasInstance( IndexT i );
|
|||
|
|
|||
|
public:
|
|||
|
// <20><>ǰ<EFBFBD>߳<EFBFBD><DFB3>е<EFBFBD><D0B5><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
char* mInstanceArray[MaxThreadInstanceNum];
|
|||
|
// <20>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
const char* mThreadName;
|
|||
|
public:
|
|||
|
|
|||
|
/// *******<2A><>ֹ<EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>******* <20><><EFBFBD><EFBFBD>Ψһ<CEA8><D2BB>һ<EFBFBD><D2BB>ID<49><44><EFBFBD>̶߳<DFB3><CCB6><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
static IndexT GetThreadInstanceID(void);
|
|||
|
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>̶߳<DFB3><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>,ÿ<><C3BF><EFBFBD>߳<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>Ρ<EFBFBD><CEA1><EFBFBD><EFBFBD>̱߳<DFB3><CCB1><EFBFBD><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD>̺߳ʹ<CCBA><CDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0><EFBFBD>á<EFBFBD><C3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̱߳<DFB3><CCB1><EFBFBD><EFBFBD>ڸո<DAB8><D5B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0><EFBFBD>á<EFBFBD>
|
|||
|
static void SetupMyThreadRunTime( const char* threadName );
|
|||
|
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>.<2E><><EFBFBD>̱߳<DFB3><CCB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
static void DestoryThreadRunTime( bool isMainThread = false );
|
|||
|
|
|||
|
/// <20>õ<EFBFBD><C3B5><EFBFBD>ǰ<EFBFBD>̵߳<DFB3><CCB5><EFBFBD><EFBFBD><EFBFBD>ʱ
|
|||
|
static Threading::ThreadRunTimeInfo* GetMyThreadRuntime( void );
|
|||
|
|
|||
|
private:
|
|||
|
static IndexT ThreadInstanceCounter;
|
|||
|
static IndexT mTlsSlot; // <09><><EFBFBD><EFBFBD>Tls<6C><73><EFBFBD>洢<EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ϣ
|
|||
|
};
|
|||
|
|
|||
|
//------------------------------------------------------------------------
|
|||
|
inline char* ThreadRunTimeInfo::GetInstance( IndexT i )
|
|||
|
{
|
|||
|
n_assert( i >=0 && i < MaxThreadInstanceNum );
|
|||
|
n_assert( mInstanceArray[i] );
|
|||
|
return mInstanceArray[i];
|
|||
|
}
|
|||
|
//------------------------------------------------------------------------
|
|||
|
inline void ThreadRunTimeInfo::SetInstance( IndexT i , char* pIns )
|
|||
|
{
|
|||
|
n_assert( i >=0 && i < MaxThreadInstanceNum );
|
|||
|
mInstanceArray[i] = pIns;
|
|||
|
}
|
|||
|
//------------------------------------------------------------------------
|
|||
|
inline bool ThreadRunTimeInfo::HasInstance( IndexT i )
|
|||
|
{
|
|||
|
n_assert( i >=0 && i < MaxThreadInstanceNum );
|
|||
|
return mInstanceArray[i] != NULL;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#endif // __ThreadRuntimeInfo_H__
|