[S] Change in libosmocore[master]: osmo_io: Use bitfield for various boolean flags
daniel has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/33495 ) Change subject: osmo_io: Use bitfield for various boolean flags ...................................................................... osmo_io: Use bitfield for various boolean flags Change-Id: Ic134e4c8d791c34778202fea98a70bc04007a113 --- M src/core/osmo_io.c M src/core/osmo_io_internal.h M src/core/osmo_io_poll.c 3 files changed, 37 insertions(+), 12 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/95/33495/1 diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c index b00da63..d06e804 100644 --- a/src/core/osmo_io.c +++ b/src/core/osmo_io.c @@ -388,6 +388,7 @@ iofd->fd = fd; iofd->mode = mode; + IOFD_FLAG_SET(iofd, IOFD_FLAG_CLOSED); if (name) iofd->name = talloc_strdup(iofd, name); @@ -427,7 +428,7 @@ if (rc) return rc; - iofd->closed = false; + IOFD_FLAG_UNSET(iofd, IOFD_FLAG_CLOSED); osmo_iofd_ops.read_enable(iofd); osmo_iofd_ops.write_enable(iofd); @@ -483,12 +484,12 @@ osmo_iofd_close(iofd); - if (!iofd->in_callback) { + if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_IN_CALLBACK)) { talloc_free(iofd); } else { /* Prevent our parent context from freeing us prematurely */ talloc_steal(NULL, iofd); - iofd->to_free = true; + IOFD_FLAG_SET(iofd, IOFD_FLAG_TO_FREE); } } @@ -503,10 +504,10 @@ { int rc = 0; - if (iofd->closed) + if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED)) return rc; - iofd->closed = true; + IOFD_FLAG_SET(iofd, IOFD_FLAG_CLOSED); /* Free pending msgs in tx queue */ osmo_iofd_txqueue_clear(iofd); diff --git a/src/core/osmo_io_internal.h b/src/core/osmo_io_internal.h index cd620e7..bd2e655 100644 --- a/src/core/osmo_io_internal.h +++ b/src/core/osmo_io_internal.h @@ -29,6 +29,23 @@ void (*read_disable)(struct osmo_io_fd *iofd); }; +#define IOFD_FLAG_CLOSED (1<<0) +#define IOFD_FLAG_IN_CALLBACK (1<<1) +#define IOFD_FLAG_TO_FREE (1<<2) +#define IOFD_FLAG_NOTIFY_CONNECTED (1<<3) + +#define IOFD_FLAG_SET(iofd, flag) \ + do { \ + iofd->flags |= (flag); \ + } while (0) + +#define IOFD_FLAG_UNSET(iofd, flag) \ + do { \ + iofd->flags &= ~(flag); \ + } while (0) + +#define IOFD_FLAG_ISSET(iofd, flag) (iofd->flags & flag) + struct osmo_io_fd { /*! linked list for internal management */ struct llist_head list; @@ -39,9 +56,7 @@ /*! flags to guard closing/freeing of iofd */ /* TODO: Move to bitfield */ - bool closed; - bool in_callback; - bool to_free; + uint32_t flags; /*! human-readable name to associte with fd */ char *name; diff --git a/src/core/osmo_io_poll.c b/src/core/osmo_io_poll.c index 571f2bb..a5fc881 100644 --- a/src/core/osmo_io_poll.c +++ b/src/core/osmo_io_poll.c @@ -81,7 +81,7 @@ } } - if (iofd->closed) + if (FLAG_ISSET(iofd, IOFD_FLAG_CLOSED)) return; if (what & OSMO_FD_WRITE) { @@ -126,11 +126,11 @@ { struct osmo_io_fd *iofd = ofd->data; - iofd->in_callback = true; + FLAG_SET(iofd, IOFD_FLAG_IN_CALLBACK); iofd_poll_ofd_cb_recvmsg_sendmsg(ofd, what); - iofd->in_callback = false; + FLAG_UNSET(iofd, IOFD_FLAG_IN_CALLBACK); - if (iofd->to_free) { + if (FLAG_ISSET(iofd, IOFD_FLAG_TO_FREE)) { talloc_free(iofd); return 0; } -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/33495 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: Ic134e4c8d791c34778202fea98a70bc04007a113 Gerrit-Change-Number: 33495 Gerrit-PatchSet: 1 Gerrit-Owner: daniel <dwillmann@sysmocom.de> Gerrit-MessageType: newchange
participants (1)
-
daniel