/* 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" #include "errors.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 #define WIN32_MEAN_AND_LEAN #include typedef CRITICAL_SECTION wolf_mutex_t; #define WOLF_MUTEX_DEFAULT_ATTR 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 ) { EnterCriticalSection( mutex ); } static INLINE void wolf_mutex_unlock( wolf_mutex_t *mutex ) { LeaveCriticalSection( mutex ); } #endif /* _WIN32 */ #ifdef __cplusplus } #endif /** @} */ /* @addtogroup wolf_threading */ #endif /* ifndef WOLF_MUTEX_H */