#ifndef MPLIB1_BPO_LOCK_INTERNAL #define MPLIB1_BPO_LOCK_INTERNAL /* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/include/bpo_lock_internal.h,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:49 $ * $Revision: 1.2 $ * ******************************************************************************* * * Change History * * $Log: bpo_lock_internal.h,v $ * Revision 1.2 2002/10/07 09:37:49 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:36:50 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/include/bpo_lock_internal.h,v 1.2 2002/10/07 09:37:49 mpoole Exp $" #ifndef MPLIB1_CONFIG #include #endif #ifndef MPLIB1_BPO_LOCK #include #endif /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ structures ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ function definitions ------------------------------------------------------------------ */ /* Only one of the following ifdef blocks should be enabled */ #ifdef HAVE_LWP_MUTEX #define Xchg(a) _lwp_mutex_trylock(a) #define Clr(a) _lwp_mutex_unlock(a) #endif #ifdef HAVE_PTHREADS /* No explicit defines needed */ #endif #ifdef HAVE_MSEM /* XPG4 varient */ /*#define Xchg(a) msem_lock(a,0)*/ /*#define Clr(a) msem_unlock(a)*/ #endif #ifdef HAVE_MUTEX #define Xchg(a) acquire_lock(a) #define Clr(a) release_lock(a) #define Lckval(a) ((long)(a->abi_lock)) #endif #ifdef HAVE_SYS_ATOMIC #include #define Xchg(a) atomic_xchg_long((long *)a,1) #define Clr(a) atomic_xchg_long((long *)a,0) #define Lckval(a) ((long)(*(long *)a)) #endif #ifdef HAVE_LINUX_BITOPS #include /* a more recent linux set of operations */ #define Xchg(a) test_and_set_bit(0,a) #define Clr(a) test_and_clear_bit(0,a) #define Lckval(a) test_bit(0,a) #else #ifdef HAVE_GCC_I386 /* The following was swiped from in the linux distribution */ /* * Some hacks to defeat gcc over-optimizations.. */ struct __dummy { unsigned long a[100]; }; #define ADDR (*(struct __dummy *) addr) __inline__ static int Xchg(volatile void * addr) { int oldbit; __asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0" :"=r" (oldbit),"=m" (ADDR) :"r" (0)); return oldbit; } __inline__ static int Clr( volatile void * addr) { int oldbit; __asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0" :"=r" (oldbit),"=m" (ADDR) :"r" (0)); return oldbit; } #define Lckval(a) ((long)(*a)) #endif #endif #ifdef HAVE_SVR4_I386 /* The following were grabbed from on NCR 3000 */ asm int Xchg(lp) { % mem lp; movl lp,%eax xchgl %eax,(%eax) } asm void Clr(lp) { % mem lp; movl lp,%eax movl $0,(%eax) % reg lp; movl $0,(lp) } #define Lckval(a) ((long)(*a)) #endif #ifdef HAVE_SVR4_I386B /* The following was grabbed from on Sequent Ptx4.2.0 */ /* * atomic_xchg_long * * Atomically exchange the specified value with that at the specified * address, returning the old value. * The only reason for having both atomic_xchg_*() and atomic_xchg_u*() * primitives is to keep the compiler and lint happy without huge * numbers of error-hiding casts. * * Parameters: * long *longptr; Address of long to exchange * long newval; New value to exchange into *longptr. */ #ifdef __STDC__ __asm long atomic_xchg_long(volatile long *const longptr, long const newval) #else asm long atomic_xchg_long(longptr, newval) #endif { %con longptr, newval; movl longptr, %ecx /* Get addr to known register. */ movl newval, %eax /* Get new value to known register. */ xchgl %eax, (%ecx) /* Perform the exchange. */ %con longptr; mem newval; movl longptr, %ecx /* Get addr to known register. */ movl newval, %eax /* Get new value to known register. */ xchgl %eax, (%ecx) /* Perform the exchange. */ %mem longptr; con newval; movl longptr, %ecx /* Get addr to known register. */ movl newval, %eax /* Get new value to known register. */ xchgl %eax, (%ecx) /* Perform the exchange. */ %mem longptr, newval; movl longptr, %ecx /* Get addr to known register. */ movl newval, %eax /* Get new value to known register. */ xchgl %eax, (%ecx) /* Perform the exchange. */ } #define Xchg(a) atomic_xchg_long((long *)a,1) #define Clr(a) atomic_xchg_long((long *)a,0) #define Lckval(a) ((long)(*(long *)a)) #endif #endif /* -- End of File -- */