I am stoopid (and fixed some bugs)
This commit is contained in:
parent
0ded77495b
commit
745623afb2
3 changed files with 9 additions and 13 deletions
|
@ -9,18 +9,11 @@
|
|||
#define __SIZE_TYPE__ unsigned long int
|
||||
#endif /* __SIZE_TYPE__ */
|
||||
|
||||
#if __SIZEOF_SIZE_T__ == 1
|
||||
#define _SSIZE_TYPE_ int8_t;
|
||||
#elif __SIZEOF_SIZE_T__ == 2
|
||||
#define _SSIZE_TYPE_ int16_t;
|
||||
#else
|
||||
#define _SSIZE_TYPE_ int32_t;
|
||||
#endif /* __SIZEOF_SIZE_T__ */
|
||||
|
||||
/** Unsigned size specifier. */
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
/** Signed size specifier (negative sizes mean error codes). */
|
||||
typedef __PTRDIFF_TYPE__ ssize_t;
|
||||
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
|
||||
#if CONFIG_SCHED_MAXPROC < 128
|
||||
#define _PID_TYPE_ int8_t
|
||||
|
@ -38,7 +31,7 @@ typedef _PID_TYPE_ pid_t;
|
|||
#endif /* __SIG_ATOMIC_TYPE__ */
|
||||
|
||||
typedef struct {
|
||||
__SIG_ATOMIC_TYPE__ lock;
|
||||
_Atomic __SIG_ATOMIC_TYPE__ lock;
|
||||
} atomic_t;
|
||||
|
||||
/*
|
||||
|
|
|
@ -26,5 +26,5 @@
|
|||
ARDIX_KERNEL_PWD = $(PWD)/kernel
|
||||
|
||||
ARDIX_SOURCES += \
|
||||
$(ARCHX_KERNEL_PWD)/ringbuf.c \
|
||||
$(ARDIX_KERNEL_PWD)/ringbuf.c \
|
||||
$(ARDIX_KERNEL_PWD)/sched.c
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <ardix/malloc.h>
|
||||
#include <ardix/ringbuf.h>
|
||||
#include <ardix/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct ringbuf *ringbuf_create(size_t size)
|
||||
|
@ -16,9 +17,11 @@ struct ringbuf *ringbuf_create(size_t size)
|
|||
buf->size = size;
|
||||
buf->rpos = &buf->data[0];
|
||||
buf->wpos = &buf->data[0];
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void ringbuf_destroy(struct ringbuf *buf)
|
||||
inline void ringbuf_destroy(struct ringbuf *buf)
|
||||
{
|
||||
free(buf);
|
||||
}
|
||||
|
@ -32,7 +35,7 @@ size_t ringbuf_read(uint8_t *dest, struct ringbuf *buf, size_t len)
|
|||
n++;
|
||||
|
||||
/* wrap around */
|
||||
if (buf->rpos - &buf->data[0] >= buf->size)
|
||||
if ((ptrdiff_t)(buf->rpos) - (ptrdiff_t)(&buf->data[0]) >= (ptrdiff_t)(buf->size))
|
||||
buf->rpos = &buf->data[0];
|
||||
}
|
||||
|
||||
|
@ -48,7 +51,7 @@ size_t ringbuf_write(struct ringbuf *buf, const uint8_t *src, size_t len)
|
|||
n++;
|
||||
|
||||
/* wrap around */
|
||||
if (buf->wpos - &buf->data[0] >= buf->size)
|
||||
if ((ptrdiff_t)(buf->wpos) - (ptrdiff_t)(&buf->data[0]) >= (ptrdiff_t)(buf->size))
|
||||
buf->wpos = &buf->data[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue