X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=runtime%2Fmem.c;h=1787a6253f299e67c01c063758aa26399d64bc87;hp=754bb19d5ce293ad345a96801d4b49f89384f944;hb=f3eb4799a11ceaeb47ab02034595b5d641c2f1c9;hpb=af2000653f50ce43e94bfd260ce47e4b53ab2222 diff --git a/runtime/mem.c b/runtime/mem.c index 754bb19..1787a62 100644 --- a/runtime/mem.c +++ b/runtime/mem.c @@ -8,10 +8,10 @@ #include #include #include "common.h" -#include "runtime_local.h" +#include "rlocal.h" #include "lwt.h" -#define GET_SCALE(n) (sizeof(n)*8-__builtin_clzl((n)-1)) // log2 of , rounded up +#define GET_SCALE(n) (sizeof(void *)*__CHAR_BIT__ - __builtin_clzl((n) - 1)) // log2 of , rounded up #define MAX_SCALE 31 // allocate blocks up to 4GB in size (arbitrary, could be bigger) #define REGION_SCALE 22 // 4MB regions #define REGION_SIZE (1 << REGION_SCALE) @@ -67,6 +67,9 @@ void nbd_free (void *x) { block_t *b = (block_t *)x; assert(((size_t)b >> REGION_SCALE) < ((1 << HEADER_REGION_SCALE) / sizeof(header_t))); header_t *h = region_header_ + ((size_t)b >> REGION_SCALE); +#ifndef NDEBUG + memset(b, 0xcd, (1 << h->scale)); +#endif TRACE("m0", "nbd_free(): block %p scale %llu", b, h->scale); if (h->owner == tid_) { TRACE("m0", "nbd_free(): private block, free list head %p", @@ -76,8 +79,9 @@ void nbd_free (void *x) { } else { TRACE("m0", "nbd_free(): owner %llu free list head %p", h->owner, pub_free_list_[h->owner][h->scale][tid_]); - b->next = pub_free_list_[h->owner][h->scale][tid_]; - pub_free_list_[h->owner][h->scale][tid_] = b; + do { + b->next = pub_free_list_[h->owner][h->scale][tid_]; + } while (SYNC_CAS(&pub_free_list_[h->owner][h->scale][tid_], b->next, b) != b->next); } }