o hopefully fixed missing functions with sunos 5.10 or higher

o removed unused trash files which somehow reappeared after rebase
This commit is contained in:
Jeff Hill
2011-09-02 18:18:46 -06:00
parent 1ff2408ba4
commit fd10e77518
3 changed files with 12 additions and 289 deletions

View File

@@ -1,154 +0,0 @@
/*************************************************************************\
* Copyright (c) 2011 LANS LLC, as Operator of
* Los Alamos National Laboratory.
* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author Jeffrey O. Hill
* johill@lanl.gov
*
* Provide a global mutex version of the atomic functions for when
* we dont have more efficent OS primitives or compiler intriniscs
* to use instead.
*
* We implement these mutex-based primitives upon the libCom private
* interface epicsMutexOsdXxxx because, in libCom, it is convenient
* to make this a standalone primitive upon which we can implement
* epicsMutex.
*/
#define epicsExportSharedSymbols
#include "epicsAtomic.h"
#include "epicsThread.h"
#include "epicsMutex.h"
namespace {
class AtomicGuard {
public:
AtomicGuard ();
~AtomicGuard ();
private:
static epicsMutexOSD * m_pMutex;
static epicsThreadOnceId m_onceFlag;
static void m_once ( void * );
};
//
// c++ 0x specifies the behavior for concurrent
// access to block scope statics but some compiler
// writers, lacking clear guidance in the earlier
// c++ standards, curiously implement thread unsafe
// block static variables despite ensuring for
// proper multithreaded behavior for many other
// parst of the compiler infrastructure such as
// runtime support for exception handling
//
// since this is potentially used by the implementation
// of staticInstance we cant use it here and must use
// epicsThreadOnce despite its perfomance pentalty
//
// using epicsThreadOnce here (at this time) increases
// the overhead of AtomicGuard by as much as 100%
//
epicsMutexOSD * AtomicGuard :: m_pMutex = 0;
epicsThreadOnceId AtomicGuard :: m_onceFlag = EPICS_THREAD_ONCE_INIT;
void AtomicGuard :: m_once ( void * )
{
m_pMutex = epicsMutexOsdCreate ();
}
inline AtomicGuard :: AtomicGuard ()
{
epicsThreadOnce ( & m_onceFlag, m_once, 0 );
const int status = epicsMutexOsdLock ( m_pMutex );
assert ( status == epicsMutexLockOK );
}
inline AtomicGuard :: ~AtomicGuard ()
{
epicsMutexOsdUnlock ( m_pMutex );
}
} // end of anonymous namespace
extern "C" {
size_t epicsLockedIncrSizeT ( size_t * pTarget )
{
AtomicGuard atomicGuard;
return ++(*pTarget);
}
size_t epicsLockedDecrSizeT ( size_t * pTarget )
{
AtomicGuard atomicGuard;
return --(*pTarget);
}
void epicsLockedSetSizeT ( size_t * pTarget, size_t newVal )
{
AtomicGuard atomicGuard;
*pTarget = newVal;
}
void epicsLockedSetUIntT ( unsigned * pTarget, unsigned newVal )
{
AtomicGuard atomicGuard;
*pTarget = newVal;
}
void epicsLockedSetPtrT ( EpicsAtomicPtrT * pTarget, EpicsAtomicPtrT newVal )
{
AtomicGuard atomicGuard;
*pTarget = newVal;
}
unsigned epicsLockedGetUIntT ( const unsigned * pTarget )
{
AtomicGuard atomicGuard;
return *pTarget;
}
size_t epicsLockedGetSizeT ( const size_t * pTarget )
{
AtomicGuard atomicGuard;
return *pTarget;
}
EpicsAtomicPtrT epicsLockedGetPtrT ( const EpicsAtomicPtrT * pTarget )
{
AtomicGuard atomicGuard;
return *pTarget;
}
unsigned epicsLockedCmpAndSwapUIntT ( unsigned * pTarget,
unsigned oldval, unsigned newval )
{
AtomicGuard atomicGuard;
const unsigned cur = *pTarget;
if ( cur == oldval ) {
*pTarget = newval;
}
return cur;
}
EpicsAtomicPtrT epicsLockedCmpAndSwapPtrT ( EpicsAtomicPtrT * pTarget,
EpicsAtomicPtrT oldval, EpicsAtomicPtrT newval )
{
AtomicGuard atomicGuard;
const EpicsAtomicPtrT cur = *pTarget;
if ( cur == oldval ) {
*pTarget = newval;
}
return cur;
}
} // end of extern "C"

View File

