Skip to content

Commit

Permalink
Fix name conflict in haiku limits.h
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Oct 2, 2023
1 parent c4db2b2 commit 755807b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/sdb/cwisstable.h
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ static inline size_t RandomSeed(void) {
size_t value = counter++;
#else
static CWISS_ATOMIC_T(size_t) counter;
size_t value = CWISS_ATOMIC_INC(counter);
size_t value = CWISS_ATOMIC_INC (counter);
#endif
return value ^ ((size_t)&counter);
}
Expand Down
16 changes: 8 additions & 8 deletions src/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ typedef struct Footer {

#define ALIGNMENT 8
#define ALIGN(size) (((size) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1))
#define PAGE_SIZE sysconf(_SC_PAGESIZE)
#define SDB_PAGE_SIZE sysconf(_SC_PAGESIZE)
#define CEIL(X) ((X - (int)(X)) > 0 ? (int)(X + 1) : (int)(X))
#define PAGES(size) (CEIL(size / (double)PAGE_SIZE))
#define PAGES(size) (CEIL(size / (double)SDB_PAGE_SIZE))
#define MIN_SIZE (ALIGN(sizeof(free_list) + META_SIZE))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))

Expand Down Expand Up @@ -233,8 +233,8 @@ static void *sdb_heap_malloc(SdbHeap *heap, int size) {
// No free block was found. Allocate size requested + header (in full pages).
// Each next allocation will be doubled in size from the previous one
// (to decrease the number of mmap sys calls we make).
// int bytes = MAX (PAGES (required_size), heap->last_mapped_size) * PAGE_SIZE;
size_t bytes = PAGES(MAX (PAGES (required_size), heap->last_mapped_size)) * PAGE_SIZE;
// int bytes = MAX (PAGES (required_size), heap->last_mapped_size) * SDB_PAGE_SIZE;
size_t bytes = PAGES(MAX (PAGES (required_size), heap->last_mapped_size)) * SDB_PAGE_SIZE;
heap->last_mapped_size *= 2;

// last_address my not be returned by mmap, but makes it more efficient if it happens.
Expand Down Expand Up @@ -334,17 +334,17 @@ static void sdb_heap_free(SdbHeap *heap, void *ptr) {
Header *header = (Header *)start_address;
int size = header->size;
uintptr_t addr = (uintptr_t)header;
if (size % PAGE_SIZE == 0 && addr % PAGE_SIZE == 0) {
if (size % SDB_PAGE_SIZE == 0 && (addr % SDB_PAGE_SIZE) == 0) {
// if: full page is free (or multiple consecutive pages), page-aligned -> can munmap it.
unmap (heap, start_address, size);
} else {
append_to_free_list (heap, start_address);
coalesce (heap, start_address);
// if we are left with a free block of size bigger than PAGE_SIZE that is
// page-aligned, munmap that part.
if (size >= PAGE_SIZE && addr % PAGE_SIZE == 0) {
split (heap, start_address, size, (size / PAGE_SIZE) * PAGE_SIZE);
unmap (heap, start_address, (size / PAGE_SIZE) * PAGE_SIZE);
if (size >= SDB_PAGE_SIZE && (addr % SDB_PAGE_SIZE) == 0) {
split (heap, start_address, size, (size / SDB_PAGE_SIZE) * SDB_PAGE_SIZE);
unmap (heap, start_address, (size / SDB_PAGE_SIZE) * SDB_PAGE_SIZE);
}
}
}
Expand Down

0 comments on commit 755807b

Please sign in to comment.