pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/42084?usp=email )


Change subject: osmo_io: Lazy-initialize during osmo_iofd_setup()
......................................................................

osmo_io: Lazy-initialize during osmo_iofd_setup()

This way new threads (!=main) don't need to explicitly call
osmo_iofd_init() explicitly before using osmo_io. This is specially
useful for threads using osmo_io indirectly, eg, when logging.

The osmo_iofd_setup() API is really the only main API which requires
initialization. All other APIs requiring it come after osmo_iofd_setup()
since they use an osmo_iofd pointer.

Change-Id: Ia543c1b9d111c929cd9dbed266b6d21b74e47e4b
---
M src/core/osmo_io.c
1 file changed, 7 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/84/42084/1

diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index 9e159a1..7c59a61 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -69,9 +69,14 @@
 /* Used by some tests, can't be static */
 struct iofd_backend_ops osmo_iofd_ops;

+static __thread bool g_thread_initialized = false;
+
 /*! initialize osmo_io for the current thread */
 void osmo_iofd_init(void)
 {
+       if (g_thread_initialized)
+               return;
+
        switch (g_io_backend) {
        case OSMO_IO_BACKEND_POLL:
                break;
@@ -84,6 +89,7 @@
                OSMO_ASSERT(0);
                break;
        }
+       g_thread_initialized = true;
 }

 /* ensure main thread always has pre-initialized osmo_io
@@ -833,6 +839,7 @@
                  const struct osmo_io_ops *ioops, void *data)
 {
        struct osmo_io_fd *iofd;
+       osmo_iofd_init();

        /* reject unsupported/unknown modes */
        switch (mode) {

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/42084?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ia543c1b9d111c929cd9dbed266b6d21b74e47e4b
Gerrit-Change-Number: 42084
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to