MCPcopy Create free account
hub / github.com/buke/quickjs-go / js_os_poll_internal

Function js_os_poll_internal

deps/quickjs/quickjs-libc.c:2740–2815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2738
2739#if defined(_WIN32)
2740static int js_os_poll_internal(JSContext *ctx, int timeout_ms, int flags)
2741{
2742 JSRuntime *rt = JS_GetRuntime(ctx);
2743 JSThreadState *ts = js_get_thread_state(rt);
2744 int min_delay, count;
2745 JSOSRWHandler *rh;
2746 struct list_head *el;
2747 HANDLE handles[MAXIMUM_WAIT_OBJECTS]; // 64
2748
2749 /* XXX: handle signals if useful */
2750
2751 min_delay = timeout_ms;
2752
2753 if (flags & JS_OS_POLL_RUN_TIMERS) {
2754 if (js_os_run_timers(rt, ctx, ts, &min_delay))
2755 return -1;
2756 if (min_delay == 0)
2757 return 0; // expired timer
2758 if (min_delay < 0)
2759 if (list_empty(&ts->os_rw_handlers) && list_empty(&ts->port_list))
2760 return -1; /* no more events */
2761 }
2762
2763 count = 0;
2764 list_for_each(el, &ts->os_rw_handlers) {
2765 rh = list_entry(el, JSOSRWHandler, link);
2766 if (rh->fd == 0 && !JS_IsNull(rh->rw_func[0]))
2767 handles[count++] = (HANDLE)_get_osfhandle(rh->fd); // stdin
2768 if (count == (int)countof(handles))
2769 break;
2770 }
2771
2772 if (flags & JS_OS_POLL_WORKERS) {
2773 list_for_each(el, &ts->port_list) {
2774 JSWorkerMessageHandler *port = list_entry(el, JSWorkerMessageHandler, link);
2775 if (JS_IsNull(port->on_message_func))
2776 continue;
2777 handles[count++] = port->recv_pipe->waker.handle;
2778 if (count == (int)countof(handles))
2779 break;
2780 }
2781 }
2782
2783 if (count > 0) {
2784 DWORD ret, timeout = INFINITE;
2785 if (min_delay != -1)
2786 timeout = min_delay;
2787 ret = WaitForMultipleObjects(count, handles, FALSE, timeout);
2788 if (ret < (DWORD)count) {
2789 list_for_each(el, &ts->os_rw_handlers) {
2790 rh = list_entry(el, JSOSRWHandler, link);
2791 if (rh->fd == 0 && !JS_IsNull(rh->rw_func[0])) {
2792 return call_handler(ctx, rh->rw_func[0]);
2793 /* must stop because the list may have been modified */
2794 }
2795 }
2796
2797 if (flags & JS_OS_POLL_WORKERS) {

Callers 2

js_os_pollFunction · 0.85
js_std_poll_ioFunction · 0.85

Calls 7

js_get_thread_stateFunction · 0.85
js_os_run_timersFunction · 0.85
list_emptyFunction · 0.85
JS_IsNullFunction · 0.85
call_handlerFunction · 0.85
handle_posted_messageFunction · 0.85
find_rhFunction · 0.85

Tested by

no test coverage detected