[io-layer] Move _wapi_getpid out of handles.c
[mono.git] / mono / io-layer / wapi.c
1
2 #include "wapi.h"
3
4 #include "handles-private.h"
5 #include "process-private.h"
6 #include "thread-private.h"
7
8 #include "mono/utils/mono-lazy-init.h"
9
10 gboolean _wapi_has_shut_down = FALSE;
11
12 void
13 wapi_init (void)
14 {
15         _wapi_handle_init ();
16         _wapi_shm_semaphores_init ();
17         _wapi_io_init ();
18         wapi_processes_init ();
19 }
20
21 void
22 wapi_cleanup (void)
23 {
24         g_assert (_wapi_has_shut_down == FALSE);
25         _wapi_has_shut_down = TRUE;
26
27         _wapi_error_cleanup ();
28         _wapi_thread_cleanup ();
29         wapi_processes_cleanup ();
30         _wapi_io_cleanup ();
31         _wapi_handle_cleanup ();
32 }
33
34 /* Use this instead of getpid(), to cope with linuxthreads.  It's a
35  * function rather than a variable lookup because we need to get at
36  * this before share_init() might have been called. */
37 static mono_lazy_init_t _wapi_pid_init_lazy = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
38 static pid_t _wapi_pid;
39
40 static void
41 _wapi_pid_init (void)
42 {
43         _wapi_pid = getpid ();
44 }
45
46 pid_t
47 _wapi_getpid (void)
48 {
49         mono_lazy_initialize (&_wapi_pid_init_lazy, _wapi_pid_init);
50         return _wapi_pid;
51 }