diff --git a/HISTORY b/HISTORY index 890799f..d495ac6 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.44 2020-09-08 +Version 1.44 2020-09-12 * add test file src/tests/test_pthread_lock.c * add uniq_skiplist.[hc] * add function split_string_ex diff --git a/src/sched_thread.c b/src/sched_thread.c index 154b613..c6546da 100644 --- a/src/sched_thread.c +++ b/src/sched_thread.c @@ -467,13 +467,13 @@ static void *sched_thread_entrance(void *args) } else { - usleep(1*1000); + fc_sleep_ms(1); for (i=1; !pCurrent->thread_running && i<100; i++) { logDebug("file: "__FILE__", line: %d, " "task_id: %d, waiting thread ready, count %d", __LINE__, pCurrent->id, i); - usleep(1*1000); + fc_sleep_ms(1); } } } @@ -642,7 +642,7 @@ int sched_add_entries(const ScheduleArray *pScheduleArray) "schedule_flag: %d ...", __LINE__, __sync_add_and_fetch(&g_schedule_flag, 0)); } - else if (++i == 10) + else if (++i == 300) { logError("file: "__FILE__", line: %d, " "waiting for schedule array ready timeout, " @@ -650,7 +650,7 @@ int sched_add_entries(const ScheduleArray *pScheduleArray) __sync_add_and_fetch(&g_schedule_flag, 0), i); break; } - sleep(1); + fc_sleep_ms(10); } } @@ -908,13 +908,13 @@ static void deal_timeout_tasks(ScheduleContext *pContext, FastTimerEntry *head) } else { - usleep(1*1000); + fc_sleep_ms(1); for (i=1; !task->thread_running && i<100; i++) { logDebug("file: "__FILE__", line: %d, " "task args: %p, waiting thread ready, count %d", __LINE__, task->func_args, i); - usleep(1*1000); + fc_sleep_ms(1); } } } diff --git a/src/shared_func.h b/src/shared_func.h index 263f49a..ebccb7c 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -987,6 +988,24 @@ int fc_get_last_line(const char *filename, char *buff, bool fc_path_contains(const string_t *path, const string_t *needle, int *result); + +/** sleep in milliseconds + * parameters: + * milliseconds: milliseconds to sleep + * return: 0 for success, != 0 for fail +*/ +static inline int fc_sleep_ms(const int milliseconds) +{ + struct timespec ts; + ts.tv_sec = milliseconds / 1000; + ts.tv_nsec = (milliseconds % 1000) * (1000 * 1000); + if (nanosleep(&ts, NULL) == 0) { + return 0; + } else { + return errno != 0 ? errno : EINVAL; + } +} + #ifdef __cplusplus } #endif diff --git a/src/tests/test_mblock.c b/src/tests/test_mblock.c index 9826ecf..c511e30 100644 --- a/src/tests/test_mblock.c +++ b/src/tests/test_mblock.c @@ -165,10 +165,8 @@ int main(int argc, char *argv[]) fast_mblock_manager_init(); - fast_mblock_init_ex2(&mblock1, "mblock1", 1024, 128, NULL, NULL, - false, NULL, NULL, NULL); - fast_mblock_init_ex2(&mblock2, "mblock2", 1024, 100, NULL, NULL, - false, NULL, NULL, NULL); + fast_mblock_init_ex1(&mblock1, "mblock1", 1024, 128, 0, NULL, NULL, false); + fast_mblock_init_ex1(&mblock2, "mblock2", 1024, 100, 0, NULL, NULL, false); count = 2048; objs = (struct my_struct *)malloc(sizeof(struct my_struct) * count); diff --git a/src/tests/test_thread_pool.c b/src/tests/test_thread_pool.c index 9e3384f..e15581f 100644 --- a/src/tests/test_thread_pool.c +++ b/src/tests/test_thread_pool.c @@ -19,7 +19,7 @@ static volatile int64_t total = 0; #define TASK_COUNT 10 -void thread2_func(void *args) +void thread2_func(void *args, void *thread_data) { int i; for (i=0; i