aboutsummaryrefslogtreecommitdiffstats
path: root/src/select.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-03-18 17:17:43 +0100
committerHarald Welte <laforge@gnumonks.org>2019-08-27 13:43:31 +0200
commit2d90611cb06b780b165296aa3abd1f7229d503f9 (patch)
tree0967edda82deb858d513b8fa268d26597e312810 /src/select.c
parent858c86639d09333d297fbbfa7b09fb4ab1209ac9 (diff)
context: Add support for [per-thread] global talloc contexts
Rather than having applications maintain their own talloc cotexts, let's offer some root talloc contexts in libosmocore. Let's also make them per thread right from the beginning. This will help some multi-threaded applications to use talloc in a thread-safe way. Change-Id: Iae39cd57274bf6753ecaf186f229e582b42662e3
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/select.c b/src/select.c
index 7ce135f5..394a59dd 100644
--- a/src/select.c
+++ b/src/select.c
@@ -36,6 +36,8 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/logging.h>
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/utils.h>
#include "../config.h"
@@ -233,11 +235,7 @@ restart:
return work;
}
-/*! select main loop integration
- * \param[in] polling should we pollonly (1) or block on select (0)
- * \returns 0 if no fd handled; 1 if fd handled; negative in case of error
- */
-int osmo_select_main(int polling)
+static int _osmo_select_main(int polling)
{
fd_set readset, writeset, exceptset;
int rc;
@@ -259,10 +257,42 @@ int osmo_select_main(int polling)
/* fire timers */
osmo_timers_update();
+ OSMO_ASSERT(osmo_ctx->select);
+
/* call registered callback functions */
return osmo_fd_disp_fds(&readset, &writeset, &exceptset);
}
+/*! select main loop integration
+ * \param[in] polling should we pollonly (1) or block on select (0)
+ * \returns 0 if no fd handled; 1 if fd handled; negative in case of error
+ */
+int osmo_select_main(int polling)
+{
+ int rc = _osmo_select_main(polling);
+#ifndef EMBEDDED
+ if (talloc_total_size(osmo_ctx->select) != 0) {
+ osmo_panic("You cannot use the 'select' volatile "
+ "context if you don't use osmo_select_main_ctx()!\n");
+ }
+#endif
+ return rc;
+}
+
+#ifndef EMBEDDED
+/*! select main loop integration with temporary select-dispatch talloc context
+ * \param[in] polling should we pollonly (1) or block on select (0)
+ * \returns 0 if no fd handled; 1 if fd handled; negative in case of error
+ */
+int osmo_select_main_ctx(int polling)
+{
+ int rc = _osmo_select_main(polling);
+ /* free all the children of the volatile 'select' scope context */
+ talloc_free_children(osmo_ctx->select);
+ return rc;
+}
+#endif
+
/*! find an osmo_fd based on the integer fd
* \param[in] fd file descriptor to use as search key
* \returns \ref osmo_fd for \ref fd; NULL in case it doesn't exist */