From 8716a9c088d517992052c16d0cbab0301b09760f Mon Sep 17 00:00:00 2001 From: Milo Turner Date: Tue, 25 Feb 2020 14:53:54 -0500 Subject: [PATCH] [async] helper macros for msgq/pubsub moved to msg.h --- src/backend/sdl.c | 2 +- src/concurrent/msg.h | 24 ++++++++++++++++++++++++ src/concurrent/msgq.h | 21 --------------------- src/concurrent/pubsub.h | 3 --- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/backend/sdl.c b/src/backend/sdl.c index 0f77e64..b720e99 100644 --- a/src/backend/sdl.c +++ b/src/backend/sdl.c @@ -161,7 +161,7 @@ void ax__backend_step(struct ax_backend* bac) default: nmsg++; - printf("Got a weird message: `%s'\n", ax__msg_name(mqr__type)); + printf("Got a weird message: `%s'\n", ax__msg_name(m_type)); break; } msgq_end_recv(bac->inbox); diff --git a/src/concurrent/msg.h b/src/concurrent/msg.h index a950090..ef411ca 100644 --- a/src/concurrent/msg.h +++ b/src/concurrent/msg.h @@ -47,3 +47,27 @@ static inline const char* ax__msg_name(int val) #undef IMPOSSIBLE #define IMPOSSIBLE(x) IMPOSSIBLE_(x) } + +// helper macros + +#define msgq_begin_send_typed(_mq, ty) \ + ((struct ty*) msgq_begin_send(_mq, ty ## _TAG, sizeof(struct ty))) + +#define pubsub_begin_pub_typed(_src, ty) \ + ((struct ty*) pubsub_begin_pub(_src, ty ## _TAG, sizeof(struct ty))) + +#define MSGQ_RECV_ALL(_mq) \ + int m_type; void* m_data; \ + while ((m_data = msgq_recv1(_mq, &m_type)) != NULL) \ + switch (m_type) + +#define SUB_RECV_ALL(_sub) \ + int m_type; void* m_data; \ + while ((m_data = sub_recv1(_sub, &m_type)) != NULL) \ + switch (m_type) + +#define ON(ty, _body) \ + case ty ## _TAG: { \ + struct ty m = *(struct ty*) m_data; \ + _body; \ + } diff --git a/src/concurrent/msgq.h b/src/concurrent/msgq.h index 8493af3..b985aa4 100644 --- a/src/concurrent/msgq.h +++ b/src/concurrent/msgq.h @@ -13,11 +13,6 @@ struct msgq { pthread_cond_t cv; }; -struct msgq_list { - struct msgq_list* next; - struct msgq* mq; -}; - struct msgq_msg_list { struct msgq_msg_list* next; int type; @@ -33,19 +28,3 @@ void msgq_begin_recv(struct msgq* mq); void msgq_begin_recv_and_wait(struct msgq* mq); void* msgq_recv1(struct msgq* mq, int* out_type); void msgq_end_recv(struct msgq* mq); - -// helper macros - -#define msgq_begin_send_typed(_mq, ty) \ - ((struct ty*) msgq_begin_send(_mq, ty ## _TAG, sizeof(struct ty))) - -#define MSGQ_RECV_ALL(_mq) \ - int mqr__type; void* mqr__data; \ - while ((mqr__data = msgq_recv1(_mq, &mqr__type)) != NULL) \ - switch (mqr__type) - -#define ON(ty, _body) \ - case ty ## _TAG: { \ - struct ty m = *(struct ty*) mqr__data; \ - _body; \ - } diff --git a/src/concurrent/pubsub.h b/src/concurrent/pubsub.h index 2c513ef..dcc5a0f 100644 --- a/src/concurrent/pubsub.h +++ b/src/concurrent/pubsub.h @@ -47,6 +47,3 @@ void sub_begin_recv(struct sub* sub); void sub_begin_recv_and_wait(struct sub* sub); void* sub_recv1(struct sub* sub, int* out_type); void sub_end_recv(struct sub* sub); - -#define pubsub_begin_pub_typed(_src, ty) \ - ((struct ty*) pubsub_begin_pub(_src, ty ## _TAG, sizeof(struct ty)))