Skip to content

Commit

Permalink
fixed some compiling warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
ubuntu14 committed Aug 19, 2016
1 parent 67be4da commit 8c3a442
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib_acl/src/net/acl_mask_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib_acl_cpp/src/master/master_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions lib_fiber/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
11 changes: 9 additions & 2 deletions lib_fiber/c/src/fiber.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -258,15 +262,15 @@ 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.
*/
if (to->context != NULL)
setcontext(to->context);
else
LONGJMP(to->jbuf);
LONGJMP(to->env);
}
#else
if (swapcontext(from->context, to->context) < 0)
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion lib_fiber/c/src/fiber.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
2 changes: 1 addition & 1 deletion lib_fiber/cpp/include/fiber/fiber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 号
Expand Down

0 comments on commit 8c3a442

Please sign in to comment.