7ec70b1b525ed33b8806928fb09cb8bd82af6f95
[platform/upstream/libusb.git] / libusb / os / threads_posix.h
1 /*
2  * libusb synchronization using POSIX Threads
3  *
4  * Copyright © 2010 Peter Stuge <peter@stuge.se>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #ifndef LIBUSB_THREADS_POSIX_H
22 #define LIBUSB_THREADS_POSIX_H
23
24 #include <pthread.h>
25 #ifdef HAVE_SYS_TIME_H
26 #include <sys/time.h>
27 #endif
28
29 #define usbi_mutex_static_t             pthread_mutex_t
30 #define USBI_MUTEX_INITIALIZER          PTHREAD_MUTEX_INITIALIZER
31 #define usbi_mutex_static_lock          pthread_mutex_lock
32 #define usbi_mutex_static_unlock        pthread_mutex_unlock
33
34 #define usbi_mutex_t                    pthread_mutex_t
35 #define usbi_mutex_init(mutex)          pthread_mutex_init((mutex), NULL)
36 #define usbi_mutex_lock                 pthread_mutex_lock
37 #define usbi_mutex_unlock               pthread_mutex_unlock
38 #define usbi_mutex_trylock              pthread_mutex_trylock
39 #define usbi_mutex_destroy              pthread_mutex_destroy
40
41 #define usbi_cond_t                     pthread_cond_t
42 #define usbi_cond_init(cond)            pthread_cond_init((cond), NULL)
43 #define usbi_cond_wait                  pthread_cond_wait
44 #define usbi_cond_broadcast             pthread_cond_broadcast
45 #define usbi_cond_destroy               pthread_cond_destroy
46
47 #define usbi_tls_key_t                  pthread_key_t
48 #define usbi_tls_key_create(key)        pthread_key_create((key), NULL)
49 #define usbi_tls_key_get                pthread_getspecific
50 #define usbi_tls_key_set                pthread_setspecific
51 #define usbi_tls_key_delete             pthread_key_delete
52
53 int usbi_cond_timedwait(pthread_cond_t *cond,
54         pthread_mutex_t *mutex, const struct timeval *tv);
55
56 int usbi_get_tid(void);
57
58 #endif /* LIBUSB_THREADS_POSIX_H */