fix package.xml
[m6w6/ext-psi] / src / debug.c
1 /*******************************************************************************
2 Copyright (c) 2018, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #else
29 # include "php_config.h"
30 #endif
31
32 #include "php.h"
33 #include "debug.h"
34
35 #if PSI_THREADED_PARSER
36
37 # include <pthread.h>
38
39 static pthread_mutex_t debug_mutex;
40 static pthread_mutexattr_t debug_attr;
41
42 void psi_debug_lock(struct psi_data *data)
43 {
44 pthread_mutex_lock(&debug_mutex);
45 }
46
47 void psi_debug_unlock(struct psi_data *data)
48 {
49 pthread_mutex_unlock(&debug_mutex);
50 }
51
52 #endif
53
54 PHP_MINIT_FUNCTION(psi_debug);
55 PHP_MINIT_FUNCTION(psi_debug)
56 {
57 #if PSI_THREADED_PARSER
58 pthread_mutexattr_init(&debug_attr);
59 pthread_mutexattr_settype(&debug_attr, PTHREAD_MUTEX_RECURSIVE);
60 pthread_mutex_init(&debug_mutex, &debug_attr);
61 #endif
62
63 return 0;
64 }
65
66 PHP_MSHUTDOWN_FUNCTION(psi_debug);
67 PHP_MSHUTDOWN_FUNCTION(psi_debug)
68 {
69 #if PSI_THREADED_PARSER
70 pthread_mutex_destroy(&debug_mutex);
71 pthread_mutexattr_destroy(&debug_attr);
72 #endif
73
74 return 0;
75 }