AmendHub

Download:

cyberslak

/

lightsout

/

amendments

/

21

remove unused channel code


cyberslak made amendment 21 18 days ago
--- channel.c Mon Mar 10 00:23:06 2025 +++ channel.c Thu Jan 30 22:32:16 1908 @@ -1,67 +0,0 @@ -#include <stdlib.h> -#include "channel.h" -#include "util.h" - -struct channel { - Ptr* ringbuf; - size_t reader; - size_t writer; - size_t size; - size_t count; -}; - -channel* channel_open(size_t bufsize) { - channel* ch = xmalloc(sizeof(*ch)); - ch->ringbuf = xmalloc(bufsize * sizeof(Ptr)); - ch->reader = ch->writer = 0; - ch->size = bufsize; - ch->count = 0; - return ch; -} - -void channel_close(channel* ch) { - if (!ch) return; - free(ch->ringbuf); - free(ch); -} - -/* A channel is full if it is not empty and the reader - * and writer are at the same cell. */ -static inline bool channel_full(channel* ch) -{ - return (ch->count && ch->reader == ch->writer); -} - -/* A channel is empty if count==0. */ -static inline bool channel_empty(channel* ch) -{ - return ch->count == 0; -} - -short channel_send(channel* ch, Ptr data) -{ - if (channel_full(ch)) - return -1; - - ch->ringbuf[ch->writer++] = data; - ch->count++; - - ch->writer %= ch->size; - - return 0; -} - -short channel_recv(channel* ch, Ptr* data) -{ - if (channel_empty(ch)) - return -1; - - if (!data) - die("channel_recv: data == NULL"); - - *data = ch->ringbuf[ch->reader++]; - ch->count--; - ch->reader %= ch->size; - - return 0; -} --- channel.h Mon Mar 10 00:23:08 2025 +++ channel.h Thu Jan 30 22:32:16 1908 @@ -1,9 +0,0 @@ -#include "stdint.h" - -typedef struct channel channel; - -channel* channel_open(size_t bufsize); -void channel_close(channel* c); - -short channel_send(channel* c, Ptr data); -short channel_recv(channel* c, Ptr* data);