mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 11:57:43 +08:00
optimize and test fiber_cond
This commit is contained in:
parent
24a553e66b
commit
96b6a74fbe
@ -532,7 +532,8 @@ void fiber_file_set(FILE_EVENT *fe)
|
||||
}
|
||||
|
||||
if (__thread_fiber->events[fe->fd] != NULL) {
|
||||
printf("%s(%d): exist fd=%d\r\n", __FUNCTION__, __LINE__, fe->fd);
|
||||
printf("%s(%d): exist fd=%d, old=%p new=%p\r\n", __FUNCTION__,
|
||||
__LINE__, fe->fd, __thread_fiber->events[fe->fd], fe);
|
||||
abort();
|
||||
}
|
||||
|
||||
@ -692,9 +693,16 @@ void fiber_file_close(FILE_EVENT *fe)
|
||||
FILE_EVENT *fiber_file_cache_get(socket_t fd)
|
||||
{
|
||||
FILE_EVENT *fe;
|
||||
int exist = 0;
|
||||
|
||||
fiber_io_check();
|
||||
fe = (FILE_EVENT*) array_pop_back(__thread_fiber->cache);
|
||||
|
||||
fe = fiber_file_get(fd);
|
||||
if (fe == NULL) {
|
||||
fe = (FILE_EVENT*) array_pop_back(__thread_fiber->cache);
|
||||
} else { // Why? the fe wasn't removed by fiber_file_cache_put ?
|
||||
exist = 1;
|
||||
}
|
||||
if (fe == NULL) {
|
||||
fe = file_event_alloc(fd);
|
||||
} else {
|
||||
@ -706,7 +714,9 @@ FILE_EVENT *fiber_file_cache_get(socket_t fd)
|
||||
fe->mask |= EVENT_DIRECT;
|
||||
}
|
||||
#endif
|
||||
fiber_file_set(fe);
|
||||
if (!exist) {
|
||||
fiber_file_set(fe);
|
||||
}
|
||||
return fe;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ struct SYNC_TIMER {
|
||||
MBOX *box;
|
||||
int stop;
|
||||
TIMER_CACHE *waiters;
|
||||
unsigned long tid;
|
||||
};
|
||||
|
||||
static SYNC_TIMER *sync_timer_new(void)
|
||||
@ -23,6 +24,7 @@ static SYNC_TIMER *sync_timer_new(void)
|
||||
pthread_mutex_init(&timer->lock, NULL);
|
||||
timer->box = mbox_create(MBOX_T_MPSC);
|
||||
timer->waiters = timer_cache_create();
|
||||
timer->tid = __pthread_self();
|
||||
|
||||
out = mbox_out(timer->box);
|
||||
assert(out != INVALID_SOCKET);
|
||||
@ -204,12 +206,24 @@ void sync_timer_wakeup(SYNC_TIMER *timer, SYNC_OBJ *obj)
|
||||
|
||||
if (var_hook_sys_api) {
|
||||
socket_t out = mbox_out(timer->box);
|
||||
FILE_EVENT *fe = fiber_file_cache_get(out);
|
||||
FILE_EVENT *fe;
|
||||
int same_thread;
|
||||
|
||||
if (__pthread_self() == timer->tid) {
|
||||
fe = fiber_file_open_write(out);
|
||||
same_thread = 1;
|
||||
} else {
|
||||
fe = fiber_file_cache_get(out);
|
||||
same_thread = 0;
|
||||
}
|
||||
|
||||
fe->mask |= EVENT_SYSIO;
|
||||
|
||||
mbox_send(timer->box, msg);
|
||||
fiber_file_cache_put(fe);
|
||||
|
||||
if (!same_thread) {
|
||||
fiber_file_cache_put(fe);
|
||||
}
|
||||
} else {
|
||||
mbox_send(timer->box, msg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user