国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[code-design]TvServer 之CRunOnce

2019-11-06 09:37:39
字體:
來源:轉載
供稿:網友

CRunOnce is mainly described how to create exit thread

class CRunOnce: public IThread{PRivate: pthread_mutex_t m_mutex; int m_state; pthread_t m_thread; iparams *m_params; IRunnable *m_runnable; static void thread_exit(int sig) { TvServerService_detachThread(); pthread_exit(0); } static void * looper_func(void *p) { CRunOnce *r = (CRunOnce*)p; //assert(r && r->m_runnable); struct sigaction actions; memset(&actions, 0, sizeof(actions)); // sigemptyset(&actions.sa_mask); actions.sa_flags = SA_SIGINFO; actions.sa_handler = CRunOnce::thread_exit; sigaction(SIGUSR2,&actions,NULL); TvServerService_attachThread(); r->m_runnable->Run(r->m_params); TvServerService_detachThread(); return NULL; }public: virtual void Post(IRunnable *r, bool replace, IParams *p, unsigned int after ) { if(!m_runnable && r) { m_runnable = r; m_params = p; pthread_mutex_lock(&m_mutex); if(m_state == RUN_STATE_INIT) { m_state = RUN_STATE_RUNNING; int ret = pthread_create(&m_thread, NULL, CRunOnce::looper_func, this); // pthread_detach(m_thread); } //assert(!ret); pthread_mutex_unlock(&m_mutex); } } CRunOnce() { m_mutex = PTHREAD_MUTEX_INITIALIZER; m_state = RUN_STATE_INIT; m_runnable = NULL; m_params = NULL; } virtual void Halt(void) { bool tohalt=false; pthread_mutex_lock(&m_mutex); if(m_state == RUN_STATE_RUNNING) { m_state = RUN_STATE_HALTED; tohalt = true; } pthread_mutex_unlock(&m_mutex); if(tohalt) { pthread_kill(m_thread, SIGUSR2); pthread_join(m_thread,NULL); } } virtual ~CRunOnce() { Halt(); if(m_runnable) { if(m_params) m_params->Release(); delete m_runnable; } }};
上一篇:安卓6.0權限使用

下一篇:day1

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 门源| 达孜县| 静安区| 昌江| 石屏县| 株洲县| 汉沽区| 茌平县| 米泉市| 确山县| 古蔺县| 鄂托克旗| 和硕县| 台中市| 房产| 迁安市| 淳化县| 安康市| 全州县| 公主岭市| 怀来县| 贡觉县| 辉南县| 达尔| 永春县| 高雄市| 科技| 长汀县| 丰镇市| 巴彦县| 宁河县| 当雄县| 即墨市| 安福县| 仙桃市| 永吉县| 普陀区| 双城市| 四子王旗| 祁连县| 河间市|