[IOMultiplexerV2] dev snapshot
[NextIRCd.git] / src / IOInternal.h
1 /* IOInternal.h - IOMultiplexer v2
2  * Copyright (C) 2014  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17 #ifndef _IOInternal_h
18 #define _IOInternal_h
19 #ifndef _IOHandler_internals
20 #include "IOHandler.h"
21 #else
22
23 /* Multithreading */
24 #ifdef HAVE_PTHREAD_H
25 #include <pthread.h>
26 #ifdef PTHREAD_MUTEX_RECURSIVE_NP
27 #define PTHREAD_MUTEX_RECURSIVE_VAL PTHREAD_MUTEX_RECURSIVE_NP
28 #else
29 #define PTHREAD_MUTEX_RECURSIVE_VAL PTHREAD_MUTEX_RECURSIVE
30 #endif
31 #define IOTHREAD_MUTEX_INIT(var) { \
32     pthread_mutexattr_t mutex_attr; \
33     pthread_mutexattr_init(&mutex_attr);\
34     pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE_VAL);\
35     pthread_mutex_init(&var, &mutex_attr); \
36 }
37 #define IOSYNCHRONIZE(var) pthread_mutex_lock(&var)
38 #define IODESYNCHRONIZE(var) pthread_mutex_unlock(&var)
39 #else
40 #define IOTHREAD_MUTEX_INIT(var)
41 #define IOSYNCHRONIZE(var)
42 #define IODESYNCHRONIZE(var)
43 #endif
44
45
46 #define IOGC_FREE(NAME) void NAME(void *object)
47 typedef IOGC_FREE(iogc_free);
48 void iogc_add(void *object);
49 void iogc_add_callback(void *object, iogc_free *free_callback);
50
51 #endif
52 #endif