123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "wsTimerThread.h"
- #include <iostream>
- namespace YA
- {
- wsTimerThread::wsTimerThread()
- {
- __Reset();
- }
- wsTimerThread::~wsTimerThread()
- {
- Stop();
- }
- void wsTimerThread::Start()
- {
- __Running = true;
- __Thread.reset( new boost::thread( boost::bind( &wsTimerThread::_ThreadFunc, this, this ) ) );
- __Thread->detach();
- }
- void wsTimerThread::Stop()
- {
- __Enable = false;
- boost::unique_lock<boost::mutex> lock( __ExitMutex );
- __ExitCond.wait( lock );
- __Running = false;
- }
- void wsTimerThread::__Reset()
- {
- __Enable = true;
- __Running = false;
- }
- void wsTimerThread::__ChkConfig()
- {
- if ( __Config.SendInterval < MIN_SEND_INTERVAL )
- {
- __Config.SendInterval = MIN_SEND_INTERVAL;
- }
- }
- void wsTimerThread::_ThreadFunc( wsTimerThread * pOwner )
- {
- while ( pOwner->__Enable )
- {
- //do something...
- printf("doing ....timer thread .......\n");
- boost::this_thread::sleep( boost::posix_time::millisec( 1000 ) );
- }
- pOwner->__ExitCond.notify_one();
- }
- void wsTimerThread::Init( const _THREAD_CONFIG_ & Config )
- {
- __Config = Config;
- __ChkConfig();
- }
- void wsTimerThread::add_card_pos( const _CARD_POS_ & pos )
- {
- __CardPosList.insert( pos.ID, pos );
- }
- void wsTimerThread::upt_card_pos( const _CARD_POS_ & pos )
- {
- __CardPosList.update( pos.ID, pos );
- }
- void wsTimerThread::del_card_pos( const _CARD_POS_ & pos )
- {
- __CardPosList.erase( pos.ID );
- }
- }
|