diff options
| author | ruki <[email protected]> | 2019-12-12 22:52:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-12-12 11:12:55 +0800 |
| commit | bfbdaf039adfd2c145f17b256772d52cb97c8d19 (patch) | |
| tree | 6b595bf216e4e853939ecb522fd612582d683884 /core | |
| parent | bffe4246267d83833234ec0a3819dd5c060687c2 (diff) | |
improve poller
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/xmake/io/poller_wait.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/core/src/xmake/io/poller_wait.c b/core/src/xmake/io/poller_wait.c index 2589025c2..eceb44cbf 100644 --- a/core/src/xmake/io/poller_wait.c +++ b/core/src/xmake/io/poller_wait.c @@ -32,6 +32,13 @@ #include "poller.h" /* ////////////////////////////////////////////////////////////////////////////////////// + * globals + */ + +// we need only one global poller and main thread, so it is thread-safe. +static tb_int_t g_events_count = 0; + +/* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, tb_socket_ref_t sock, tb_size_t events, tb_cpointer_t priv) @@ -46,6 +53,7 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, tb_socket_ref_t sock lua_rawseti(lua, -2, 1); lua_pushinteger(lua, (tb_int_t)events); lua_rawseti(lua, -2, 2); + lua_rawseti(lua, -2, ++g_events_count); } /* ////////////////////////////////////////////////////////////////////////////////////// @@ -63,10 +71,10 @@ tb_int_t xm_io_poller_wait(lua_State* lua) // wait it lua_newtable(lua); + g_events_count = 0; tb_long_t count = tb_poller_wait(xm_io_poller(), xm_io_poller_event, timeout); if (count > 0) { - lua_rawseti(lua, -2, (tb_int_t)count); lua_pushinteger(lua, (tb_int_t)count); return 2; } |
