Change in libosmocore[master]: select: Introduce osmo_fd_{read, write}_{enable, disable}()

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.org
Sun Oct 18 20:22:17 UTC 2020


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/20734 )


Change subject: select: Introduce osmo_fd_{read,write}_{enable,disable}()
......................................................................

select: Introduce osmo_fd_{read,write}_{enable,disable}()

If we watn to migrate to something like epoll(), user application
code must call a function of the libosmocore API whenever it changes
its read/write interest in a file descriptor.

Let's introduce API so applications can be ported to this API,
before making direct 'ofd->when' manipulations illegal as a second step.

Change-Id: Idb89ba7bc7c129a6304a76900d17f47daf54d17d
---
M include/osmocom/core/select.h
M src/select.c
2 files changed, 29 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/34/20734/1

diff --git a/include/osmocom/core/select.h b/include/osmocom/core/select.h
index bc60198..b410199 100644
--- a/include/osmocom/core/select.h
+++ b/include/osmocom/core/select.h
@@ -19,6 +19,8 @@
 #define OSMO_FD_WRITE	0x0002
 /*! Indicate interest in exceptions from the file descriptor */
 #define OSMO_FD_EXCEPT	0x0004
+/*! Used as when_mask in osmo_fd_update_when() */
+#define OSMO_FD_MASK	0xFFFF
 
 /* legacy naming dating back to early OpenBSC / bsc_hack of 2008 */
 #define BSC_FD_READ	OSMO_FD_READ
@@ -47,6 +49,24 @@
 		   int (*cb)(struct osmo_fd *fd, unsigned int what),
 		   void *data, unsigned int priv_nr);
 
+void osmo_fd_update_when(struct osmo_fd *ofd, unsigned int when_mask, unsigned int when);
+
+static inline void osmo_fd_read_enable(struct osmo_fd *ofd) {
+	osmo_fd_update_when(ofd, OSMO_FD_MASK, OSMO_FD_READ);
+}
+
+static inline void osmo_fd_read_disable(struct osmo_fd *ofd) {
+	osmo_fd_update_when(ofd, ~OSMO_FD_READ, 0);
+}
+
+static inline void osmo_fd_write_enable(struct osmo_fd *ofd) {
+	osmo_fd_update_when(ofd, OSMO_FD_MASK, OSMO_FD_WRITE);
+}
+
+static inline void osmo_fd_write_disable(struct osmo_fd *ofd) {
+	osmo_fd_update_when(ofd, ~OSMO_FD_WRITE, 0);
+}
+
 bool osmo_fd_is_registered(struct osmo_fd *fd);
 int osmo_fd_register(struct osmo_fd *fd);
 void osmo_fd_unregister(struct osmo_fd *fd);
diff --git a/src/select.c b/src/select.c
index 870809f..7636502 100644
--- a/src/select.c
+++ b/src/select.c
@@ -89,6 +89,15 @@
 	ofd->priv_nr = priv_nr;
 }
 
+/*! Update the 'when' field of osmo_fd. "ofd->when = (ofd->when & when_mask) | when".
+ *  Use this function instead of directly modifying ofd->when, as the latter will be
+ *  removed soon. */
+void osmo_fd_update_when(struct osmo_fd *ofd, unsigned int when_mask, unsigned int when)
+{
+	ofd->when &= when_mask;
+	ofd->when |= when;
+}
+
 /*! Check if a file descriptor is already registered
  *  \param[in] fd osmocom file descriptor to be checked
  *  \returns true if registered; otherwise false

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/20734
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Idb89ba7bc7c129a6304a76900d17f47daf54d17d
Gerrit-Change-Number: 20734
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201018/678bd34c/attachment.htm>


More information about the gerrit-log mailing list