On 2/25/2015 7:18 AM, Matthew Wortley wrote:
> I am writing a spi driver component and an example client component.  I
> need a way of protecting the communication between them.  To that end I am
> implementing some buffer locking.  I was given a suggestion on the linuxcnc
> user's list of using a ring buffer.  I'm pondering that too.
> To that end:  Is increment (and the subsequent store) an atomic operation
> on x86?  Anyone know if it is also atomic for beagleboneblack, raspberry
> pi, and other common arm processors?  I think it was atomic on some of the
> MCU's that I have used in the past (MSP430)  I'm considering changing the
> flag bit that I am using to a "request counter" that I increment and then
> see if there are more than one process accessing the buffer before I make
> changes to the data.  Something like
> 
> bufflock++;
> if (bufflock>1) bufflock--;
> else {
>   // Do things to the buffer
>   bufflock--;  // All done, decrement back to 0.
> }
> 
> Anyone have other atomic methods I can use to this end (perhaps with a code
> example?)

For that I'd probably just use the gcc atomic intrinsics, there are
various test-and-set, add and fetch, and similar instructions available,
and you don't have to worry about porting assembly instructions across
architectures.

If you need something fancier, browse through the Linux kernel code,
which contains excellent examples of high-performance locking routines
as well as lock-free data structure manipulations.

Oh, and you might need some memory fencing around your "do things to the
buffer" code, depending on usage and how multi-core safe you need to be.

-- 
Charles Steinkuehler
[email protected]

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to