nio_thread_data support thread notify

pull/37/head
YuQing 2020-03-10 21:15:37 +08:00
parent f9881d96b7
commit 3d0956d302
5 changed files with 42 additions and 3 deletions

View File

@ -1,5 +1,5 @@
Version 1.44 2020-03-09
Version 1.44 2020-03-10
* add test file src/tests/test_pthread_lock.c
* add uniq_skiplist.[hc]
* add function split_string_ex
@ -18,6 +18,7 @@ Version 1.44 2020-03-09
* struct fast_task_info add ctx pointer for libserverframe nio
* struct thread_data add waiting_queue for Linux eventfd notify
* struct fast_task_info add canceled field for complicated thread model
* nio_thread_data support thread notify
Version 1.43 2019-12-25
* replace function call system to getExecResult,

View File

@ -19,6 +19,9 @@
#include "ioevent.h"
#include "fast_timer.h"
#define FC_NOTIFY_READ_FD(tdata) (tdata)->pipe_fds[0]
#define FC_NOTIFY_WRITE_FD(tdata) (tdata)->pipe_fds[1]
#define ALIGNED_TASK_INFO_SIZE MEM_ALIGN(sizeof(struct fast_task_info))
struct nio_thread_data;
@ -51,7 +54,12 @@ struct nio_thread_data
struct fast_task_info *head;
struct fast_task_info *tail;
pthread_mutex_t lock;
} waiting_queue;
} waiting_queue; //task queue
struct {
bool enabled;
volatile int64_t counter;
} notify; //for thread notify
};
struct fast_task_info

View File

@ -152,6 +152,14 @@ int ioevent_loop(struct nio_thread_data *pThreadData,
}
}
if (pThreadData->notify.enabled) {
int64_t n;
if ((n=__sync_fetch_and_add(&pThreadData->notify.counter, 0)) != 0) {
logInfo("file: "__FILE__", line: %d, "
"n ==== %"PRId64, __LINE__, n);
__sync_fetch_and_sub(&pThreadData->notify.counter, n);
}
}
if (pThreadData->thread_loop_callback != NULL) {
pThreadData->thread_loop_callback(pThreadData);
}

View File

@ -35,6 +35,28 @@ static inline void iovent_add_to_deleted_list(struct fast_task_info *task)
task->thread_data->deleted_list = task;
}
static inline int iovent_notify_thread(struct nio_thread_data *thread_data)
{
int64_t n;
int result;
if (__sync_fetch_and_add(&thread_data->notify.counter, 1) == 0)
{
n = 1;
if (write(FC_NOTIFY_WRITE_FD(thread_data), &n, sizeof(n)) != sizeof(n))
{
result = errno != 0 ? errno : EIO;
logError("file: "__FILE__", line: %d, "
"write to fd %d fail, errno: %d, error info: %s",
__LINE__, FC_NOTIFY_WRITE_FD(thread_data),
result, STRERROR(result));
return result;
}
}
return 0;
}
#ifdef __cplusplus
}
#endif

View File

@ -438,7 +438,7 @@ static void *sched_thread_entrance(void *args)
exec_count = 0;
pCurrent = pContext->head;
while (*(pContext->pcontinue_flag) && (pCurrent != NULL \
while (*(pContext->pcontinue_flag) && (pCurrent != NULL
&& pCurrent->next_call_time <= g_current_time))
{
//logInfo("exec task id: %d", pCurrent->id);