[async] helper macros for msgq/pubsub moved to msg.h

This commit is contained in:
Milo Turner 2020-02-25 14:53:54 -05:00
parent 3ba13abab5
commit 8716a9c088
4 changed files with 25 additions and 25 deletions

View File

@ -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);

View File

@ -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; \
}

View File

@ -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; \
}

View File

@ -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)))