Initial (bad) gc
This commit is contained in:
29
src/memory.h
29
src/memory.h
@ -5,13 +5,14 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
// Geneal macros
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(attr) 0
|
||||
#endif
|
||||
|
||||
#if __has_attribute(always_inline)
|
||||
#if __has_attribute(always_inline) && defined(_NDEBUG)
|
||||
# define ALWAYS_INLINE inline __attribute__((always_inline))
|
||||
#else
|
||||
# define ALWAYS_INLINE inline
|
||||
@ -95,5 +96,31 @@ void *lisp_realloc(void *oldptr, size_t size);
|
||||
void *lisp_malloc(size_t size);
|
||||
void *lisp_malloc0(size_t size);
|
||||
void *lisp_aligned_alloc(size_t alignment, size_t size);
|
||||
#define lisp_free free
|
||||
|
||||
// other useful things
|
||||
static ALWAYS_INLINE void sub_timespecs(const struct timespec *t1,
|
||||
const struct timespec *t2,
|
||||
struct timespec *out) {
|
||||
out->tv_sec = t1->tv_sec - t2->tv_sec;
|
||||
int32_t nsec = t1->tv_nsec - t2->tv_nsec;
|
||||
if (nsec < 0) {
|
||||
--out->tv_sec;
|
||||
nsec += 1000000000;
|
||||
}
|
||||
out->tv_nsec = nsec;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void add_timespecs(const struct timespec *t1,
|
||||
const struct timespec *t2,
|
||||
struct timespec *out) {
|
||||
out->tv_sec = t1->tv_sec + t2->tv_sec;
|
||||
int32_t nsec = t1->tv_nsec + t2->tv_nsec;
|
||||
if (nsec > 1000000000) {
|
||||
++out->tv_sec;
|
||||
nsec -= 1000000000;
|
||||
}
|
||||
out->tv_nsec = nsec;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user