Release preparation, bump library version, makefile update for README
[nobug.git] / src / nobug_nothread.c
blob5acdeb506f724246d9035f861e8ab75ecb3ec1f4
1 /*
2 This file is part of the NoBug debugging library.
4 Copyright (C)
5 2007, 2008, 2009, 2010, Christian Thaeter <ct@pipapo.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, contact Christian Thaeter <ct@pipapo.org>.
20 #define NOBUG_LIBNOBUG_C
21 #include "nobug.h"
22 #include "llist.h"
26 Fake thread id's for non-threaded processes, only a single static one
28 static struct nobug_tls_data nothread_id = {
29 .thread_id = NULL,
30 .thread_num = 0,
31 .thread_gen = 0,
32 .data = NULL,
33 .coverage_disable_cnt = 0,
34 //struct llist_struct res_stack; /* resources of this thread */
37 struct nobug_tls_data*
38 nobug_thread_set (const char* name)
40 struct nobug_tls_data * tls = &nothread_id;
42 free ((char*)tls->thread_id);
43 ++tls->thread_gen;
45 char buf[256];
46 snprintf (buf, 256, "%s_%d", name, tls->thread_num);
47 tls->thread_id = strdup(buf);
48 if (!tls->thread_id)
50 nobug_log (&nobug_flag_nobug, LOG_EMERG, "NOBUG",
51 (const struct nobug_context){"-", 0, "nobug_thread_set"},
52 " failed thread id allocation");
53 abort();
56 return tls;
60 struct nobug_tls_data*
61 nobug_thread_get (void)
63 struct nobug_tls_data* tls = &nothread_id;
64 if (!tls->thread_id)
65 return nobug_thread_set ("thread");
67 return tls;
71 const char*
72 nobug_thread_id_set (const char* name)
74 return nobug_thread_set (name) -> thread_id;
78 const char*
79 nobug_thread_id_get (void)
81 return nobug_thread_get () -> thread_id;
85 void**
86 nobug_thread_data (void)
88 return &nobug_thread_get () -> data;