<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/13537">View Change</a></p><div style="white-space:pre-wrap">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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">select: Make file descriptor lists per-thread<br><br>In a multi-threaded environemnt, it's likely that each thread will have<br>its own, distinct set of file descriptors that it wants to watch.<br><br>Hence, let's make the osmo_fd_* functions configure not one global<br>list of file descriptors, but a thread-local list of file descriptors.<br><br>Change-Id: I5082ed3e500ad1a7516e1785bc57e008da2fac9a<br>---<br>M include/osmocom/core/select.h<br>M src/select.c<br>2 files changed, 18 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/core/select.h b/include/osmocom/core/select.h</span><br><span>index a200b6f..92904e2 100644</span><br><span>--- a/include/osmocom/core/select.h</span><br><span>+++ b/include/osmocom/core/select.h</span><br><span>@@ -52,6 +52,7 @@</span><br><span> void osmo_fd_close(struct osmo_fd *fd);</span><br><span> int osmo_select_main(int polling);</span><br><span> int osmo_select_main_ctx(int polling);</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_select_init(void);</span><br><span> </span><br><span> struct osmo_fd *osmo_fd_get_by_fd(int fd);</span><br><span> </span><br><span>diff --git a/src/select.c b/src/select.c</span><br><span>index 394a59d..b997122 100644</span><br><span>--- a/src/select.c</span><br><span>+++ b/src/select.c</span><br><span>@@ -50,9 +50,11 @@</span><br><span>  *</span><br><span>  * \file select.c */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static int maxfd = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-static LLIST_HEAD(osmo_fds);</span><br><span style="color: hsl(0, 100%, 40%);">-static int unregistered_count;</span><br><span style="color: hsl(120, 100%, 40%);">+/* keep a set of file descriptors per-thread, so that each thread can have its own</span><br><span style="color: hsl(120, 100%, 40%);">+ * distinct set of file descriptors to interact with */</span><br><span style="color: hsl(120, 100%, 40%);">+static __thread int maxfd = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+static __thread struct llist_head osmo_fds; /* TLS cannot use LLIST_HEAD() */</span><br><span style="color: hsl(120, 100%, 40%);">+static __thread int unregistered_count;</span><br><span> </span><br><span> /*! Set up an osmo-fd. Will not register it.</span><br><span>  *  \param[inout] ofd Osmo FD to be set-up</span><br><span>@@ -307,6 +309,18 @@</span><br><span>     return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! initialize the osmocom select abstraction for the current thread */</span><br><span style="color: hsl(120, 100%, 40%);">+void osmo_select_init(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        INIT_LLIST_HEAD(&osmo_fds);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* ensure main thread always has pre-initialized osmo_fds */</span><br><span style="color: hsl(120, 100%, 40%);">+static __attribute__((constructor)) void on_dso_load_select(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      osmo_select_init();</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #ifdef HAVE_SYS_TIMERFD_H</span><br><span> #include <sys/timerfd.h></span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/13537">change 13537</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/13537"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I5082ed3e500ad1a7516e1785bc57e008da2fac9a </div>
<div style="display:none"> Gerrit-Change-Number: 13537 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: fixeria <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>