2 This file is part of the NoBug debugging library.
4 Copyright (C) 2007, 2008, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, contact Christian Thaeter <ct@pipapo.org>.
19 #define NOBUG_LIBNOBUG_C
23 pthread_mutex_t nobug_logging_mutex
= PTHREAD_MUTEX_INITIALIZER
;
29 pthread_key_t nobug_tls_key
;
30 static unsigned nobug_thread_cnt
= 0;
33 struct nobug_tls_data
*
34 nobug_thread_set (const char* name
)
37 snprintf (buf
, 256, "%s_%d", name
, ++nobug_thread_cnt
);
38 struct nobug_tls_data
* tls
= pthread_getspecific (nobug_tls_key
);
41 tls
= malloc (sizeof *tls
);
43 tls
->thread_id
= strdup(buf
);
45 if (!tls
->thread_id
) abort();
46 llist_init (&tls
->res_stack
);
47 pthread_setspecific (nobug_tls_key
, tls
);
51 //TODO assert that the thread holds no resources when the id gets reset
52 free ((char*)tls
->thread_id
);
53 tls
->thread_id
= strdup(buf
);
54 if (!tls
->thread_id
) abort();
55 llist_init (&tls
->res_stack
);
62 struct nobug_tls_data
*
63 nobug_thread_get (void)
65 struct nobug_tls_data
* tls
= pthread_getspecific (nobug_tls_key
);
67 return nobug_thread_set ("thread");
74 nobug_thread_id_set (const char* name
)
76 return nobug_thread_set (name
) -> thread_id
;
81 nobug_thread_id_get (void)
83 return nobug_thread_get () -> thread_id
;
88 nobug_thread_data (void)
90 return &nobug_thread_get () -> data
;