add function fc_sleep_ms
parent
6a54076cf5
commit
bc5efd235e
2
HISTORY
2
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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<LOOP_COUNT; i++) {
|
||||
|
|
@ -28,7 +28,7 @@ void thread2_func(void *args)
|
|||
}
|
||||
}
|
||||
|
||||
void thread1_func(void *args)
|
||||
void thread1_func(void *args, void *thread_data)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<LOOP_COUNT; i++) {
|
||||
|
|
@ -37,7 +37,7 @@ void thread1_func(void *args)
|
|||
}
|
||||
}
|
||||
|
||||
void wait_thread_func(void *args)
|
||||
void wait_thread_func(void *args, void *thread_data)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<LOOP_COUNT; i++) {
|
||||
|
|
@ -108,8 +108,9 @@ int main(int argc, char *argv[])
|
|||
g_log_context.log_level = LOG_DEBUG;
|
||||
|
||||
start_time = get_current_time_ms();
|
||||
if ((result=fc_thread_pool_init(&pool, limit, stack_size, max_idle_time,
|
||||
min_idle_count, (bool * volatile)&continue_flag)) != 0)
|
||||
if ((result=fc_thread_pool_init(&pool, "test", limit, stack_size,
|
||||
max_idle_time, min_idle_count,
|
||||
(bool * volatile)&continue_flag)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue