diff --git a/HISTORY b/HISTORY index a9d255c..f0755d8 100644 --- a/HISTORY +++ b/HISTORY @@ -1,10 +1,11 @@ -Version 5.03 2014-08-11 +Version 5.03 2014-08-10 * network send and recv retry when error EINTR happen * support mac OS Darwin * use newest logger from libfastcommon * patches by liangry@ucweb.com * bug fixed: can't sync large files cause by v5.02 + * use newest ioevent_loop from libfastcommon Version 5.02 2014-07-20 * corect README spell mistake diff --git a/common/fast_task_queue.c b/common/fast_task_queue.c index c01b3da..2319fc3 100644 --- a/common/fast_task_queue.c +++ b/common/fast_task_queue.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "fast_task_queue.h" #include "logger.h" #include "shared_func.h" diff --git a/common/fast_task_queue.h b/common/fast_task_queue.h index 695ee25..06a873e 100644 --- a/common/fast_task_queue.h +++ b/common/fast_task_queue.h @@ -19,10 +19,12 @@ #include "ioevent.h" #include "fast_timer.h" +struct nio_thread_data; struct fast_task_info; -typedef int (*TaskFinishCallBack) (struct fast_task_info *pTask); -typedef void (*TaskCleanUpCallBack) (struct fast_task_info *pTask); +typedef int (*ThreadLoopCallback) (struct nio_thread_data *pThreadData); +typedef int (*TaskFinishCallback) (struct fast_task_info *pTask); +typedef void (*TaskCleanUpCallback) (struct fast_task_info *pTask); typedef void (*IOEventCallback) (int sock, short event, void *arg); @@ -37,8 +39,10 @@ struct nio_thread_data { struct ioevent_puller ev_puller; struct fast_timer timer; - int pipe_fds[2]; + int pipe_fds[2]; struct fast_task_info *deleted_list; + ThreadLoopCallback thread_loop_callback; + void *arg; //extra argument pointer }; struct fast_task_info @@ -50,8 +54,8 @@ struct fast_task_info int size; //alloc size int length; //data length int offset; //current offset - int req_count; //request count - TaskFinishCallBack finish_callback; + int64_t req_count; //request count + TaskFinishCallback finish_callback; struct nio_thread_data *thread_data; struct fast_task_info *next; }; diff --git a/common/ioevent_loop.c b/common/ioevent_loop.c index f2e2938..11b0755 100644 --- a/common/ioevent_loop.c +++ b/common/ioevent_loop.c @@ -38,7 +38,7 @@ static void deal_timeouts(FastTimerEntry *head) } int ioevent_loop(struct nio_thread_data *pThreadData, - IOEventCallback recv_notify_callback, TaskCleanUpCallBack + IOEventCallback recv_notify_callback, TaskCleanUpCallback clean_up_callback, volatile bool *continue_flag) { int result; @@ -109,6 +109,10 @@ int ioevent_loop(struct nio_thread_data *pThreadData, deal_timeouts(&head); } } + + if (pThreadData->thread_loop_callback != NULL) { + pThreadData->thread_loop_callback(pThreadData); + } } return 0; diff --git a/common/ioevent_loop.h b/common/ioevent_loop.h index dbed3a1..f4ea160 100644 --- a/common/ioevent_loop.h +++ b/common/ioevent_loop.h @@ -8,7 +8,7 @@ extern "C" { #endif int ioevent_loop(struct nio_thread_data *pThreadData, - IOEventCallback recv_notify_callback, TaskCleanUpCallBack + IOEventCallback recv_notify_callback, TaskCleanUpCallback clean_up_callback, volatile bool *continue_flag); int ioevent_set(struct fast_task_info *pTask, struct nio_thread_data *pThread, diff --git a/tracker/tracker_service.c b/tracker/tracker_service.c index 4d4d7ff..02f5032 100644 --- a/tracker/tracker_service.c +++ b/tracker/tracker_service.c @@ -54,6 +54,7 @@ static void tracker_find_max_free_space_group(); int tracker_service_init() { int result; + int bytes; struct nio_thread_data *pThreadData; struct nio_thread_data *pDataEnd; pthread_t tid; @@ -81,17 +82,16 @@ int tracker_service_init() { return result; } - - g_thread_data = (struct nio_thread_data *)malloc(sizeof( \ - struct nio_thread_data) * g_work_threads); + bytes = sizeof(struct nio_thread_data) * g_work_threads; + g_thread_data = (struct nio_thread_data *)malloc(bytes ); if (g_thread_data == NULL) { logError("file: "__FILE__", line: %d, " \ "malloc %d bytes fail, errno: %d, error info: %s", \ - __LINE__, (int)sizeof(struct nio_thread_data) * \ - g_work_threads, errno, STRERROR(errno)); + __LINE__, bytes, errno, STRERROR(errno)); return errno != 0 ? errno : ENOMEM; } + memset(g_thread_data, 0, bytes); g_tracker_thread_count = 0; pDataEnd = g_thread_data + g_work_threads;