@@ -1,118 +0,0 @@
/*************************************************************************\
* Copyright (c) 2011 LANS LLC, as Operator of
* Los Alamos National Laboratory.
* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author Jeffrey O. Hill
* johill@lanl.gov
*/
//
// The epicsAtomicXxxxx functions herein are implemented with C++ but directly
// callable by C code, and therefore they must not be instantiated inline.
// Therefore, this isnt a traditional header file because it has function
// definitions that are not inline, and must therefore be included by only
// one module in the executable - typically this is the epicsAtomicOSD
// c++ source file. These out-of-line function definitions are placed in a
// header file so that there is potential code reuse when instantiating for
// a specific OS. An alternative option would have been to place these
// function definitions in a OS type conditionally compiled source file
// but this wasnt done because I suspect that selecting the posix version
// would require a proliferation of "SRCS_XXXX += xxx.cpp" in the libCom
// Makefile for every variety of Unix (a maintenance headache when new
// varieties of UNIX are configured).
//
// Aee also the comments in epicsAtomicGuard header.
//
#ifndef epicsAtomicLocked_h
#define epicsAtomicLocked_h
#ifndef __cplusplus
# error epicsAtomicLocked.h is intended only for use only by C++ code
#endif
#include "epicsAtomic.h" // always cross check the function prototypes
#include "epicsAtomicGuard.h"
extern "C" {
size_t epicsAtomicIncrSizeT ( size_t * pTarget )
{
AtomicGuard atomicGuard;
return ++(*pTarget);
}
size_t epicsAtomicDecrSizeT ( size_t * pTarget )
{
AtomicGuard atomicGuard;
return --(*pTarget);
}
void epicsAtomicSetSizeT ( size_t * pTarget, size_t newVal )
{
AtomicGuard atomicGuard;
*pTarget = newVal;
}
void epicsAtomicSetUIntT ( unsigned * pTarget, unsigned newVal )
{
AtomicGuard atomicGuard;
*pTarget = newVal;
}
void epicsAtomicSetPtrT ( EpicsAtomicPtrT * pTarget, EpicsAtomicPtrT newVal )
{
AtomicGuard atomicGuard;
*pTarget = newVal;
}
unsigned epicsAtomicGetUIntT ( const unsigned * pTarget )
{
AtomicGuard atomicGuard;
return *pTarget;
}
size_t epicsAtomicGetSizeT ( const size_t * pTarget )
{
AtomicGuard atomicGuard;
return *pTarget;
}
EpicsAtomicPtrT epicsAtomicGetPtrT ( const EpicsAtomicPtrT * pTarget )
{
AtomicGuard atomicGuard;
return *pTarget;
}
unsigned epicsAtomicCmpAndSwapUIntT ( unsigned * pTarget,
unsigned oldval, unsigned newval )
{
AtomicGuard atomicGuard;
const unsigned cur = *pTarget;
if ( cur == oldval ) {
*pTarget = newval;
}
return cur;
}
EpicsAtomicPtrT epicsAtomicCmpAndSwapPtrT ( EpicsAtomicPtrT * pTarget,
EpicsAtomicPtrT oldval, EpicsAtomicPtrT newval )
{
AtomicGuard atomicGuard;
const EpicsAtomicPtrT cur = *pTarget;
if ( cur == oldval ) {
*pTarget = newval;
}
return cur;
}
} // end of extern "C"
#endif /* epicsAtomicLocked_h */

View File

@@ -21,7 +21,7 @@
/*
* atomic.h exists only in Solaris 10 or higher
*/
#include <sys/atomic.h>
#include <atomic.h>
#include "epicsAssert.h"
@@ -63,9 +63,8 @@ EPICS_ATOMIC_INLINE size_t epicsAtomicCmpAndSwapSizeT (
size_t * pTarget,
size_t oldVal, size_t newVal )
{
STATIC_ASSERT ( sizeof ( void * ) == sizeof ( size_t ) );
void ** const ppPtr = (void **) pTarget;
return ( size_t ) atomic_cas_ptr ( ppPtr, ( void * )oldVal, ( void * )newVal );
STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
return atomic_cas_ulong ( pTarget, oldVal, newVal );
}
#endif
@@ -94,9 +93,8 @@ EPICS_ATOMIC_INLINE int epicsAtomicIncrIntT ( int * pTarget )
#define EPICS_ATOMIC_INCR_SIZET
EPICS_ATOMIC_INLINE size_t epicsAtomicIncrSizeT ( size_t * pTarget )
{
STATIC_ASSERT ( sizeof ( void * ) == sizeof ( size_t ) );
void ** const ppTarg = ( void ** ) ( pTarget );
return ( size_t ) atomic_inc_ptr_nv ( ppTarg );
STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
return atomic_inc_ulong_nv ( pTarget );
}
#endif
@@ -114,9 +112,8 @@ EPICS_ATOMIC_INLINE int epicsAtomicDecrIntT ( int * pTarget )
#define EPICS_ATOMIC_DECR_SIZET
EPICS_ATOMIC_INLINE size_t epicsAtomicDecrSizeT ( size_t * pTarget )
{
STATIC_ASSERT ( sizeof ( void * ) == sizeof ( size_t ) );
void ** const pTarg = ( void ** ) ( pTarget );
return ( size_t ) atomic_dec_ptr_nv ( pTarg );
STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
return atomic_dec_ulong_nv ( pTarget );
}
#endif
@@ -135,9 +132,8 @@ EPICS_ATOMIC_INLINE int epicsAtomicAddIntT ( int * pTarget, int delta )
EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT ( size_t * pTarget,
size_t delta )
{
STATIC_ASSERT ( sizeof ( void * ) == sizeof ( size_t ) );
void ** const pTarg = ( void ** ) ( pTarget );
return ( size_t ) atomic_add_ptr_nv ( pTarg, ( ssize_t ) delta );
STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
return atomic_add_long_nv ( pTarget, ( long ) delta );
}
#endif
@@ -146,10 +142,9 @@ EPICS_ATOMIC_INLINE size_t epicsAtomicAddSizeT ( size_t * pTarget,
EPICS_ATOMIC_INLINE size_t epicsAtomicSubSizeT ( size_t * pTarget,
size_t delta )
{
STATIC_ASSERT ( sizeof ( void * ) == sizeof ( size_t ) );
void ** const pTarg = ( void ** ) ( pTarget );
ssize_t sdelta = ( ssize_t ) delta;
return ( size_t ) atomic_add_ptr_nv ( pTarg, -sdelta );
STATIC_ASSERT ( sizeof ( ulong_t ) == sizeof ( size_t ) );
long sdelta = ( long ) delta;
return atomic_add_long_nv ( pTarget, -sdelta );
}
#endif