嵌入式 解决线程使用sleep或usleep等函数导致整个进程睡眠的问题
2013-12-06 21:43
579 查看
解决线程使用sleep或usleep等函数导致整个进程睡眠的问题:
获取当前时间的秒数
使用下面的函数接口完成替换线程中sleep计时
call the time interval api example
获取当前时间的秒数
/* author : kj time : 2013-12-06 21:36 instruction: get the num of the current seconds */ int get_current_time_second(void) { struct tm *tmnow; struct timeval tv; gettimeofday(&tv,NULL); tmnow = localtime(&tv.tv_sec); return tv.tv_sec; }
使用下面的函数接口完成替换线程中sleep计时
/* author : kj time : 2013-12-06 21:42 function : done the function of time interval in separate thread */ int pthread_count_second(int time_interval) { int current_seconds = 0; int execl_seconds = 0; int set_time_interval = time_interval; current_seconds = get_current_time_second(); execl_seconds = current_seconds + set_time_interval; while(1) { current_seconds = get_current_time_second(); if((execl_seconds - current_seconds) == 0) { break; } } return 0; }
call the time interval api example
/* author : kj time : 2013-12-01 instrucion: glitter : 0 - direct set to board 1 - speed slow 2 - speed quickly */ int set_led_status(char *led_status,int glitter_type) { //int i_temp = 0;//the times need global variable char set_led_status_buf[4] = {0}; joseph_ipnc_param.joseph_ipnc_network_attr.joseph_ipnc_led_glitter_close = read_user_file("joseph_ipnc_led_glitter_close"); if(glitter_type == 0) { strcpy(set_led_status_buf,led_status); set_status_to_board(set_led_status_buf); } if(glitter_type == 1) { strcpy(set_led_status_buf,led_status); while(joseph_ipnc_param.joseph_ipnc_network_attr.joseph_ipnc_led_glitter_close == 1) { set_status_to_board(set_led_status_buf); pthread_count_second(2); set_status_to_board("00");//close the led pthread_count_second(2); joseph_ipnc_param.joseph_ipnc_network_attr.joseph_ipnc_led_glitter_close = read_user_file("joseph_ipnc_led_glitter_close"); //i_temp++; } //i_temp = 0; } if(glitter_type == 2) { strcpy(set_led_status_buf,led_status); while(joseph_ipnc_param.joseph_ipnc_network_attr.joseph_ipnc_led_glitter_close == 1) { set_status_to_board(set_led_status_buf); pthread_count_second(1); set_status_to_board("00");//close the led pthread_count_second(1); //i_temp++; joseph_ipnc_param.joseph_ipnc_network_attr.joseph_ipnc_led_glitter_close = read_user_file("joseph_ipnc_led_glitter_close"); } //i_temp = 0; } set_status_to_board(set_led_status_buf); alter_ipnc_param("joseph_ipnc_led_glitter_close","0"); return 0; }
相关文章推荐
- 关于ios使用线程导致程序不规律的闪退问题解决
- 误删除系统libselinux.SO.1,导致系统命令基本上都不能使用--附解决问题的整个过程
- sleep,usleep可能会导致线程堵塞的问题
- IdHTTP.post超时导致整个线程停止问题解决
- 进程线程中睡眠函数(sleep)被信号中断后失效,处理方式总结
- 面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用就可以了;面向对象是把构成问题事务分解成各个对象,建立对象的目的不是为了完成一个步骤,而是为了描叙某个事物在整个解决问题的步骤中的行为(转)
- 有关td使用colspan属性后导致td不能充满整个tr的问题解决方法
- Matlab使用xlsread, xlswrite函数导致excel进程无法终止的问题
- curl使用curl_easy_perform导致线程或者进程卡死解决办法
- 【python学习】编码时写路径使用后斜杠导致的unicode error问题解决办法
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- 使用复制存储过程执行解决“事务复制中的表大量更新导致无法及时同步”的问题
- 碰上usleep导致线程堵塞的问题
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- 为什么可能导致睡眠的函数都不能在中断上下文中使用呢?
- 使用复制存储过程执行解决“事务复制中的表大量更新导致无法及时同步”的问题 (转)
- c#中使用多线程访问winform中控件的若干问题 解决线程间操作无效: 从不是创建控件的线程访问它
- 使用PrintWriter对象导致Struts国际化化失败问题的解决及分析
- 使用nhmicro的micro-datasource嵌入式解决微服务架构分布式事务问题
- MySQL中使用group_concat()函数数据字符过长报错的问题解决方法