Skip to content

Commit

Permalink
🔥 core poisoning and m_bool removal
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Feb 12, 2024
1 parent 794ebb7 commit 373c31f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
18 changes: 18 additions & 0 deletions include/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

#define CHECK_b(f) \
do { \
if (!f) return GW_ERROR; \
} while (0)
#define CHECK_B(f) \
do { \
if (!f) return false; \
} while (0)
#define CHECK_O(f) \
do { \
if (!f) return NULL; \
} while (0)
#define CHECK_BB(f) \
do { \
if (f < 0) return GW_ERROR; \
Expand All @@ -61,6 +73,12 @@
if (!f) return NULL; \
} while (0)

#define DECL_B(decl, f, exp) \
decl f exp; \
if (!f) return false
#define DECL_O(decl, f, exp) \
decl f exp; \
if (!f) return NULL
#define DECL_BB(decl, f, exp) \
decl f exp; \
if (f < 0) return GW_ERROR
Expand Down
2 changes: 1 addition & 1 deletion include/mpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ typedef struct MemPool_ {
ANN struct pool *new_pool(const uint32_t elementSize);
ANN struct pool *mp_ini(MemPool p, const uint32_t elementSize);
ANN void mp_end(struct pool *);
ANEW ANN void *_mp_calloc2(struct pool *, const m_bool) __attribute__((hot));
ANEW ANN void *_mp_calloc2(struct pool *, const bool) __attribute__((hot));
ANEW ANN void *_mp_calloc(MemPool, const m_uint) __attribute__((hot));
ANEW ANN void *_mp_malloc(MemPool, const m_uint) __attribute__((hot));
ANN void _mp_free(MemPool, const m_uint, void *);
Expand Down
2 changes: 1 addition & 1 deletion include/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ ANN static inline void scope_pop(MemPool p NUSED, const Scope s) {
ANN static inline void _scope_init(const Scope s) {
vector_init((Vector)(void *)s);
}
ANN m_bool scope_iter(struct scope_iter *iter, void *ret);
ANN bool scope_iter(struct scope_iter *iter, void *ret);
#endif
4 changes: 2 additions & 2 deletions src/carg.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ ANN static void _split_args(MemPool mp, struct ArgSplitter *as) {
m_uint i = 0, j = 0;
char c;
while ((c = as->str[i]) != '\0') {
const m_bool skip = prev == '\\';
const m_bool comma = c == ',';
const bool skip = prev == '\\';
const bool comma = c == ',';
if (comma) {
if (!skip) break;
--j;
Expand Down
4 changes: 2 additions & 2 deletions src/mpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void _realloc(struct pool *p) {
p->data[p->blk_id] = (uint8_t *)xcalloc(BLK(p->obj_sz), p->obj_sz);
}

static void *__mp_calloc2(struct pool *p, const m_bool zero) {
static void *__mp_calloc2(struct pool *p, const bool zero) {
if (p->next) {
volatile struct Recycle *const recycle = p->next;
#ifdef USE_HELGRIND
Expand All @@ -103,7 +103,7 @@ static void *__mp_calloc2(struct pool *p, const m_bool zero) {
return p->data[p->blk_id] + p->obj_id * p->obj_sz;
}

void *_mp_calloc2(struct pool *p, const m_bool zero) {
void *_mp_calloc2(struct pool *p, const bool zero) {
gwt_lock(&p->mutex);
void *ret = __mp_calloc2(p, zero);
gwt_unlock(&p->mutex);
Expand Down
6 changes: 3 additions & 3 deletions src/scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ ANN void free_scope(MemPool p, Scope a) {
mp_free(p, Scope, a);
}

ANN m_bool scope_iter(struct scope_iter *iter, void *ret) {
ANN bool scope_iter(struct scope_iter *iter, void *ret) {
m_uint size = map_size(&iter->s->map);
const m_uint vsize = vector_size((Vector)iter->s);
const m_uint vec = vsize - iter->vec;
Map map = &iter->s->map;
if (vsize == iter->vec) {
if (iter->idx == size) return GW_ERROR;
if (iter->idx == size) return false;
} else {
map = (Map)&VPTR(iter->s, vec - 1);
size = map_size(map);
Expand All @@ -77,5 +77,5 @@ ANN m_bool scope_iter(struct scope_iter *iter, void *ret) {
}
}
*(vtype *)ret = map_at(map, size - ++iter->idx);
return GW_OK;
return true;
}
5 changes: 3 additions & 2 deletions src/threadpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ANN static bool utils(threadpool_t *p) {

ANN static bool start(threadpool_t *p, const uint32_t thread_count) {
for(uint32_t i = 0; i < thread_count; i++) {
if(gwt_create(&p->threads[i], threadpool_thread, p))
if(!gwt_create(&p->threads[i], threadpool_thread, p))
return false;
p->started++;
}
Expand All @@ -71,10 +71,11 @@ threadpool_t *new_threadpool(const uint32_t thread_count, const uint32_t queue_s
p->started = 0;
p->queue_size = queue_size;
if(alloc(p, thread_count, queue_size) || !utils(p) ||
start(p, thread_count)) {
!start(p, thread_count)) {
free_threadpool(p);
return NULL;
}

return p;
}

Expand Down

0 comments on commit 373c31f

Please sign in to comment.