g+
g+ Communities
Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014 
<== Date ==> <== Thread ==>

Subject: Re: "spinlock" API
From: Andrew Johnson <anj@aps.anl.gov>
To: mdavidsaver@bnl.gov
Cc: core-talk@aps.anl.gov
Date: Mon, 11 Jun 2012 11:06:55 -0500
Hi Michael,

On 2012-06-11 Michael Davidsaver wrote:
> 
> I used 'unsigned long' in the example, but the formal specification
> would be:
> 
> typedef <unspecified> epicsSpinKey;

Unfortunately the header does have to fully define the key type, since the 
user code has to instantiate one of these to be able to take a lock.

> >> #define epicsSLLocalFlag(name) epicsSLFlag name = 0
> >
> > Not keen, depends on answer above...
> 
> The only use of this type is as a function local variable.  This is an
> attempt to make this case more convenient.  The zero assignment is meant
> to avoid compiler warnings about using of an uninitialized variable when
> passing the pointer to the lock() function.

It's quite valid to call a function to initialize something one of its 
arguments points at; we do that all the time with calls to sscanf() for 
example without it generating warnings.  I don't think the macro is necessary.

I have a revised preference about names, to match other OSI APIs:

typedef struct epicsSpin * epicsSpinId;

Then replace all instances of epicsSpin * with epicsSpinId.


I just looked up spinLocks in the vxWorks 6.8 documentation, for comparison. 
If possible we should try to design our API so that native APIs can be a 
substituted using macros or inline functions where available.

Wind River provides 4 different spinlock types, in 3 libraries:

    spinLockLib     	spinlock library
    spinLockIsrNdLib	fast, nondeterministic ISR spinlock library
    spinLockNdTimedLib	time limited spinlock library

The first library defines two types, ISR-callable (which masks interrupts on 
the local CPU) and task-only.  These are the functions they provide:

    spinLockIsrInit( ) initialize an ISR-callable spinlock
    spinLockIsrTake( ) take an ISR-callable spinlock
    spinLockIsrGive( ) release an ISR-callable spinlock
    spinLockIsrHeld( ) is an ISR-callable spinlock held by the current CPU?
        These all take just spinlockIsr_t *pLock

    spinLockTaskInit( )	initialize a task-only spinlock
    spinLockTaskTake( )	take a task-only spinlock
    spinLockTaskGive( )	release a task-only spinlock
        These all take just spinlockTask_t *pLock

    spinLockIsrNdInit( ) initialize a non-deterministic ISR spinlock
    spinLockIsrNdTake( ) take a non-deterministic ISR spinlock
    spinLockIsrNdGive( ) release a non-deterministic ISR spinlock
        These use an int key as well as spinlockIsrNd_t *spin

    spinLockNdTimedInit( )         initialize a timed spinlock
    spinLockNdTimedTake( )         take a timed spinlock
    spinLockNdTimedGive( )         give a timed spinlock
    spinLockNdTimedPrevOwnerGet( ) get ID of the previous owner of spinlock
        These are a lot more complicated...

We should be able to implement your API using either the spinLockIsr or 
spinLockIsrNd types.  I would need to read more to work out the difference 
between them though.

- Andrew
-- 
Never interrupt your enemy when he is making a mistake.
-- Napoleon Bonaparte

Replies:
Re: "spinlock" API Michael Davidsaver
References:
"spinlock" API Michael Davidsaver
Re: "spinlock" API Andrew Johnson
Re: "spinlock" API Michael Davidsaver

Navigate by Date:
Prev: Re: "spinlock" API Michael Davidsaver
Next: Re: "spinlock" API Michael Davidsaver
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014 
Navigate by Thread:
Prev: Re: "spinlock" API Michael Davidsaver
Next: Re: "spinlock" API Michael Davidsaver
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014 
ANJ, 26 Nov 2012 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICSv4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·