summaryrefslogtreecommitdiff
path: root/libcr_ipc
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-11 18:40:13 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-11-11 19:19:48 -0700
commitc3fa4301fd3a5205b6bc1de3c6975ac5b56befd6 (patch)
tree3fc41e16cc1102fe303b6d419a02d58bda27e3c2 /libcr_ipc
parentc08b86b1c07bc45c14393ed0d3e759faa89ea59b (diff)
libcr_ipc/select.h: Simplify cr_select_l()
Diffstat (limited to 'libcr_ipc')
-rw-r--r--libcr_ipc/include/libcr_ipc/select.h45
1 files changed, 4 insertions, 41 deletions
diff --git a/libcr_ipc/include/libcr_ipc/select.h b/libcr_ipc/include/libcr_ipc/select.h
index 5e36a18..788bf53 100644
--- a/libcr_ipc/include/libcr_ipc/select.h
+++ b/libcr_ipc/include/libcr_ipc/select.h
@@ -5,7 +5,6 @@
*/
#include <alloca.h> /* for alloca() */
-#include <stdarg.h> /* for va_* */
#include <stddef.h> /* for size_t */
#include <libmisc/assert.h>
@@ -24,7 +23,6 @@
*/
struct cr_select_arg {
enum {
- _CR_SELECT_OP_NONE,
_CR_SELECT_OP_RECV,
_CR_SELECT_OP_SEND,
_CR_SELECT_OP_DEFAULT,
@@ -62,10 +60,6 @@ struct cr_select_arg {
((struct cr_select_arg){ \
.op = _CR_SELECT_OP_DEFAULT, \
})
-#define _CR_SELECT_END \
- ((struct cr_select_arg){ \
- .op = _CR_SELECT_OP_NONE, \
- })
/* cr_select_v(arg_cnt, arg_vec) **********************************************/
@@ -177,40 +171,9 @@ static size_t cr_select_v(size_t arg_cnt, struct cr_select_arg arg_vec[]) {
/* cr_select_l(arg1, arg2, arg3, ...) ******************************************/
-#define cr_select_l(...) _cr_selectl(__VA_ARGS__ __VA_OPT__(,) _CR_SELECT_END)
-static inline size_t _cr_select_l(struct cr_select_arg first_arg, ...) {
- va_list list;
-
- /* Pass 1: Count how many args we have. */
- size_t arg_cnt = 0;
- va_start(list, first_arg);
- for (;;) {
- struct cr_select_arg arg;
- if (arg_cnt == 0)
- arg = first_arg;
- else
- arg = va_arg(list, struct cr_select_arg);
- if (arg.op == _CR_SELECT_OP_NONE)
- break;
- arg_cnt++;
- }
- va_end(list);
-
- /* Pass 2: Copy the args to a simple vector on the stack. */
- struct cr_select_arg *arg_vec = alloca(sizeof(struct cr_select_arg) * arg_cnt);
- va_start(list, first_arg);
- for (size_t i = 0; i < arg_cnt; i++) {
- struct cr_select_arg arg;
- if (i == 0)
- arg = first_arg;
- else
- arg = va_arg(list, struct cr_select_arg);
- arg_vec[i] = arg;
- }
- va_end(list);
-
- /* Now pass that to cr_select_v() for the real work. */
- return cr_select_v(arg_cnt, arg_vec);
-}
+#define cr_select_l(...) ({ \
+ struct cr_select_arg _cr_select_args[] = { __VA_ARGS__ }; \
+ cr_select_v(sizeof(_cr_select_args)/sizeof(_cr_select_args[0])); \
+})
#endif /* _LIBCR_IPC_SELECT_H_ */