void acl_fiber_kill(ACL_FIBER *fiber) { ACL_FIBER *curr = __thread_fiber->running; if (fiber == NULL) { acl_msg_error("%s(%d), %s: fiber NULL", __FILE__, __LINE__, __FUNCTION__); return; } if (curr == NULL) { acl_msg_error("%s(%d), %s: current fiber NULL", __FILE__, __LINE__, __FUNCTION__); return; } fiber->flag |= FIBER_F_KILLED; if (fiber == curr) { acl_msg_error("%s(%d), %s: fiber-%d kill itself disable!", __FILE__, __LINE__, __FUNCTION__, acl_fiber_id(fiber)); return; } acl_ring_detach(&curr->me); acl_ring_detach(&fiber->me); acl_fiber_ready(fiber); acl_fiber_yield(); }
static void echo_client(int fd) { char buf[8192]; int ret, i; const char *str = "hello world\r\n"; for (i = 0; i < __max_loop; i++) { if (write(fd, str, strlen(str)) <= 0) { printf("write error: %s\r\n", strerror(errno)); break; } if (!__read_data) { __total_count++; if (i % 10000 == 0) printf("fiber-%d: total %lld, curr %d\r\n", acl_fiber_self(), __total_count, i); if (__total_count % 10000 == 0) acl_fiber_yield(); continue; } ret = read(fd, buf, sizeof(buf)); if (ret <= 0) { printf("read error: %s\r\n", strerror(errno)); break; } __total_count++; } close(fd); }
void fiber::yield(void) { (void) acl_fiber_yield(); }