xref: /netbsd-src/external/gpl3/binutils/dist/gprofng/libcollector/tsd.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
2    Contributed by Oracle.
3 
4    This file is part of GNU Binutils.
5 
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 3, or (at your option)
9    any later version.
10 
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.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, 51 Franklin Street - Fifth Floor, Boston,
19    MA 02110-1301, USA.  */
20 
21 /* Thread-specific data */
22 
23 #ifndef _TSD_H
24 #define _TSD_H
25 
26 #include <sys/types.h>
27 
28 int __collector_tsd_init ();
29 /* Function: Init tsd module.  Call once before using other functions.
30    MT-Level: Unsafe
31    Return:   0 if successful
32  */
33 
34 void __collector_tsd_fini ();
35 /* Function: Shutdown tsd module.
36    MT-Level: Unsafe
37    Return:   None
38  */
39 
40 void __collector_tsd_fork_child_cleanup ();
41 /* Function: Reset tsd module.  Call immediately after fork() in child process.
42    MT-Level: Unsafe
43    Return:   None
44  */
45 
46 int __collector_tsd_allocate ();
47 /* Function: Allocate thread info.
48 	     Call from threads before using tsd_get_by_key().
49 	     Call from main thread should be made before calls from other threads.
50    MT-Level: First call is unsafe.  Safe afterwards.
51    Return:   0 if successful
52  */
53 
54 void __collector_tsd_release ();
55 /* Function: Free thread info.
56 	     Call from threads just before thread termination.
57    MT-Level: Safe
58    Return:   None
59  */
60 
61 #define COLLECTOR_TSD_INVALID_KEY ((unsigned)-1)
62 unsigned __collector_tsd_create_key (size_t memsize, void (*init)(void*), void (*fini)(void*));
63 /* Function: Reserve TDS memory.
64    MT-Level: Unsafe
65    Inputs:   <memsize>: number of bytes to reserve
66 	     <init>: key memory initialization.  Must be callable even if
67 		     the associated thread has not yet been created.
68 	     <fini>: key memory finalization.  Must be callable even if
69 		     the associated thread has been terminated.
70    Return:   key or COLLECTOR_TSD_INVALID_KEY if not successful.
71  */
72 
73 void *__collector_tsd_get_by_key (unsigned key);
74 /* Function: Get TSD memory.
75 	     Call from threads after calling tsd_allocate().
76    MT-Level: Safe
77    Inputs:   <key>: return value from tsd_create_key()
78    Return:   memory if successful, NULL otherwise
79  */
80 #endif /* _TSD_H */
81