aboutsummaryrefslogtreecommitdiff
path: root/stdlib/channels.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-13 20:18:08 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-13 20:18:08 -0400
commitc455e7b67d2e55e6ed03e3449203d4e307f5a7dd (patch)
tree27d9d4c77193f7aa1fe3a3c6fe5631d0ccfd59e2 /stdlib/channels.h
parent816aa29b799132acb8c71d4968df6c4619fb2b1d (diff)
Rename builtins/ -> stdlib/
Diffstat (limited to 'stdlib/channels.h')
-rw-r--r--stdlib/channels.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/stdlib/channels.h b/stdlib/channels.h
new file mode 100644
index 00000000..8deb0569
--- /dev/null
+++ b/stdlib/channels.h
@@ -0,0 +1,28 @@
+#pragma once
+
+// Functions that operate on channels (thread-safe arrays)
+
+#include <stdbool.h>
+
+#include "datatypes.h"
+#include "types.h"
+#include "util.h"
+
+Channel_t *Channel$new(Int_t max_size);
+void Channel$give(Channel_t *channel, const void *item, bool front, int64_t padded_item_size);
+#define Channel$give_value(channel, item, front, padded_item_size) \
+ ({ __typeof(item) _item = item; Channel$give(channel, &_item, front, padded_item_size); })
+void Channel$give_all(Channel_t *channel, Array_t to_give, bool front, int64_t padded_item_size);
+void Channel$get(Channel_t *channel, void *out, bool front, int64_t item_size, int64_t padded_item_size);
+#define Channel$get_value(channel, front, t, padded_item_size) \
+ ({ t _val; Channel$get(channel, &_val, front, sizeof(t), padded_item_size); _val; })
+void Channel$peek(Channel_t *channel, void *out, bool front, int64_t item_size);
+#define Channel$peek_value(channel, front, t) ({ t _val; Channel$peek(channel, &_val, front, sizeof(t)); _val; })
+void Channel$clear(Channel_t *channel);
+Array_t Channel$view(Channel_t *channel);
+PUREFUNC uint64_t Channel$hash(Channel_t **channel, const TypeInfo *type);
+PUREFUNC int32_t Channel$compare(Channel_t **x, Channel_t **y, const TypeInfo *type);
+PUREFUNC bool Channel$equal(Channel_t **x, Channel_t **y, const TypeInfo *type);
+Text_t Channel$as_text(Channel_t **channel, bool colorize, const TypeInfo *type);
+
+// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0