1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +01:00
libwebsockets/lib/event-libs/common.c
Andy Green 3c12fd72e8 unify us sorted waits
There are quite a few linked-lists of things that want events after
some period.  This introduces a type binding an lws_dll2 for the
list and a lws_usec_t for the duration.

The wsi timeouts, the hrtimer and the sequencer timeouts are converted
to use these, also in the common event wait calculation.
2019-08-08 22:39:47 +01:00

48 lines
1.3 KiB
C

/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010-2018 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include "core/private.h"
lws_usec_t
__lws_event_service_get_earliest_wake(struct lws_context_per_thread *pt,
lws_usec_t usnow)
{
lws_usec_t t, us = 0;
char seen = 0;
t = __lws_wsitimeout_service(pt, usnow);
if (t) {
us = t;
seen = 1;
}
t = __lws_hrtimer_service(pt, usnow);
if (t && (!seen || t < us)) {
us = t;
seen = 1;
}
t = __lws_seq_timeout_check(pt, usnow);
if (t && (!seen || t < us)) {
us = t;
seen = 1;
}
return us;
}