[rtems commit] ringbuf: Add SMP support
Sebastian Huber
sebh at rtems.org
Tue Aug 27 08:44:49 UTC 2013
Module: rtems
Branch: master
Commit: ef3640f7a7b249a22cc89de60b0f198d341ce971
Changeset: http://git.rtems.org/rtems/commit/?id=ef3640f7a7b249a22cc89de60b0f198d341ce971
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon Aug 26 15:25:58 2013 +0200
ringbuf: Add SMP support
---
cpukit/libcsupport/include/ringbuf.h | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/cpukit/libcsupport/include/ringbuf.h b/cpukit/libcsupport/include/ringbuf.h
index 99e72a5..13821a5 100644
--- a/cpukit/libcsupport/include/ringbuf.h
+++ b/cpukit/libcsupport/include/ringbuf.h
@@ -10,6 +10,8 @@
#ifndef _RTEMS_RINGBUF_H
#define _RTEMS_RINGBUF_H
+#include <rtems.h>
+
#ifndef RINGBUF_QUEUE_LENGTH
#define RINGBUF_QUEUE_LENGTH 128
#endif
@@ -18,6 +20,7 @@ typedef struct {
uint8_t buffer[RINGBUF_QUEUE_LENGTH];
volatile int head;
volatile int tail;
+ rtems_interrupt_lock lock;
} Ring_buffer_t;
#define Ring_buffer_Initialize( _buffer ) \
@@ -33,22 +36,22 @@ typedef struct {
#define Ring_buffer_Add_character( _buffer, _ch ) \
do { \
- uint32_t isrlevel; \
+ rtems_interrupt_level isrlevel; \
\
- rtems_interrupt_disable( isrlevel ); \
+ rtems_interrupt_lock_acquire( &(_buffer)->lock, isrlevel ); \
(_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \
(_buffer)->buffer[ (_buffer)->tail ] = (_ch); \
- rtems_interrupt_enable( isrlevel ); \
+ rtems_interrupt_lock_release( &(_buffer)->lock, isrlevel ); \
} while ( 0 )
#define Ring_buffer_Remove_character( _buffer, _ch ) \
do { \
- uint32_t isrlevel; \
+ rtems_interrupt_level isrlevel; \
\
- rtems_interrupt_disable( isrlevel ); \
+ rtems_interrupt_lock_acquire( &(_buffer)->lock, isrlevel ); \
(_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \
(_ch) = (_buffer)->buffer[ (_buffer)->head ]; \
- rtems_interrupt_enable( isrlevel ); \
+ rtems_interrupt_lock_release( &(_buffer)->lock, isrlevel ); \
} while ( 0 )
#endif
More information about the vc
mailing list