diff options
Diffstat (limited to 'mbglib/common/mbgmutex.h')
-rw-r--r-- | mbglib/common/mbgmutex.h | 67 |
1 files changed, 45 insertions, 22 deletions
diff --git a/mbglib/common/mbgmutex.h b/mbglib/common/mbgmutex.h index e9f8a51..b8e1ae8 100644 --- a/mbglib/common/mbgmutex.h +++ b/mbglib/common/mbgmutex.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgmutex.h 1.1 2011/04/15 12:26:59 martin REL_M $ + * $Id: mbgmutex.h 1.3.1.2 2014/03/04 12:08:12 martin TEST $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -11,6 +11,16 @@ * * ----------------------------------------------------------------------- * $Log: mbgmutex.h $ + * Revision 1.3.1.2 2014/03/04 12:08:12 martin + * Revision 1.3.1.1 2014/01/08 17:20:57Z martin + * MBG_TGT_POSIX + * Revision 1.3 2013/04/11 13:46:58 martin + * Use non-specific spinlock function under Windows. + * Revision 1.2 2012/03/08 12:19:01Z martin + * Fixes for Linux kernel and FreeBSD. + * Fixed build under DOS and QNX usinc dummy defines. + * Don't define macros for semaphore destroy functions + * if not required/supported on the target OS. * Revision 1.1 2011/04/15 12:26:59 martin * Initial revision. * @@ -41,16 +51,16 @@ typedef KSPIN_LOCK MBG_SPINLOCK; #define _mbg_spin_lock_init( _spl ) KeInitializeSpinLock( _spl ) - #define _mbg_spin_lock_destroy( _spl ) _nop_macro_fnc() - #define _mbg_spin_lock_acquire( _spl ) KeAcquireSpinLockAtDpcLevel( _spl ) - #define _mbg_spin_lock_release( _spl ) KeReleaseSpinLockFromDpcLevel( _spl ) + // _mbg_spin_lock_destroy is not supported + #define _mbg_spin_lock_acquire( _spl ) KeAcquireSpinLock( _spl, &OldIrql ) + #define _mbg_spin_lock_release( _spl ) KeReleaseSpinLock( _spl, OldIrql ) - #define MBG_SPINLOCK_DEFINED 1 + #define _MBG_SPINLOCK_DEFINED 1 typedef FAST_MUTEX MBG_MUTEX; #define _mbg_mutex_init( _pmtx ) ExInitializeFastMutex( _pmtx ) - #define _mbg_mutex_destroy( _pmtx ) _nop_macro_fnc() + // _mbg_mutex_destroy( _pmtx ) is not supported #define _mbg_mutex_acquire( _pmtx ) ExAcquireFastMutex( _pmtx ) #define _mbg_mutex_release( _pmtx ) ExReleaseFastMutex( _pmtx ) @@ -59,20 +69,26 @@ #elif defined( MBG_TGT_LINUX ) // Linux kernel space #include <linux/spinlock.h> - #include <asm/semaphore.h> + #include <linux/version.h> + + #if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 26 ) ) + #include <linux/semaphore.h> + #else + #include <asm/semaphore.h> + #endif typedef spinlock_t MBG_SPINLOCK; #define _mbg_spin_lock_init( _spl ) spin_lock_init( _spl ) - #define _mbg_spin_lock_destroy( _spl ) _nop_macro_fnc() + // _mbg_spin_lock_destroy is not supported #define _mbg_spin_lock_acquire( _spl ) spin_lock( _spl ) #define _mbg_spin_lock_release( _spl ) spin_unlock( _spl ) - #define MBG_SPINLOCK_DEFINED 1 + #define _MBG_SPINLOCK_DEFINED 1 typedef struct semaphore MBG_MUTEX; #define _mbg_mutex_init( _pmtx ) sema_init( _pmtx, 1 ) - #define _mbg_mutex_destroy( _pmtx ) _nop_macro_fnc() + // _mbg_mutex_destroy( _pmtx ) is not supported #define _mbg_mutex_acquire( _pmtx ) down_interruptible( _pmtx ) #define _mbg_mutex_release( _pmtx ) up( _pmtx ) @@ -80,6 +96,7 @@ #elif defined( MBG_TGT_FREEBSD ) // FreeBSD kernel space + #include <sys/lock.h> #include <sys/mutex.h> typedef struct mtx MBG_SPINLOCK; @@ -88,7 +105,7 @@ #define _mbg_spin_lock_acquire( _spl ) mtx_lock_spin( _spl ) #define _mbg_spin_lock_release( _spl ) mtx_unlock_spin( _spl ) - #define MBG_SPINLOCK_DEFINED 1 + #define _MBG_SPINLOCK_DEFINED 1 typedef struct mtx MBG_MUTEX; @@ -112,7 +129,7 @@ #define _mbg_spin_lock_acquire( _spl ) mutex_spin_enter( _spl ) #define _mbg_spin_lock_release( _spl ) mutex_spin_exit( _spl ) - #define MBG_SPINLOCK_DEFINED 1 + #define _MBG_SPINLOCK_DEFINED 1 typedef kmutex_t MBG_MUTEX; @@ -129,8 +146,6 @@ #if defined( MBG_TGT_WIN32 ) // Windows user space - #include <windows.h> - // definitions used with mutexes typedef HANDLE MBG_MUTEX; #define _mbg_mutex_init( _pm ) *(_pm) = CreateMutex( NULL, FALSE, NULL ) @@ -149,7 +164,7 @@ #define _MBG_CRIT_SECT_DEFINED 1 - #elif defined( MBG_TGT_UNIX ) // Unix user space use pthread library + #elif defined( MBG_TGT_POSIX ) // Unix user space use pthread library #include <pthread.h> @@ -167,15 +182,21 @@ // For critical sections use defaults specified below + #elif defined( MBG_TGT_DOS ) || defined( MBG_TGT_QNX ) + + typedef int MBG_MUTEX; // just a dummy declaration + + #define _MBG_MUTEX_DEFINED 1 + #endif #endif -#if !defined( MBG_SPINLOCK_DEFINED ) +#if !defined( _MBG_SPINLOCK_DEFINED ) #define _mbg_spin_lock_init( _spl ) _nop_macro_fnc() - #define _mbg_spin_lock_destroy( _spl ) _nop_macro_fnc() + // _mbg_spin_lock_destroy is not supported #define _mbg_spin_lock_acquire( _spl ) _nop_macro_fnc() #define _mbg_spin_lock_release( _spl ) _nop_macro_fnc() @@ -189,7 +210,7 @@ typedef MBG_CRIT_SECT MBG_MUTEX; #define _mbg_mutex_init( _pm ) _nop_macro_fnc() - #define _mbg_mutex_destroy( _pm ) _nop_macro_fnc() + // _mbg_mutex_destroy( _pmtx ) is not supported #define _mbg_mutex_acquire( _pm ) _nop_macro_fnc() #define _mbg_mutex_release( _pm ) _nop_macro_fnc() @@ -203,10 +224,12 @@ #define _MBG_CRIT_SECT_DEFINED 1 typedef MBG_MUTEX MBG_CRIT_SECT; - #define _mbg_crit_sect_init _mbg_mutex_init - #define _mbg_crit_sect_destroy _mbg_mutex_destroy - #define _mbg_crit_sect_enter _mbg_mutex_acquire - #define _mbg_crit_sect_leave _mbg_mutex_release + #define _mbg_crit_sect_init _mbg_mutex_init + #if defined( _mbg_mutex_destroy ) + #define _mbg_crit_sect_destroy _mbg_mutex_destroy + #endif + #define _mbg_crit_sect_enter _mbg_mutex_acquire + #define _mbg_crit_sect_leave _mbg_mutex_release #endif |