1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * lt-lock.h
4  * Copyright (C) 2011-2015 Akira TAGOH
5  *
6  * Authors:
7  *   Akira TAGOH  <akira@tagoh.org>
8  *
9  * You may distribute under the terms of either the GNU
10  * Lesser General Public License or the Mozilla Public
11  * License, as specified in the README file.
12  */
13 #ifndef __LT_LOCK_H__
14 #define __LT_LOCK_H__
15 
16 #if !defined (__LANGTAG_PRIVATE)
17 #error "Unable to use the private header publicly"
18 #endif
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #if HAVE_PTHREAD
25 #include <pthread.h>
26 #elif _WIN32
27 #include <windows.h>
28 #endif
29 #include "lt-macros.h"
30 
31 LT_BEGIN_DECLS
32 
33 #define LT_LOCK_DEFINE_STATIC(v)	static LT_LOCK_DEFINE(v)
34 #define LT_LOCK_NAME(v)			__lt_ ## name ## _lock
35 
36 #if HAVE_PTHREAD
37 #define LT_LOCK_DEFINE(v)		pthread_mutex_t LT_LOCK_NAME (v) = PTHREAD_MUTEX_INITIALIZER
38 #define LT_LOCK(v)			pthread_mutex_lock(&LT_LOCK_NAME (v))
39 #define LT_UNLOCK(v)			pthread_mutex_unlock(&LT_LOCK_NAME (v))
40 #elif _WIN32
41 #define LT_LOCK_DEFINE(v)		HANDLE LT_LOCK_NAME (v)
42 #define LT_LOCK(v)			LT_LOCK_NAME (v) = CreateMutex(NULL, FALSE, NULL)
43 #define LT_UNLOCK(v)			ReleaseMutex(LT_LOCK_NAME (v))
44 #else
45 #error No Mutex Lock available
46 #endif
47 
48 LT_END_DECLS
49 
50 #endif /* __LT_LOCK_H__ */
51