diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-30 18:11:19 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-30 18:11:19 +0200 |
commit | 181c176bc16d57a3dcb42b3657290ce1dbf7695f (patch) | |
tree | 226594c69e8a7d3035f9a2475bb512cb05168b0d /include | |
parent | 8c0d332229b887595d01e77a501cb6a986b70be6 (diff) | |
download | wolfbones-181c176bc16d57a3dcb42b3657290ce1dbf7695f.tar.gz wolfbones-181c176bc16d57a3dcb42b3657290ce1dbf7695f.tar.bz2 |
started to add thread stuff, mutexes first
Diffstat (limited to 'include')
-rw-r--r-- | include/wolf/mutex.h | 74 | ||||
-rw-r--r-- | include/wolf/port/sys.h | 1 |
2 files changed, 75 insertions, 0 deletions
diff --git a/include/wolf/mutex.h b/include/wolf/mutex.h new file mode 100644 index 0000000..63cd903 --- /dev/null +++ b/include/wolf/mutex.h @@ -0,0 +1,74 @@ +/* + Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com> + + 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 3 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef WOLF_MUTEX_H +#define WOLF_MUTEX_H + +/** + * @addtogroup wolf_threading Threading support + * @{ + */ + +/** + * @file mutex.h + * @brief Portable mutexes for thread synchronization + * @author Andreas Baumann <abaumann@yahoo.com> + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "port/sys.h" + +#ifdef HAVE_PTHREADS + +#include <pthread.h> /* for mutex functions */ +#include <assert.h> /* for assert */ + +typedef pthread_mutex_t wolf_mutex_t; + +#define WOLF_MUTEX_DEFAULT_ATTR PTHREAD_MUTEX_NORMAL + +wolf_error_t wolf_mutex_init( wolf_mutex_t *mutex ); +wolf_error_t wolf_mutex_destroy( wolf_mutex_t *mutex ); + +static inline void wolf_mutex_lock( wolf_mutex_t *mutex ) { + int res; + res = pthread_mutex_lock( mutex ); + assert( res == 0 ); +} + +static inline void wolf_mutex_unlock( wolf_mutex_t *mutex ) { + int res; + res = pthread_mutex_unlock( mutex ); + assert( res == 0 ); +} + +#endif /* HAVE_PTHREADS */ + +#ifdef _WIN32 + +#endif /* _WIN32 */ + +#ifdef __cplusplus +} +#endif + +/** @} */ /* @addtogroup wolf_threading */ + +#endif /* ifndef WOLF_MUTEX_H */ diff --git a/include/wolf/port/sys.h b/include/wolf/port/sys.h index 2d1faa7..fe0a174 100644 --- a/include/wolf/port/sys.h +++ b/include/wolf/port/sys.h @@ -47,6 +47,7 @@ #define HAVE_SYSLOG_H #define HAVE_GETADDRINFO #define HAVE_IPV6 +#define HAVE_PTHREADS #else #error unknown platform #endif /* defined OS_MINOR_VERSION == 6 */ |