This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/13537 ) Change subject: select: Make file descriptor lists per-thread ...................................................................... select: Make file descriptor lists per-thread In a multi-threaded environemnt, it's likely that each thread will have its own, distinct set of file descriptors that it wants to watch. Hence, let's make the osmo_fd_* functions configure not one global list of file descriptors, but a thread-local list of file descriptors. Change-Id: I5082ed3e500ad1a7516e1785bc57e008da2fac9a --- M include/osmocom/core/select.h M src/select.c 2 files changed, 18 insertions(+), 3 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved fixeria: Looks good to me, but someone else must approve pespin: Looks good to me, but someone else must approve diff --git a/include/osmocom/core/select.h b/include/osmocom/core/select.h index a200b6f..92904e2 100644 --- a/include/osmocom/core/select.h +++ b/include/osmocom/core/select.h @@ -52,6 +52,7 @@ void osmo_fd_close(struct osmo_fd *fd); int osmo_select_main(int polling); int osmo_select_main_ctx(int polling); +void osmo_select_init(void); struct osmo_fd *osmo_fd_get_by_fd(int fd); diff --git a/src/select.c b/src/select.c index 394a59d..b997122 100644 --- a/src/select.c +++ b/src/select.c @@ -50,9 +50,11 @@ * * \file select.c */ -static int maxfd = 0; -static LLIST_HEAD(osmo_fds); -static int unregistered_count; +/* keep a set of file descriptors per-thread, so that each thread can have its own + * distinct set of file descriptors to interact with */ +static __thread int maxfd = 0; +static __thread struct llist_head osmo_fds; /* TLS cannot use LLIST_HEAD() */ +static __thread int unregistered_count; /*! Set up an osmo-fd. Will not register it. * \param[inout] ofd Osmo FD to be set-up @@ -307,6 +309,18 @@ return NULL; } +/*! initialize the osmocom select abstraction for the current thread */ +void osmo_select_init(void) +{ + INIT_LLIST_HEAD(&osmo_fds); +} + +/* ensure main thread always has pre-initialized osmo_fds */ +static __attribute__((constructor)) void on_dso_load_select(void) +{ + osmo_select_init(); +} + #ifdef HAVE_SYS_TIMERFD_H #include <sys/timerfd.h> -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/13537 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I5082ed3e500ad1a7516e1785bc57e008da2fac9a Gerrit-Change-Number: 13537 Gerrit-PatchSet: 5 Gerrit-Owner: laforge <laforge at osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <axilirator at gmail.com> Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-Reviewer: pespin <pespin at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191107/d2f034dc/attachment.htm>