osmo_io: Use bitfield for various boolean flags

Change-Id: Ic134e4c8d791c34778202fea98a70bc04007a113
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index b00da63..253dfa2 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);
 
@@ -443,6 +444,7 @@
 {
 	if (osmo_iofd_ops.unregister_fd)
 		return osmo_iofd_ops.unregister_fd(iofd);
+	IOFD_FLAG_SET(iofd, IOFD_FLAG_CLOSED);
 
 	return 0;
 }
@@ -483,12 +485,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 +505,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..d45b161 100644
--- a/src/core/osmo_io_internal.h
+++ b/src/core/osmo_io_internal.h
@@ -29,6 +29,19 @@
 	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) \
+	(iofd)->flags |= (flag)
+
+#define IOFD_FLAG_UNSET(iofd, flag) \
+	(iofd)->flags &= ~(flag)
+
+#define IOFD_FLAG_ISSET(iofd, flag) ((iofd)->flags & (flag))
+
 struct osmo_io_fd {
 	/*! linked list for internal management */
 	struct llist_head list;
@@ -38,10 +51,7 @@
 	enum osmo_io_fd_mode mode;
 
 	/*! 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..77a741a 100644
--- a/src/core/osmo_io_poll.c
+++ b/src/core/osmo_io_poll.c
@@ -81,7 +81,7 @@
 		}
 	}
 
-	if (iofd->closed)
+	if (IOFD_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;
+	IOFD_FLAG_SET(iofd, IOFD_FLAG_IN_CALLBACK);
 	iofd_poll_ofd_cb_recvmsg_sendmsg(ofd, what);
-	iofd->in_callback = false;
+	IOFD_FLAG_UNSET(iofd, IOFD_FLAG_IN_CALLBACK);
 
-	if (iofd->to_free) {
+	if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_TO_FREE)) {
 		talloc_free(iofd);
 		return 0;
 	}