summaryrefslogtreecommitdiffstats
path: root/include/mutexs.h
blob: 83c5075bef7bfe0f29b8945e7c9c959b11ef4810 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* 
** ZABBIX
** Copyright (C) 2000-2005 SIA Zabbix
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/

#ifndef ZABBIX_MUTEXS_H
#define ZABBIX_MUTEXS_H

#if defined(_WINDOWS)

#	define ZBX_MUTEX		HANDLE
#	define ZBX_MUTEX_ERROR		(0)
#	define ZBX_MUTEX_OK		(1)

#	define ZBX_MUTEX_NAME		char*

#	define ZBX_MUTEX_LOG    	"ZBX_MUTEX_LOG"
#	define ZBX_MUTEX_NODE_SYNC    	"ZBX_MUTEX_NODE_SYNC"

#else /* not _WINDOWS */

#	define ZBX_MUTEX		int

#	define ZBX_MUTEX_ERROR		(-1)
#	define ZBX_MUTEX_OK		(1)
	
#	define ZBX_MUTEX_NAME		int

#	define ZBX_MUTEX_LOG		0
#	define ZBX_MUTEX_NODE_SYNC	1
#	define ZBX_MUTEX_CACHE		2
/* This has to be the last MUTEX in the list with MAX number */
#	define ZBX_MUTEX_COUNT		3

#	define ZBX_MUTEX_MAX_TRIES	20 /* seconds */

#	if defined(HAVE_SQLITE3)

#	endif

#endif /* _WINDOWS */

#define zbx_mutex_create(mutex, name)		zbx_mutex_create_ext(mutex, name, 0)
#define zbx_mutex_create_force(mutex, name)	zbx_mutex_create_ext(mutex, name, 1)
int zbx_mutex_create_ext(ZBX_MUTEX	*mutex, ZBX_MUTEX_NAME name, unsigned char forced);
int zbx_mutex_lock(ZBX_MUTEX	*mutex);
int zbx_mutex_unlock(ZBX_MUTEX	*mutex);
int zbx_mutex_destroy(ZBX_MUTEX	*mutex);

/*********************************************************/
/*** PHP Semaphore functions using System V semaphores ***/
/*********************************************************/

#define PHP_MUTEX_OK	1
#define PHP_MUTEX_ERROR	0

typedef struct {
	int semid;
	int count;
} PHP_MUTEX;

#if defined(HAVE_SQLITE3) && !defined(_WINDOWS)

int php_sem_get(PHP_MUTEX* sem_ptr, char* path_name);
int php_sem_acquire(PHP_MUTEX* sem_ptr);
int php_sem_release(PHP_MUTEX* sem_ptr);
int php_sem_remove(PHP_MUTEX* sem_ptr);

#else /* !HAVE_SQLITE3 || _WINDOWS */

#	define php_sem_get(sem_ptr, path_name) PHP_MUTEX_OK
#	define php_sem_acquire(sem_ptr)        PHP_MUTEX_OK
#	define php_sem_release(sem_ptr)        PHP_MUTEX_OK
#	define php_sem_remove(sem_ptr)         PHP_MUTEX_OK

#endif  /* HAVE_SQLITE3 && !_WINDOWS */

#endif /* ZABBIX_MUTEXS_H */