1 /* 2 ** Zabbix 3 ** Copyright (C) 2001-2021 Zabbix SIA 4 ** 5 ** This program is free software; you can redistribute it and/or modify 6 ** it under the terms of the GNU General Public License as published by 7 ** the Free Software Foundation; either version 2 of the License, or 8 ** (at your option) any later version. 9 ** 10 ** This program is distributed in the hope that it will be useful, 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 ** GNU General Public License for more details. 14 ** 15 ** You should have received a copy of the GNU General Public License 16 ** along with this program; if not, write to the Free Software 17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 **/ 19 20 #ifndef ZABBIX_MUTEXS_H 21 #define ZABBIX_MUTEXS_H 22 23 #ifdef _WINDOWS 24 25 # define ZBX_MUTEX HANDLE 26 # define ZBX_MUTEX_NULL NULL 27 28 # define ZBX_MUTEX_NAME wchar_t * 29 30 # define ZBX_MUTEX_LOG zbx_mutex_create_per_process_name(L"ZBX_MUTEX_LOG") 31 # define ZBX_MUTEX_PERFSTAT zbx_mutex_create_per_process_name(L"ZBX_MUTEX_PERFSTAT") 32 33 #else /* not _WINDOWS */ 34 35 # define ZBX_MUTEX int 36 # define ZBX_MUTEX_NULL -1 37 38 # define ZBX_MUTEX_NAME int 39 40 # define ZBX_NO_MUTEX -1 41 # define ZBX_MUTEX_LOG 0 42 # define ZBX_MUTEX_CACHE 1 43 # define ZBX_MUTEX_TRENDS 2 44 # define ZBX_MUTEX_CACHE_IDS 3 45 # define ZBX_MUTEX_CONFIG 4 46 # define ZBX_MUTEX_SELFMON 5 47 # define ZBX_MUTEX_CPUSTATS 6 48 # define ZBX_MUTEX_DISKSTATS 7 49 # define ZBX_MUTEX_ITSERVICES 8 50 # define ZBX_MUTEX_VALUECACHE 9 51 # define ZBX_MUTEX_VMWARE 10 52 # define ZBX_MUTEX_SQLITE3 11 53 # define ZBX_MUTEX_PROCSTAT 12 54 # define ZBX_MUTEX_PROXY_HISTORY 13 55 # define ZBX_MUTEX_COUNT 14 56 57 # define ZBX_MUTEX_MAX_TRIES 20 /* seconds */ 58 59 #endif /* _WINDOWS */ 60 61 #define zbx_mutex_create(mutex, name) zbx_mutex_create_ext(mutex, name, 0) 62 #define zbx_mutex_create_force(mutex, name) zbx_mutex_create_ext(mutex, name, 1) 63 #define zbx_mutex_lock(mutex) __zbx_mutex_lock(__FILE__, __LINE__, mutex) 64 #define zbx_mutex_unlock(mutex) __zbx_mutex_unlock(__FILE__, __LINE__, mutex) 65 66 int zbx_mutex_create_ext(ZBX_MUTEX *mutex, ZBX_MUTEX_NAME name, unsigned char forced); 67 void __zbx_mutex_lock(const char *filename, int line, ZBX_MUTEX *mutex); 68 void __zbx_mutex_unlock(const char *filename, int line, ZBX_MUTEX *mutex); 69 int zbx_mutex_destroy(ZBX_MUTEX *mutex); 70 71 #ifdef _WINDOWS 72 ZBX_MUTEX_NAME zbx_mutex_create_per_process_name(const ZBX_MUTEX_NAME prefix); 73 #endif 74 75 #endif /* ZABBIX_MUTEXS_H */ 76