国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 和田县| 宕昌县| 岳阳县| 乐昌市| 鹰潭市| 明星| 尉氏县| 兴城市| 华容县| 扶绥县| 尚志市| 神农架林区| 乃东县| 泽州县| 安图县| 化隆| 松桃| 台东市| 六盘水市| 青川县| 滁州市| 临泽县| 灵川县| 襄樊市| 甘泉县| 盘锦市| 梧州市| 开阳县| 交城县| 开封市| 恩平市| 虎林市| 临猗县| 漳平市| 新密市| 新竹市| 乳山市| 康马县| 阳山县| 贵定县| 南澳县|