嵌入式 解决线程使用sleep或usleep等函数导致整个进程睡眠的问题
来源:互联网 发布:中国 气候 变迁 知乎 编辑:程序博客网 时间:2024/05/03 08:08
解决线程使用sleep或usleep等函数导致整个进程睡眠的问题:
获取当前时间的秒数
/*author : kjtime : 2013-12-06 21:36instruction: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 : kjtime : 2013-12-06 21:42function :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 : kjtime : 2013-12-01instrucion:glitter :0 - direct set to board1 - speed slow2 - 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;}
- 嵌入式 解决线程使用sleep或usleep等函数导致整个进程睡眠的问题
- linux 睡眠函数——sleep(),usleep()
- linux 睡眠函数——sleep(),usleep()
- 碰上usleep导致线程堵塞的问题
- 碰上usleep导致线程堵塞的问题
- 关于Linux的线程休眠函数sleep/usleep/nanosleep/select
- linux中sleep()和usleep()函数的使用和区别
- IOS usleep函数导致线程阻塞
- linux编程中while里面使用usleep/sleep异常的情况的解决
- 进程线程中睡眠函数(sleep)被信号中断后失效,处理方式总结
- PHP sleep() 函数, usleep() 函数
- PHP sleep() 函数, usleep() 函数
- SIGINT信号导致的usleep无效问题
- SIGINT信号导致的usleep无效问题
- 十九、Linux系统编程-信号(六)三种不同精度的睡眠sleep、usleep、nanosleep
- java中的睡眠--线程的Sleep中断
- 多线程 sleep usleep 阻塞问题
- linux 的sleep()、usleep()、nanosleep()函数的区别
- PHPCMS广告模块详细分析——广告的生成
- mysql database中常用操作
- C#基础实践:引用与值类型
- Java程序计算对象所占内存的大小的方法
- 计数排序(Countsort)之Java实现
- 嵌入式 解决线程使用sleep或usleep等函数导致整个进程睡眠的问题
- corbarclient支持spring3.X
- PCB中的地线
- LeetCode Container With Most Water
- SQL Server中 DateDiff计算时间差
- 【mysql】表的创建以及基本操作
- BeagleBone Black 高清照片两张
- EFI安装64位系统
- HTML5 API --- 页面可见性改变(visibilitychange)事件