wsTimerThread.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "wsTimerThread.h"
  2. #include <iostream>
  3. namespace YA
  4. {
  5. wsTimerThread::wsTimerThread()
  6. {
  7. __Reset();
  8. }
  9. wsTimerThread::~wsTimerThread()
  10. {
  11. Stop();
  12. }
  13. void wsTimerThread::Start()
  14. {
  15. __Running = true;
  16. __Thread.reset( new boost::thread( boost::bind( &wsTimerThread::_ThreadFunc, this, this ) ) );
  17. __Thread->detach();
  18. }
  19. void wsTimerThread::Stop()
  20. {
  21. __Enable = false;
  22. boost::unique_lock<boost::mutex> lock( __ExitMutex );
  23. __ExitCond.wait( lock );
  24. __Running = false;
  25. }
  26. void wsTimerThread::__Reset()
  27. {
  28. __Enable = true;
  29. __Running = false;
  30. }
  31. void wsTimerThread::__ChkConfig()
  32. {
  33. if ( __Config.SendInterval < MIN_SEND_INTERVAL )
  34. {
  35. __Config.SendInterval = MIN_SEND_INTERVAL;
  36. }
  37. }
  38. void wsTimerThread::_ThreadFunc( wsTimerThread * pOwner )
  39. {
  40. while ( pOwner->__Enable )
  41. {
  42. //do something...
  43. printf("doing ....timer thread .......\n");
  44. boost::this_thread::sleep( boost::posix_time::millisec( 1000 ) );
  45. }
  46. pOwner->__ExitCond.notify_one();
  47. }
  48. void wsTimerThread::Init( const _THREAD_CONFIG_ & Config )
  49. {
  50. __Config = Config;
  51. __ChkConfig();
  52. }
  53. void wsTimerThread::add_card_pos( const _CARD_POS_ & pos )
  54. {
  55. __CardPosList.insert( pos.ID, pos );
  56. }
  57. void wsTimerThread::upt_card_pos( const _CARD_POS_ & pos )
  58. {
  59. __CardPosList.update( pos.ID, pos );
  60. }
  61. void wsTimerThread::del_card_pos( const _CARD_POS_ & pos )
  62. {
  63. __CardPosList.erase( pos.ID );
  64. }
  65. }