From 181c176bc16d57a3dcb42b3657290ce1dbf7695f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 30 Mar 2009 18:11:19 +0200 Subject: started to add thread stuff, mutexes first --- include/wolf/mutex.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ include/wolf/port/sys.h | 1 + 2 files changed, 75 insertions(+) create mode 100644 include/wolf/mutex.h (limited to 'include') 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 + + 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 . +*/ + +#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 + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "port/sys.h" + +#ifdef HAVE_PTHREADS + +#include /* for mutex functions */ +#include /* 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 */ -- cgit v1.2.3-54-g00ecf