Changeset: 106fef9bd7ae for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/106fef9bd7ae
Modified Files:
        gdk/gdk_system.c
        gdk/gdk_system.h
Branch: resource_management
Log Message:

create tls allocator on thread creation


diffs (83 lines):

diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -195,7 +195,7 @@ struct thread_funcs {
 };
 
 struct mtthread {
-       allocator *thread_allocator;
+       allocator *ma;
        struct mtthread *next;
        void (*func) (void *);  /* function to be called */
        void *data;             /* and its data */
@@ -366,15 +366,18 @@ static void
 rm_mtthread(struct mtthread *t)
 {
        struct mtthread **pt;
+       allocator *ta = t->ma;
 
        assert(t != &mainthread);
        thread_lock();
+       t->ma = NULL;
        for (pt = &mtthreads; *pt && *pt != t; pt = &(*pt)->next)
                ;
        if (*pt)
                *pt = t->next;
        free(t);
        thread_unlock();
+       sa_destroy(ta);
 }
 
 bool
@@ -573,14 +576,14 @@ MT_thread_getfreebats(void)
 }
 
 void
-MT_thread_setallocator(allocator *allocator)
+MT_thread_setallocator(allocator *ma)
 {
        if (!thread_initialized)
                return;
        struct mtthread *self = thread_self();
 
        if (self)
-               self->thread_allocator = allocator;
+               self->ma = ma;
 }
 
 allocator *
@@ -590,7 +593,7 @@ MT_thread_getallocator(void)
                return NULL;
        struct mtthread *self = thread_self();
 
-       return self ? self->thread_allocator : NULL;
+       return self ? self->ma : NULL;
 }
 
 void
@@ -969,7 +972,13 @@ MT_create_thread(MT_Id *t, void (*f) (vo
                .exited = ATOMIC_VAR_INIT(0),
                .working = ATOMIC_PTR_VAR_INIT(NULL),
                .semawait = ATOMIC_PTR_VAR_INIT(NULL),
+               .ma = create_allocator(NULL, threadname, false),
        };
+       if (self->ma == NULL) {
+               free(self);
+               GDKerror("Creating thread allocator failed\n");
+               return -1;
+       }
        MT_lock_set(&thread_init_lock);
        /* remember the list of callback functions we need to call for
         * this thread (i.e. anything registered so far) */
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -185,7 +185,7 @@ gdk_export bool MT_thread_register(void)
 gdk_export void MT_thread_deregister(void);
 gdk_export const char *MT_thread_getname(void);
 gdk_export allocator *MT_thread_getallocator(void);
-gdk_export void MT_thread_setallocator(allocator *allocator);
+gdk_export void MT_thread_setallocator(allocator *ma);
 gdk_export void *MT_thread_getdata(void);
 gdk_export void MT_thread_setdata(void *data);
 gdk_export void MT_exiting_thread(void);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to