<commit_before>#include "fmpool.h"

#define fmpoolFobj(P) \
	((fobj*)(((char*)(P)) - sizeof(fobj)))

fmpool* 
fmpoolCreate(size_t cap, size_t size) {
	fmpool* p;
	if ((p = calloc(1, sizeof(fmpool)+(sizeof(fobj)+size)*cap)) == NULL) return NULL;
	p->size = sizeof(fobj) + size;
	p->cap = cap * p->size;
	return p;
}

void*
fmpoolAlloc(fmpool* p) {
	fobj* o;
	int   b = 1;
	while (b) {
		p->last += p->size;
		p->last %= p->cap;
		o = (fobj*)&p->memory[p->last];
		b = o->busy;
	}
	o->busy = 1;
	return (void*)&o->memory[0];
}

void
fmpoolFree(void* obj) {
	fmpoolFobj(obj)->busy = 0;
}<commit_msg>mt fmpool, yet not tested<commit_after>#include "fmpool.h"

#define fmpoolFobj(P) \
	((fobj*)(((char*)(P)) - sizeof(fobj)))

#define CAS(ptr, old, new) \
	 (__sync_bool_compare_and_swap((ptr), (old), (new)))

fmpool* 
fmpoolCreate(size_t cap, size_t size) {
	fmpool* p;
	if ((p = calloc(1, sizeof(fmpool)+(sizeof(fobj)+size)*cap)) == NULL) return NULL;
	p->size = sizeof(fobj) + size;
	p->cap = cap * p->size;
	return p;
}

void*
fmpoolAlloc(fmpool* p) {
	int size = p->size;
	int cap = p->cap;
	int count = cap/size;
	int i, b;
	fobj* o;
	for (i = 0; i < count; i++) {
		p->last += size;
		p->last %= cap;
		o = (fobj*)&p->memory[p->last];
		b = o->busy;
		if (!b && CAS(&fmpoolFobj(o)->busy, 0, 1))
			return (void*)&o->memory[0];
	}
	return NULL;
}

void
fmpoolFree(void* obj) {
	CAS(&fmpoolFobj(obj)->busy, 1, 0);
}
{'fraction_non_alphanumeric': 0.22968197879858657, 'fraction_numerical': 0.008480565371024734, 'mean_word_length': 3.9337979094076654, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4252259', 'n_tokens_mistral': 697, 'n_tokens_neox': 672, 'n_words': 140}