From 8c3a44218ae5ba62a07d05a909521d1eb79ba740 Mon Sep 17 00:00:00 2001 From: ubuntu14 Date: Fri, 19 Aug 2016 22:31:05 +0800 Subject: [PATCH] fixed some compiling warning. --- lib_acl/src/net/acl_mask_addr.c | 3 ++- lib_acl_cpp/src/master/master_threads.cpp | 3 ++- lib_fiber/README.md | 11 +++++++++++ lib_fiber/c/src/fiber.c | 11 +++++++++-- lib_fiber/c/src/fiber.h | 6 +++++- lib_fiber/cpp/include/fiber/fiber.hpp | 2 +- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib_acl/src/net/acl_mask_addr.c b/lib_acl/src/net/acl_mask_addr.c index 2adaf0a4d..c3dac9828 100644 --- a/lib_acl/src/net/acl_mask_addr.c +++ b/lib_acl/src/net/acl_mask_addr.c @@ -33,7 +33,8 @@ void acl_mask_addr(unsigned char *addr_bytes, /* abs just avoiding gcc6.1 warning */ if (network_bits != 0) - *p++ &= (unsigned char) ~0 << abs(CHAR_BIT - network_bits); + *p++ &= (unsigned char) ~0 << (unsigned) + (CHAR_BIT - network_bits); while (p < addr_bytes + addr_byte_count) *p++ = 0; diff --git a/lib_acl_cpp/src/master/master_threads.cpp b/lib_acl_cpp/src/master/master_threads.cpp index 42e74f40a..6d9038c6e 100644 --- a/lib_acl_cpp/src/master/master_threads.cpp +++ b/lib_acl_cpp/src/master/master_threads.cpp @@ -67,7 +67,8 @@ bool master_threads::run_alone(const char* addrs, const char* path /* = NULL */, int argc = 0; const char *argv[9]; - argv[argc++] = acl_process_path(); + const char* proc = acl_process_path(); + argv[argc++] = proc ? proc : "demo"; argv[argc++] = "-L"; argv[argc++] = addrs; if (path && *path) diff --git a/lib_fiber/README.md b/lib_fiber/README.md index b83d379b6..bbc8008f1 100644 --- a/lib_fiber/README.md +++ b/lib_fiber/README.md @@ -147,6 +147,8 @@ static void fiber_accept(ACL_FIBER *fiber acl_unused, void *ctx acl_unused) __nconnect++; printf("accept one, fd: %d\r\n", cfd); + + // 将接收到的客户端连接传递给新创建的协程 acl_fiber_create(echo_client, fd, __stack_size); } @@ -203,11 +205,20 @@ int main(int argc, char *argv[]) acl_msg_stdout_enable(1); printf("%s: call fiber_creater\r\n", __FUNCTION__); + + // 创建监听协程 acl_fiber_create(fiber_accept, NULL, 32768); printf("call fiber_schedule\r\n"); + + // 开始协程调度过程 acl_fiber_schedule(); return 0; } ``` + +参考: +1、网络协程编程:http://zsxxsz.iteye.com/blog/2312043 +2、使用协程编写高并发网络服务:http://zsxxsz.iteye.com/blog/2309654 +3、使用协程方式编写高并发的WEB服务:http://zsxxsz.iteye.com/blog/2309665 diff --git a/lib_fiber/c/src/fiber.c b/lib_fiber/c/src/fiber.c index e44707aaf..36892408d 100644 --- a/lib_fiber/c/src/fiber.c +++ b/lib_fiber/c/src/fiber.c @@ -36,6 +36,10 @@ __thread int acl_var_hook_sys_api = 0; static acl_pthread_key_t __fiber_key; +/* forward declare */ +static ACL_FIBER *fiber_alloc(void (*fn)(ACL_FIBER *, void *), + void *arg, size_t size); + void acl_fiber_hook_api(int onoff) { acl_var_hook_sys_api = onoff; @@ -258,7 +262,7 @@ static void fiber_swap(ACL_FIBER *from, ACL_FIBER *to) /* use setcontext() for the initial jump, as it allows us to set up * a stack, but continue with longjmp() as it's much faster. */ - if (SETJMP(from->jbuf) == 0) { + if (SETJMP(from->env) == 0) { /* context just be used once for set up a stack, which will * be freed in fiber_start. The context in __thread_fiber * was set NULL. @@ -266,7 +270,7 @@ static void fiber_swap(ACL_FIBER *from, ACL_FIBER *to) if (to->context != NULL) setcontext(to->context); else - LONGJMP(to->jbuf); + LONGJMP(to->env); } #else if (swapcontext(from->context, to->context) < 0) @@ -356,6 +360,9 @@ static void fiber_start(unsigned int x, unsigned int y) static void fiber_free(ACL_FIBER *fiber) { +#ifdef USE_VALGRIND + VALGRIND_STACK_DEREGISTER(fiber->vid); +#endif if (fiber->context) acl_myfree(fiber->context); acl_myfree(fiber->buff); diff --git a/lib_fiber/c/src/fiber.h b/lib_fiber/c/src/fiber.h index 1965d661b..dde1de618 100644 --- a/lib_fiber/c/src/fiber.h +++ b/lib_fiber/c/src/fiber.h @@ -34,7 +34,11 @@ struct ACL_FIBER { int nlocal; #ifdef USE_JMP - jmp_buf jbuf; +# if defined(__x86_64__) + unsigned long long env[10]; +# else + sigjmp_buf env; +# endif #endif ucontext_t *context; void (*fn)(ACL_FIBER *, void *); diff --git a/lib_fiber/cpp/include/fiber/fiber.hpp b/lib_fiber/cpp/include/fiber/fiber.hpp index 39fdfb259..faa14e411 100644 --- a/lib_fiber/cpp/include/fiber/fiber.hpp +++ b/lib_fiber/cpp/include/fiber/fiber.hpp @@ -17,7 +17,7 @@ class fiber * 在创建一个协程类后,需要本函数启动协程 * @param stack_size {size_t} 创建的协程对象的栈大小 */ - void start(size_t stack_size = 64000); + void start(size_t stack_size = 320000); /** * 获得本协程对象的 ID 号