add waiting_queue for Linux eventfd notify

pull/37/head
YuQing 2020-03-08 16:12:54 +08:00
parent 6b528f123f
commit b88d5b03fe
6 changed files with 110 additions and 8 deletions

View File

@ -1,5 +1,5 @@
Version 1.44 2020-03-06
Version 1.44 2020-03-08
* add test file src/tests/test_pthread_lock.c
* add uniq_skiplist.[hc]
* add function split_string_ex
@ -16,6 +16,7 @@ Version 1.44 2020-03-06
* shared_func.[hc]: add function getFileSize
* char_converter.[hc]: add function fast_char_unescape
* struct fast_task_info add ctx pointer for libserverframe nio
* struct thread_data add waiting_queue for Linux eventfd notify
Version 1.43 2019-12-25
* replace function call system to getExecResult,

View File

@ -30,6 +30,8 @@ typedef void (*TaskCleanUpCallback) (struct fast_task_info *pTask);
typedef void (*IOEventCallback) (int sock, short event, void *arg);
struct fast_task_info;
typedef struct ioevent_entry
{
int fd;
@ -41,10 +43,15 @@ struct nio_thread_data
{
struct ioevent_puller ev_puller;
struct fast_timer timer;
int pipe_fds[2];
int pipe_fds[2]; //for notify
struct fast_task_info *deleted_list;
ThreadLoopCallback thread_loop_callback;
void *arg; //extra argument pointer
struct {
struct fast_task_info *head;
struct fast_task_info *tail;
pthread_mutex_t lock;
} waiting_queue;
};
struct fast_task_info

View File

@ -7,8 +7,8 @@ static void deal_ioevents(IOEventPoller *ioevent)
int event;
IOEventEntry *pEntry;
for (ioevent->iterator.index=0; ioevent->iterator.index < ioevent->iterator.
count; ioevent->iterator.index++)
for (ioevent->iterator.index=0; ioevent->iterator.index < ioevent->
iterator.count; ioevent->iterator.index++)
{
event = IOEVENT_GET_EVENTS(ioevent, ioevent->iterator.index);
pEntry = (IOEventEntry *)IOEVENT_GET_DATA(ioevent,
@ -18,7 +18,8 @@ static void deal_ioevents(IOEventPoller *ioevent)
}
else {
logDebug("file: "__FILE__", line: %d, "
"ignore iovent : %d, index: %d", __LINE__, event, ioevent->iterator.index);
"ignore iovent : %d, index: %d",
__LINE__, event, ioevent->iterator.index);
}
}
}
@ -100,6 +101,7 @@ int ioevent_loop(struct nio_thread_data *pThreadData,
memset(&ev_notify, 0, sizeof(ev_notify));
ev_notify.fd = pThreadData->pipe_fds[0];
ev_notify.callback = recv_notify_callback;
ev_notify.timer.data = pThreadData;
if (ioevent_attach(&pThreadData->ev_puller,
pThreadData->pipe_fds[0], IOEVENT_READ,
&ev_notify) != 0)
@ -116,7 +118,8 @@ int ioevent_loop(struct nio_thread_data *pThreadData,
last_check_time = g_current_time;
while (*continue_flag)
{
pThreadData->ev_puller.iterator.count = ioevent_poll(&pThreadData->ev_puller);
pThreadData->ev_puller.iterator.count = ioevent_poll(
&pThreadData->ev_puller);
if (pThreadData->ev_puller.iterator.count > 0)
{
deal_ioevents(&pThreadData->ev_puller);

View File

@ -8,7 +8,7 @@
#include "fastcommon/logger.h"
#include "fastcommon/shared_func.h"
#define LOOP (200 * 1000)
#define LOOP (2000 * 1000)
int main(int argc, char *argv[])
{

View File

@ -36,7 +36,7 @@ int main(int argc, char *argv[])
start_time = get_current_time_ms();
sum = 0;
for (k=1; k<=LOOP_COUNT; k++) {
__sync_synchronize();
//__sync_synchronize();
//barrier();
__sync_add_and_fetch(&sum, k);
}

View File

@ -3,6 +3,7 @@
#include <string.h>
#include <math.h>
#include <time.h>
#include <fcntl.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/time.h>
@ -11,6 +12,54 @@
#include "fastcommon/shared_func.h"
#include "fastcommon/server_id_func.h"
static int test_open_lseek(const char *filename)
{
int result;
int fd;
int bytes;
char buff[1024];
int64_t offset = 1024 * 1024;
fd = open(filename, O_RDONLY);
if (fd < 0) {
result = errno != 0 ? errno : EACCES;
logError("file: "__FILE__", line: %d, "
"open file \"%s\" fail, "
"errno: %d, error info: %s",
__LINE__, filename,
result, STRERROR(result));
return result;
}
if (offset > 0) {
if (lseek(fd, offset, SEEK_SET) < 0) {
result = errno != 0 ? errno : EACCES;
logError("file: "__FILE__", line: %d, "
"lseek file \"%s\" fail, offset: %"PRId64", "
"errno: %d, error info: %s", __LINE__,
filename, offset,
result, STRERROR(result));
return result;
} else {
logInfo("lseek %"PRId64" successfully.", offset);
}
}
if ((bytes=read(fd, buff, sizeof(buff))) < 0) {
result = errno != 0 ? errno : EACCES;
logError("file: "__FILE__", line: %d, "
"read file \"%s\" fail, offset: %"PRId64", "
"errno: %d, error info: %s", __LINE__,
filename, offset, result, STRERROR(result));
return result;
}
printf("read bytes: %d\n", bytes);
close(fd);
return 0;
}
int main(int argc, char *argv[])
{
int result;
@ -26,6 +75,48 @@ int main(int argc, char *argv[])
}
log_init();
{
union {
int64_t flags;
struct {
union {
int flags: 4;
struct {
bool ns: 1; //namespace
bool pt: 1; //path
bool hc: 1; //hash code
};
} path_info;
bool user_data : 1;
bool extra_data: 1;
bool mode : 1;
bool ctime: 1;
bool mtime: 1;
bool size : 1;
};
} options;
char *endptr;
int64_t n;
endptr = NULL;
n = strtoll(argv[1], &endptr, 10);
printf("sizeof(mode_t): %d\n", (int)sizeof(mode_t));
printf("sizeof(options): %d\n", (int)sizeof(options));
options.path_info.ns = options.path_info.pt = options.path_info.hc = 1;
printf("union flags: %d\n", options.path_info.flags);
printf("n: %"PRId64", endptr: %s(%d)\n", n, endptr, (int)strlen(endptr));
n = snprintf(NULL, 0, "%"PRId64, n);
printf("expect len: %d\n", (int)n);
test_open_lseek(config_filename);
return 1;
}
if ((result=fc_server_load_from_file_ex(&ctx, config_filename,
default_port, min_hosts_each_group,
share_between_groups)) != 0)