]> pd.if.org Git - nbds/blobdiff - runtime/mem.c
work in progress
[nbds] / runtime / mem.c
index 90a22e1f90b57e3d8b31d17618be2a3b95647258..2f55ff4d2108d93522d878e4549ef5812cc10721 100644 (file)
@@ -74,9 +74,9 @@ static inline header_t *get_header (void *r) {
 }
 
 static void *get_new_region (int block_scale) {
-    LOCALIZE_THREAD_LOCAL(tid_, int);
+    int thread_index = GET_THREAD_INDEX();
 #ifdef RECYCLE_PAGES
-    tl_t *tl = &tl_[tid_]; // thread-local data
+    tl_t *tl = &tl_[thread_index]; // thread-local data
     if (block_scale <= PAGE_SCALE && tl->free_pages != NULL) {
         void *region = tl->free_pages;
         tl->free_pages = tl->free_pages->next;
@@ -122,7 +122,7 @@ static void *get_new_region (int block_scale) {
     TRACE("m1", "get_new_region: header %p (%p)", h, h - headers_);
     assert(h->scale == 0);
     h->scale = block_scale;
-    h->owner = tid_;
+    h->owner = thread_index;
 
     return region;
 }
@@ -148,7 +148,6 @@ void mem_init (void) {
 void nbd_free (void *x) {
     TRACE("m1", "nbd_free: block %p page %p", x, (size_t)x & ~MASK(PAGE_SCALE));
     ASSERT(x);
-    LOCALIZE_THREAD_LOCAL(tid_, int);
     block_t  *b = (block_t *)x;
     header_t *h = get_header(x);
     int b_scale = h->scale;
@@ -164,8 +163,9 @@ void nbd_free (void *x) {
 #ifndef NDEBUG
     memset(b, 0xcd, (1ULL << b_scale)); // bear trap
 #endif
-    tl_t *tl = &tl_[tid_]; // thread-local data
-    if (h->owner == tid_) {
+    int thread_index = GET_THREAD_INDEX();
+    tl_t *tl = &tl_[thread_index]; // thread-local data
+    if (h->owner == thread_index) {
         TRACE("m1", "nbd_free: private block, old free list head %p", tl->free_list[b_scale], 0);
 
 #ifndef RECYCLE_PAGES
@@ -264,8 +264,7 @@ void *nbd_malloc (size_t n) {
     if (EXPECT_FALSE(b_scale < MIN_SCALE)) { b_scale = MIN_SCALE; }
     if (EXPECT_FALSE(b_scale > MAX_SCALE)) { return NULL; }
 
-    LOCALIZE_THREAD_LOCAL(tid_, int);
-    tl_t *tl = &tl_[tid_]; // thread-local data
+    tl_t *tl = &tl_[GET_THREAD_INDEX()]; // thread-local data
 
     block_t *b = pop_free_list(tl, b_scale);
     if (b != NULL) {