From 9c191eea63fd6c5511c01186297722e594220032 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 25 Sep 2006 13:36:58 +0000 Subject: * score/Makefile.am, score/preinstall.am, score/include/rtems/score/coresem.h, score/include/rtems/score/object.h, score/include/rtems/score/states.h, score/inline/rtems/score/coresem.inl: Add SuperCore Barriers, SpinLocks and a partial implementation of RWLocks. * score/include/rtems/score/corebarrier.h, score/include/rtems/score/corerwlock.h, score/include/rtems/score/corespinlock.h, score/inline/rtems/score/corebarrier.inl, score/inline/rtems/score/corerwlock.inl, score/inline/rtems/score/corespinlock.inl, score/macros/rtems/score/corebarrier.inl, score/macros/rtems/score/corerwlock.inl, score/macros/rtems/score/corespinlock.inl, score/src/corebarrier.c, score/src/corebarrierrelease.c, score/src/corebarrierwait.c, score/src/corerwlock.c, score/src/corerwlockobtainread.c, score/src/corerwlockobtainwrite.c, score/src/corerwlockrelease.c, score/src/corespinlock.c, score/src/corespinlockrelease.c, score/src/corespinlockwait.c: New files. --- cpukit/ChangeLog | 21 +++ cpukit/score/Makefile.am | 22 ++- cpukit/score/include/rtems/score/corebarrier.h | 195 ++++++++++++++++++++ cpukit/score/include/rtems/score/corerwlock.h | 219 +++++++++++++++++++++++ cpukit/score/include/rtems/score/coresem.h | 2 +- cpukit/score/include/rtems/score/corespinlock.h | 160 +++++++++++++++++ cpukit/score/include/rtems/score/object.h | 19 +- cpukit/score/include/rtems/score/states.h | 25 ++- cpukit/score/inline/rtems/score/corebarrier.inl | 62 +++++++ cpukit/score/inline/rtems/score/corerwlock.inl | 34 ++++ cpukit/score/inline/rtems/score/coresem.inl | 4 +- cpukit/score/inline/rtems/score/corespinlock.inl | 38 ++++ cpukit/score/macros/rtems/score/corebarrier.inl | 34 ++++ cpukit/score/macros/rtems/score/corerwlock.inl | 21 +++ cpukit/score/macros/rtems/score/corespinlock.inl | 23 +++ cpukit/score/preinstall.am | 36 ++++ cpukit/score/src/corebarrier.c | 60 +++++++ cpukit/score/src/corebarrierrelease.c | 68 +++++++ cpukit/score/src/corebarrierwait.c | 81 +++++++++ cpukit/score/src/corerwlock.c | 62 +++++++ cpukit/score/src/corerwlockobtainread.c | 103 +++++++++++ cpukit/score/src/corerwlockobtainwrite.c | 93 ++++++++++ cpukit/score/src/corerwlockrelease.c | 80 +++++++++ cpukit/score/src/corespinlock.c | 56 ++++++ cpukit/score/src/corespinlockrelease.c | 53 ++++++ cpukit/score/src/corespinlockwait.c | 110 ++++++++++++ 26 files changed, 1660 insertions(+), 21 deletions(-) create mode 100644 cpukit/score/include/rtems/score/corebarrier.h create mode 100644 cpukit/score/include/rtems/score/corerwlock.h create mode 100644 cpukit/score/include/rtems/score/corespinlock.h create mode 100644 cpukit/score/inline/rtems/score/corebarrier.inl create mode 100644 cpukit/score/inline/rtems/score/corerwlock.inl create mode 100644 cpukit/score/inline/rtems/score/corespinlock.inl create mode 100644 cpukit/score/macros/rtems/score/corebarrier.inl create mode 100644 cpukit/score/macros/rtems/score/corerwlock.inl create mode 100644 cpukit/score/macros/rtems/score/corespinlock.inl create mode 100644 cpukit/score/src/corebarrier.c create mode 100644 cpukit/score/src/corebarrierrelease.c create mode 100644 cpukit/score/src/corebarrierwait.c create mode 100644 cpukit/score/src/corerwlock.c create mode 100644 cpukit/score/src/corerwlockobtainread.c create mode 100644 cpukit/score/src/corerwlockobtainwrite.c create mode 100644 cpukit/score/src/corerwlockrelease.c create mode 100644 cpukit/score/src/corespinlock.c create mode 100644 cpukit/score/src/corespinlockrelease.c create mode 100644 cpukit/score/src/corespinlockwait.c (limited to 'cpukit') diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index f74a6c5f58..771900d0c3 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,24 @@ + * score/Makefile.am, score/preinstall.am, + score/include/rtems/score/coresem.h, + score/include/rtems/score/object.h, + score/include/rtems/score/states.h, + score/inline/rtems/score/coresem.inl: Add SuperCore Barriers, + SpinLocks and a partial implementation of RWLocks. + * score/include/rtems/score/corebarrier.h, + score/include/rtems/score/corerwlock.h, + score/include/rtems/score/corespinlock.h, + score/inline/rtems/score/corebarrier.inl, + score/inline/rtems/score/corerwlock.inl, + score/inline/rtems/score/corespinlock.inl, + score/macros/rtems/score/corebarrier.inl, + score/macros/rtems/score/corerwlock.inl, + score/macros/rtems/score/corespinlock.inl, score/src/corebarrier.c, + score/src/corebarrierrelease.c, score/src/corebarrierwait.c, + score/src/corerwlock.c, score/src/corerwlockobtainread.c, + score/src/corerwlockobtainwrite.c, score/src/corerwlockrelease.c, + score/src/corespinlock.c, score/src/corespinlockrelease.c, + score/src/corespinlockwait.c: New files. + 2006-09-14 Joel Sherrill * libnetworking/net/route.c, librpc/src/rpc/auth_none.c, diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index 04ddb00229..88a4a60957 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -20,6 +20,7 @@ include_rtems_score_HEADERS = include/rtems/score/address.h \ include/rtems/score/apiext.h include/rtems/score/apimutex.h \ include/rtems/score/bitfield.h include/rtems/score/chain.h \ include/rtems/score/context.h include/rtems/score/copyrt.h \ + include/rtems/score/corebarrier.h \ include/rtems/score/coremsg.h include/rtems/score/coremutex.h \ include/rtems/score/coresem.h include/rtems/score/heap.h \ include/rtems/score/interr.h include/rtems/score/isr.h \ @@ -41,7 +42,9 @@ endif ## inline if INLINE include_rtems_score_HEADERS += inline/rtems/score/address.inl \ - inline/rtems/score/chain.inl inline/rtems/score/coremsg.inl \ + inline/rtems/score/chain.inl inline/rtems/score/corebarrier.inl \ + inline/rtems/score/coremsg.inl inline/rtems/score/corerwlock.inl \ + inline/rtems/score/corespinlock.inl \ inline/rtems/score/coremutex.inl inline/rtems/score/coresem.inl \ inline/rtems/score/heap.inl inline/rtems/score/isr.inl \ inline/rtems/score/object.inl inline/rtems/score/priority.inl \ @@ -59,7 +62,10 @@ endif else ## macros include_rtems_score_HEADERS += macros/rtems/score/address.inl \ - macros/rtems/score/chain.inl macros/rtems/score/coremsg.inl \ + macros/rtems/score/chain.inl macros/rtems/score/corebarrier.inl \ + macros/rtems/score/coremsg.inl \ + macros/rtems/score/corerwlock.inl \ + macros/rtems/score/corespinlock.inl \ macros/rtems/score/coremutex.inl macros/rtems/score/coresem.inl \ macros/rtems/score/heap.inl macros/rtems/score/isr.inl \ macros/rtems/score/object.inl macros/rtems/score/priority.inl \ @@ -90,6 +96,10 @@ if HAS_MP libscore_a_SOURCES += src/mpci.c src/objectmp.c src/threadmp.c endif +## CORE_BARRIER_C_FILES +libscore_a_SOURCES += src/corebarrier.c src/corebarrierrelease.c \ + src/corebarrierwait.c + ## CORE_MESSAGE_QUEUE_C_FILES libscore_a_SOURCES += src/coremsg.c src/coremsgbroadcast.c \ src/coremsgclose.c src/coremsgflush.c src/coremsgflushwait.c \ @@ -100,10 +110,18 @@ libscore_a_SOURCES += src/coremsg.c src/coremsgbroadcast.c \ libscore_a_SOURCES += src/coremutex.c src/coremutexflush.c \ src/coremutexseize.c src/coremutexsurrender.c +## CORE_RWLOCK_C_FILES +libscore_a_SOURCES += src/corerwlock.c src/corerwlockobtainread.c \ + src/corerwlockobtainwrite.c src/corerwlockrelease.c + ## CORE_SEMAPHORE_C_FILES libscore_a_SOURCES += src/coresem.c src/coresemflush.c src/coresemseize.c \ src/coresemsurrender.c +## CORE_SPINLOCK_C_FILES +libscore_a_SOURCES += src/corespinlock.c src/corespinlockrelease.c \ + src/corespinlockwait.c + ## HEAP_C_FILES libscore_a_SOURCES += src/heap.c src/heapallocate.c src/heapextend.c src/heapfree.c \ src/heapsizeofuserarea.c src/heapwalk.c src/heapgetinfo.c \ diff --git a/cpukit/score/include/rtems/score/corebarrier.h b/cpukit/score/include/rtems/score/corebarrier.h new file mode 100644 index 0000000000..34337e195f --- /dev/null +++ b/cpukit/score/include/rtems/score/corebarrier.h @@ -0,0 +1,195 @@ +/** + * @file rtems/score/corebarrier.h + * + * This include file contains all the constants and structures associated + * with the Barrier Handler. + */ + +/* + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifndef _RTEMS_SCORE_COREBARRIER_H +#define _RTEMS_SCORE_COREBARRIER_H + +/** + * @defgroup ScoreBarrier Barrier Handler + * + * This handler encapsulates functionality which provides the foundation + * Barrier services used in all of the APIs supported by RTEMS. + */ +/**@{*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +/** + * The following type defines the callout which the API provides + * to support global/multiprocessor operations on barriers. + */ +typedef void ( *CORE_barrier_API_mp_support_callout )( + Thread_Control *, + Objects_Id + ); + +/** + * Flavors of barriers. + */ +typedef enum { + /** This specifies that the barrier will automatically release when + * the user specified number of threads have arrived at the barrier. + */ + CORE_BARRIER_AUTOMATIC_RELEASE, + /** This specifies that the user will have to manually release the barrier + * in order to release the waiting threads. + */ + CORE_BARRIER_MANUAL_RELEASE +} CORE_barrier_Disciplines; + +/** + * Core Barrier handler return statuses. + */ +typedef enum { + /** This status indicates that the operation completed successfully. */ + CORE_BARRIER_STATUS_SUCCESSFUL, + /** This status indicates that the barrier is configured for automatic + * release and the caller tripped the automatic release. The caller + * thus did not block. + */ + CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED, + /** This status indicates that the thread was blocked waiting for an + * operation to complete and the barrier was deleted. + */ + CORE_BARRIER_WAS_DELETED, + /** This status indicates that the calling task was willing to block + * but the operation was unable to complete within the time allotted + * because the resource never became available. + */ + CORE_BARRIER_TIMEOUT +} CORE_barrier_Status; + +/** + * The following defines the control block used to manage the + * attributes of each barrier. + */ +typedef struct { + /** This field indicates whether the barrier is automatic or manual. + */ + CORE_barrier_Disciplines discipline; + /** This element indicates the number of threads which must arrive at the + * barrier to trip the automatic release. + */ + uint32_t maximum_count; +} CORE_barrier_Attributes; + +/** + * The following defines the control block used to manage each + * barrier. + */ +typedef struct { + /** This field is the Waiting Queue used to manage the set of tasks + * which are blocked waiting for the barrier to be released. + */ + Thread_queue_Control Wait_queue; + /** This element is the set of attributes which define this instance's + * behavior. + */ + CORE_barrier_Attributes Attributes; + /** This element contains the current number of thread waiting for this + * barrier to be released. */ + uint32_t number_of_waiting_threads; +} CORE_barrier_Control; + +/** + * This routine initializes the barrier based on the parameters passed. + * + * @param[in] the_barrier is the barrier to initialize + * @param[in] the_barrier_attributes define the behavior of this instance + */ +void _CORE_barrier_Initialize( + CORE_barrier_Control *the_barrier, + CORE_barrier_Attributes *the_barrier_attributes +); + +/** + * This routine wait for the barrier to be released. If the barrier + * is set to automatic and this is the appropriate thread, then it returns + * immediately. Otherwise, the calling thread is blocked until the barrier + * is released. + * + * @param[in] the_barrier is the barrier to wait for + * @param[in] id is the id of the object being waited upon + * @param[in] wait is TRUE if the calling thread is willing to wait + * @param[in] timeout is the number of ticks the calling thread is willing + * to wait if @a wait is TRUE. + * @param[in] api_barrier_mp_support is the routine to invoke if the + * thread unblocked is remote + * + * @note Status is returned via the thread control block. + */ +void _CORE_barrier_Wait( + CORE_barrier_Control *the_barrier, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout, + CORE_barrier_API_mp_support_callout api_barrier_mp_support +); + +/** + * This routine manually releases the barrier. All of the threads waiting + * for the barrier will be readied. + * + * @param[in] the_barrier is the barrier to surrender + * @param[in] id is the id of the object for a remote unblock + * @param[in] api_barrier_mp_support is the routine to invoke if the + * thread unblocked is remote + * + * @return the number of unblocked threads + */ +uint32_t _CORE_barrier_Release( + CORE_barrier_Control *the_barrier, + Objects_Id id, + CORE_barrier_API_mp_support_callout api_barrier_mp_support +); + +/** + * This routine assists in the deletion of a barrier by flushing the + * associated wait queue. + * + * @param[in] the_barrier is the barrier to flush + * @param[in] remote_extract_callout is the routine to invoke if the + * thread unblocked is remote + * @param[in] status is the status to be returned to the unblocked thread + */ +#define _CORE_barrier_Flush( _the_barrier, _remote_extract_callout, _status) \ + _Thread_queue_Flush( \ + &((_the_barrier)->Wait_queue), \ + (_remote_extract_callout), \ + (_status) \ + ) + +#ifndef __RTEMS_APPLICATION__ +#include +#endif + +#ifdef __cplusplus +} +#endif + +/**@}*/ + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/corerwlock.h b/cpukit/score/include/rtems/score/corerwlock.h new file mode 100644 index 0000000000..d596ac4130 --- /dev/null +++ b/cpukit/score/include/rtems/score/corerwlock.h @@ -0,0 +1,219 @@ +/** + * @file rtems/score/corerwlock.h + * + * This include file contains all the constants and structures associated + * with the RWLock Handler. + */ + +/* + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifndef _RTEMS_SCORE_CORERWLOCK_H +#define _RTEMS_SCORE_CORERWLOCK_H + +/** + * @defgroup ScoreRWLock RWLock Handler + * + * This handler encapsulates functionality which provides the foundation + * RWLock services used in all of the APIs supported by RTEMS. + */ +/**@{*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +/** + * The following type defines the callout which the API provides + * to support global/multiprocessor operations on RWLocks. + */ +typedef void ( *CORE_RWLock_API_mp_support_callout )( + Thread_Control *, + Objects_Id + ); + +/** + * RWLock State. + */ +typedef enum { + /** This indicates the the RWLock is not currently locked. + */ + CORE_RWLOCK_UNLOCKED, + /** This indicates the the RWLock is currently locked for reading. + */ + CORE_RWLOCK_LOCKED_FOR_READING, + /** This indicates the the RWLock is currently locked for reading. + */ + CORE_RWLOCK_LOCKED_FOR_WRITING +} CORE_RWLock_States; + +/** + * Core RWLock handler return statuses. + */ +typedef enum { + /** This status indicates that the operation completed successfully. */ + CORE_RWLOCK_SUCCESSFUL, + /** This status indicates that the thread was blocked waiting for an */ + CORE_RWLOCK_WAS_DELETED, + /** This status indicates that the rwlock was not immediately available. */ + CORE_RWLOCK_UNAVAILABLE, + /** This status indicates that the calling task was willing to block + * but the operation was unable to complete within the time allotted + * because the resource never became available. + */ + CORE_RWLOCK_TIMEOUT +} CORE_RWLock_Status; + +/** This is the last status value. + */ +#define CORE_RWLOCK_STATUS_LAST CORE_RWLOCK_TIMEOUT + +/** + * This is used to denote that a thread is blocking waiting for + * read-only access to the RWLock. + */ +#define CORE_RWLOCK_THREAD_WAITING_FOR_READ 0 + +/** + * This is used to denote that a thread is blocking waiting for + * write-exclusive access to the RWLock. + */ +#define CORE_RWLOCK_THREAD_WAITING_FOR_WRITE 1 + +/** + * The following defines the control block used to manage the + * attributes of each RWLock. + */ +typedef struct { + /** This field indicates XXX. + */ + int XXX; +} CORE_RWLock_Attributes; + +/** + * The following defines the control block used to manage each + * RWLock. + */ +typedef struct { + /** This field is the Waiting Queue used to manage the set of tasks + * which are blocked waiting for the RWLock to be released. + */ + Thread_queue_Control Wait_queue; + /** This element is the set of attributes which define this instance's + * behavior. + */ + CORE_RWLock_Attributes Attributes; + /** This element is the current state of the RWLock. + */ + CORE_RWLock_States current_state; + /** This element contains the current number of thread waiting for this + * RWLock to be released. */ + uint32_t number_of_readers; +} CORE_RWLock_Control; + +/** + * This routine initializes the RWLock based on the parameters passed. + * + * @param[in] the_rwlock is the RWLock to initialize + * @param[in] the_rwlock_attributes define the behavior of this instance + */ +void _CORE_RWLock_Initialize( + CORE_RWLock_Control *the_rwlock, + CORE_RWLock_Attributes *the_rwlock_attributes +); + +/** + * This routine attempts to obtain the RWLock for read access. + * + * @param[in] the_rwlock is the RWLock to wait for + * @param[in] id is the id of the object being waited upon + * @param[in] wait is TRUE if the calling thread is willing to wait + * @param[in] timeout is the number of ticks the calling thread is willing + * to wait if @a wait is TRUE. + * @param[in] api_rwlock_mp_support is the routine to invoke if the + * thread unblocked is remote + * + * @note Status is returned via the thread control block. + */ +void _CORE_RWLock_Obtain_for_reading( + CORE_RWLock_Control *the_rwlock, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout, + CORE_RWLock_API_mp_support_callout api_rwlock_mp_support +); + +/** + * This routine attempts to obtain the RWLock for write exclusive access. + * + * @param[in] the_rwlock is the RWLock to wait for + * @param[in] id is the id of the object being waited upon + * @param[in] wait is TRUE if the calling thread is willing to wait + * @param[in] timeout is the number of ticks the calling thread is willing + * to wait if @a wait is TRUE. + * @param[in] api_rwlock_mp_support is the routine to invoke if the + * thread unblocked is remote + * + * @note Status is returned via the thread control block. + */ +void _CORE_RWLock_Obtain_for_writing( + CORE_RWLock_Control *the_rwlock, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout, + CORE_RWLock_API_mp_support_callout api_rwlock_mp_support +); + +/** + * This routine manually releases the RWLock. All of the threads waiting + * for the RWLock will be readied. + * + * @param[in] the_rwlock is the RWLock to surrender + * + * @return Status is returned to indicate successful or failure. + */ +CORE_RWLock_Status _CORE_RWLock_Release( + CORE_RWLock_Control *the_rwlock +); + +/** + * This routine assists in the deletion of a RWLock by flushing the + * associated wait queue. + * + * @param[in] the_rwlock is the RWLock to flush + * @param[in] remote_extract_callout is the routine to invoke if the + * thread unblocked is remote + * @param[in] status is the status to be returned to the unblocked thread + */ +#define _CORE_RWLock_Flush( _the_rwlock, _remote_extract_callout, _status) \ + _Thread_queue_Flush( \ + &((_the_rwlock)->Wait_queue), \ + (_remote_extract_callout), \ + (_status) \ + ) + +#ifndef __RTEMS_APPLICATION__ +#include +#endif + +#ifdef __cplusplus +} +#endif + +/**@}*/ + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/coresem.h b/cpukit/score/include/rtems/score/coresem.h index 54621fce84..7445151ecd 100644 --- a/cpukit/score/include/rtems/score/coresem.h +++ b/cpukit/score/include/rtems/score/coresem.h @@ -129,7 +129,7 @@ void _CORE_semaphore_Initialize( ); /** - * This routine attempts to receive a unit from the_semaphore. + * This routine attempts to receive a unit from @a the_semaphore. * If a unit is available or if the wait flag is FALSE, then the routine * returns. Otherwise, the calling task is blocked until a unit becomes * available. diff --git a/cpukit/score/include/rtems/score/corespinlock.h b/cpukit/score/include/rtems/score/corespinlock.h new file mode 100644 index 0000000000..dc559b2a7c --- /dev/null +++ b/cpukit/score/include/rtems/score/corespinlock.h @@ -0,0 +1,160 @@ +/** + * @file rtems/score/corespinlock.h + * + * This include file contains all the constants and structures associated + * with the Spinlock Handler. + */ + +/* + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifndef _RTEMS_SCORE_CORESPINLOCK_H +#define _RTEMS_SCORE_CORESPINLOCK_H + +/** + * @defgroup ScoreSpinlock Spinlock Handler + * + * This handler encapsulates functionality which provides the foundation + * Spinlock services used in all of the APIs supported by RTEMS. + */ +/**@{*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** + * Core Spinlock handler return statuses. + */ +typedef enum { + /** This status indicates that the operation completed successfully. */ + CORE_SPINLOCK_SUCCESSFUL, + /** This status indicates that the current thread already holds the spinlock. + * An attempt to relock it will result in deadlock. + */ + CORE_SPINLOCK_HOLDER_RELOCKING, + /** This status indicates that a thread reached the limit of time it + * was willing to wait on the spin lock. + */ + CORE_SPINLOCK_TIMEOUT, + /** This status indicates that a thread is currently waiting for this + * spin lock. + */ + CORE_SPINLOCK_IS_BUSY, + /** This status indicates that the spinlock is currently locked and thus + * unavailable. + */ + CORE_SPINLOCK_UNAVAILABLE, + /** This status indicates that the spinlock is not currently locked and thus + * should not be released. + */ + CORE_SPINLOCK_NOT_LOCKED +} CORE_spinlock_Status; + +/** This is a shorthand for the last status code. */ +#define CORE_SPINLOCK_STATUS_LAST CORE_SPINLOCK_NOT_LOCKED + +/** This indicates the lock is available. */ +#define CORE_SPINLOCK_UNLOCKED 0 + +/** This indicates the lock is unavailable. */ +#define CORE_SPINLOCK_LOCKED 1 + +/** + * The following defines the control block used to manage the + * attributes of each spinlock. + */ +typedef struct { + /** This element indicates XXX + */ + uint32_t XXX; +} CORE_spinlock_Attributes; + +/** + * The following defines the control block used to manage each + * spinlock. + */ +typedef struct { + /** XXX may not be needed */ + CORE_spinlock_Attributes Attributes; + + /** This field is the lock. + */ + volatile uint32_t lock; + + /** This field is a count of the current number of threads using + * this spinlock. It includes the thread holding the lock as well + * as those waiting. + */ + volatile uint32_t users; + + /** This field is the Id of the thread holding the lock. It may or may + * not be the thread which acquired it. + */ + volatile Objects_Id holder; +} CORE_spinlock_Control; + +/** + * This routine initializes the spinlock based on the parameters passed. + * + * @param[in] the_spinlock is the spinlock to initialize + * @param[in] the_spinlock_attributes define the behavior of this instance + */ +void _CORE_spinlock_Initialize( + CORE_spinlock_Control *the_spinlock, + CORE_spinlock_Attributes *the_spinlock_attributes +); + +/** + * This routine wait for the spinlock to be released. If the spinlock + * is set to automatic and this is the appropriate thread, then it returns + * immediately. Otherwise, the calling thread is blocked until the spinlock + * is released. + * + * @param[in] the_spinlock is the spinlock to wait for + * @param[in] wait is true if willing to wait + * @param[in] timeout is the maximum number of ticks to spin (0 is forever) + * + * @return A status is returned which indicates the success or failure of + * this operation. + */ +CORE_spinlock_Status _CORE_spinlock_Wait( + CORE_spinlock_Control *the_spinlock, + boolean wait, + Watchdog_Interval timeout +); + +/** + * This routine manually releases the spinlock. All of the threads waiting + * for the spinlock will be readied. + * + * @param[in] the_spinlock is the spinlock to surrender + */ +CORE_spinlock_Status _CORE_spinlock_Release( + CORE_spinlock_Control *the_spinlock +); + +#ifndef __RTEMS_APPLICATION__ +#include +#endif + +#ifdef __cplusplus +} +#endif + +/**@}*/ + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/object.h b/cpukit/score/include/rtems/score/object.h index 1cc37c7965..4f93e47ecc 100644 --- a/cpukit/score/include/rtems/score/object.h +++ b/cpukit/score/include/rtems/score/object.h @@ -1,13 +1,14 @@ /** * @file rtems/score/object.h - */ - -/* + * + * * This include file contains all the constants and structures associated * with the Object Handler. This Handler provides mechanisms which * can be used to initialize and manipulate all objects which have * ids. - * + */ + +/* * COPYRIGHT (c) 1989-2006. * On-Line Applications Research Corporation (OAR). * @@ -230,7 +231,8 @@ typedef enum { OBJECTS_RTEMS_REGIONS = 6, OBJECTS_RTEMS_PORTS = 7, OBJECTS_RTEMS_PERIODS = 8, - OBJECTS_RTEMS_EXTENSIONS = 9 + OBJECTS_RTEMS_EXTENSIONS = 9, + OBJECTS_RTEMS_BARRIERS = 10 } Objects_Classic_API; /** This macro is used to generically specify the last API index. */ @@ -250,11 +252,14 @@ typedef enum { OBJECTS_POSIX_MUTEXES = 6, OBJECTS_POSIX_SEMAPHORES = 7, OBJECTS_POSIX_CONDITION_VARIABLES = 8, - OBJECTS_POSIX_TIMERS = 9 + OBJECTS_POSIX_TIMERS = 9, + OBJECTS_POSIX_BARRIERS = 10, + OBJECTS_POSIX_SPINLOCKS = 11, + OBJECTS_POSIX_RWLOCKS = 12 } Objects_POSIX_API; /** This macro is used to generically specify the last API index. */ -#define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_TIMERS +#define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_RWLOCKS /** * This enumerated type is used in the class field of the object ID diff --git a/cpukit/score/include/rtems/score/states.h b/cpukit/score/include/rtems/score/states.h index 8e0b07f138..305460bd8c 100644 --- a/cpukit/score/include/rtems/score/states.h +++ b/cpukit/score/include/rtems/score/states.h @@ -42,19 +42,19 @@ typedef uint32_t States_Control; */ /** This macro corresponds to all states being set. */ -#define STATES_ALL_SET 0xfffff /* all states */ +#define STATES_ALL_SET 0xfffff /** This macro corresponds to a task being ready. */ -#define STATES_READY 0x00000 /* ready to run */ +#define STATES_READY 0x00000 /** This macro corresponds to a task being created but not yet started. */ -#define STATES_DORMANT 0x00001 /* created not started */ +#define STATES_DORMANT 0x00001 /** This macro corresponds to a task being suspended. */ -#define STATES_SUSPENDED 0x00002 /* waiting for resume */ +#define STATES_SUSPENDED 0x00002 /** This macro corresponds to a task being in an internal state transition. */ -#define STATES_TRANSIENT 0x00004 /* in transition */ +#define STATES_TRANSIENT 0x00004 /** This macro corresponds to a task which is waiting for a timeout. */ -#define STATES_DELAYING 0x00008 /* wait for timeout */ +#define STATES_DELAYING 0x00008 /** This macro corresponds to a task waiting until a specific TOD. */ -#define STATES_WAITING_FOR_TIME 0x00010 /* wait for TOD */ +#define STATES_WAITING_FOR_TIME 0x00010 /** This macro corresponds to a task waiting for a variable length buffer. */ #define STATES_WAITING_FOR_BUFFER 0x00020 /** This macro corresponds to a task waiting for a fixed size segment. */ @@ -77,10 +77,15 @@ typedef uint32_t States_Control; #define STATES_WAITING_FOR_PERIOD 0x04000 /** This macro corresponds to a task waiting for a signal. */ #define STATES_WAITING_FOR_SIGNAL 0x08000 +/** This macro corresponds to a task waiting for a barrier. */ +#define STATES_WAITING_FOR_BARRIER 0x10000 +/** This macro corresponds to a task waiting for a RWLock. */ +#define STATES_WAITING_FOR_RWLOCK 0x20000 + /** This macro corresponds to a task which is in an interruptible * blocking state. */ -#define STATES_INTERRUPTIBLE_BY_SIGNAL 0x10000 +#define STATES_INTERRUPTIBLE_BY_SIGNAL 0x10000000 /** This macro corresponds to a task waiting for a local object operation. */ #define STATES_LOCALLY_BLOCKED ( STATES_WAITING_FOR_BUFFER | \ @@ -90,7 +95,9 @@ typedef uint32_t States_Control; STATES_WAITING_FOR_MUTEX | \ STATES_WAITING_FOR_CONDITION_VARIABLE | \ STATES_WAITING_FOR_JOIN_AT_EXIT | \ - STATES_WAITING_FOR_SIGNAL ) + STATES_WAITING_FOR_SIGNAL | \ + STATES_WAITING_FOR_BARRIER | \ + STATES_WAITING_FOR_RWLOCK ) /** This macro corresponds to a task waiting which is blocked on * a thread queue. */ diff --git a/cpukit/score/inline/rtems/score/corebarrier.inl b/cpukit/score/inline/rtems/score/corebarrier.inl new file mode 100644 index 0000000000..d8104e7179 --- /dev/null +++ b/cpukit/score/inline/rtems/score/corebarrier.inl @@ -0,0 +1,62 @@ +/** + * @file rtems/score/corebarrier.inl + * + * This include file contains all of the inlined routines associated + * with the SuperCore barrier. + */ + +/* + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifndef _RTEMS_SCORE_COREBARRIER_INL +#define _RTEMS_SCORE_COREBARRIER_INL + +/** + * @addtogroup ScoreBarrier + * @{ + */ + +#include +#include + +/** + * This function returns TRUE if the automatic release attribute is + * enabled in the @a attribute_set and FALSE otherwise. + * + * @param[in] the_attribute is the attribute set to test + * @return TRUE if the priority attribute is enabled + */ +RTEMS_INLINE_ROUTINE boolean _CORE_barrier_Is_automatic( + CORE_barrier_Attributes *the_attribute +) +{ + return + (the_attribute->discipline == CORE_BARRIER_AUTOMATIC_RELEASE); +} + +/** + * This routine returns the number of threads currently waiting at the barrier. + * + * @param[in] the_barrier is the barrier to obtain the number of blocked + * threads for + * @return the current count of this barrier + */ +RTEMS_INLINE_ROUTINE uint32_t _CORE_barrier_Get_number_of_waiting_threads( + CORE_barrier_Control *the_barrier +) +{ + return the_barrier->number_of_waiting_threads; +} + +/**@}*/ + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/corerwlock.inl b/cpukit/score/inline/rtems/score/corerwlock.inl new file mode 100644 index 0000000000..31ca5f0dc0 --- /dev/null +++ b/cpukit/score/inline/rtems/score/corerwlock.inl @@ -0,0 +1,34 @@ +/** + * @file rtems/score/coreRWLock.inl + * + * This include file contains all of the inlined routines associated + * with the SuperCore RWLock. + */ + +/* + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifndef _RTEMS_SCORE_CORERWLOCK_INL +#define _RTEMS_SCORE_CORERWLOCK_INL + +/** + * @addtogroup ScoreRWLock + * @{ + */ + +#include +#include + + +/**@}*/ + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/coresem.inl b/cpukit/score/inline/rtems/score/coresem.inl index c7e6b69605..72b297b489 100644 --- a/cpukit/score/inline/rtems/score/coresem.inl +++ b/cpukit/score/inline/rtems/score/coresem.inl @@ -2,7 +2,7 @@ * @file rtems/score/coresem.inl * * This include file contains all of the inlined routines associated - * with the CORE semaphore. + * with the SuperCore semaphore. */ /* @@ -29,7 +29,7 @@ /** * This function returns TRUE if the priority attribute is - * enabled in the attribute_set and FALSE otherwise. + * enabled in the @a attribute_set and FALSE otherwise. * * @param[in] the_attribute is the attribute set to test * @return TRUE if the priority attribute is enabled diff --git a/cpukit/score/inline/rtems/score/corespinlock.inl b/cpukit/score/inline/rtems/score/corespinlock.inl new file mode 100644 index 0000000000..e0f3feeec2 --- /dev/null +++ b/cpukit/score/inline/rtems/score/corespinlock.inl @@ -0,0 +1,38 @@ +/** + * @file rtems/score/corespinlock.inl + * + * This include file contains all of the inlined routines associated + * with the SuperCore spinlock. + */ + +/* + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifndef _RTEMS_SCORE_CORESPINLOCK_INL +#define _RTEMS_SCORE_CORESPINLOCK_INL + +/** + * @addtogroup ScoreSpinlock + * @{ + */ + +RTEMS_INLINE_ROUTINE boolean _CORE_spinlock_Is_busy( + CORE_spinlock_Control *the_spinlock +) +{ + return (the_spinlock->users != 0); +} + + +/**@}*/ + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/corebarrier.inl b/cpukit/score/macros/rtems/score/corebarrier.inl new file mode 100644 index 0000000000..84b02bbd9b --- /dev/null +++ b/cpukit/score/macros/rtems/score/corebarrier.inl @@ -0,0 +1,34 @@ +/* macros/corebarrier.inl + * + * This include file contains all of the inlined routines associated + * with core barriers. + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifndef _RTEMS_SCORE_COREBARRIER_INL +#define _RTEMS_SCORE_COREBARRIER_INL + +/* + * _CORE_barrier_Is_automatic + */ + +#define _CORE_barrier_Is_automatic( _the_attribute ) \ + ( (_the_attribute)->discipline == CORE_BARRIER_AUTOMATIC_RELEASE) + +/* + * _CORE_barrier_Get_number_of_waiting_threads + */ + +#define _CORE_barrier_Get_number_of_waiting_threads( _the_barrier ) \ + ( (_the_barrier)->number_of_waiting_threads ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/corerwlock.inl b/cpukit/score/macros/rtems/score/corerwlock.inl new file mode 100644 index 0000000000..9ed371d23d --- /dev/null +++ b/cpukit/score/macros/rtems/score/corerwlock.inl @@ -0,0 +1,21 @@ +/* macros/corerwlock.inl + * + * This include file contains all of the inlined routines associated + * with core RWLocks. + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifndef _RTEMS_SCORE_CORERWLOCK_INL +#define _RTEMS_SCORE_CORERWLOCK_INL + + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/corespinlock.inl b/cpukit/score/macros/rtems/score/corespinlock.inl new file mode 100644 index 0000000000..65eba1c1d0 --- /dev/null +++ b/cpukit/score/macros/rtems/score/corespinlock.inl @@ -0,0 +1,23 @@ +/* macros/rtems/score/corespinlock.inl + * + * This include file contains all of the inlined routines associated + * with core spinlocks. + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifndef _RTEMS_SCORE_CORESPINLOCK_INL +#define _RTEMS_SCORE_CORESPINLOCK_INL + +#define _CORE_spinlock_Is_busy(_the_spinlock) \ + ((_the_spinlock)->users != 0) + +#endif +/* end of include file */ diff --git a/cpukit/score/preinstall.am b/cpukit/score/preinstall.am index 81ed119404..b35cae6e12 100644 --- a/cpukit/score/preinstall.am +++ b/cpukit/score/preinstall.am @@ -63,6 +63,10 @@ $(PROJECT_INCLUDE)/rtems/score/copyrt.h: include/rtems/score/copyrt.h $(PROJECT_ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/copyrt.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/copyrt.h +$(PROJECT_INCLUDE)/rtems/score/corebarrier.h: include/rtems/score/corebarrier.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corebarrier.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corebarrier.h + $(PROJECT_INCLUDE)/rtems/score/coremsg.h: include/rtems/score/coremsg.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremsg.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremsg.h @@ -71,10 +75,18 @@ $(PROJECT_INCLUDE)/rtems/score/coremutex.h: include/rtems/score/coremutex.h $(PR $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremutex.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremutex.h +$(PROJECT_INCLUDE)/rtems/score/corerwlock.h: include/rtems/score/corerwlock.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corerwlock.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corerwlock.h + $(PROJECT_INCLUDE)/rtems/score/coresem.h: include/rtems/score/coresem.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coresem.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coresem.h +$(PROJECT_INCLUDE)/rtems/score/corespinlock.h: include/rtems/score/corespinlock.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corespinlock.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corespinlock.h + $(PROJECT_INCLUDE)/rtems/score/heap.h: include/rtems/score/heap.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/heap.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/heap.h @@ -165,10 +177,22 @@ $(PROJECT_INCLUDE)/rtems/score/chain.inl: inline/rtems/score/chain.inl $(PROJECT $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/chain.inl PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/chain.inl +$(PROJECT_INCLUDE)/rtems/score/corebarrier.inl: inline/rtems/score/corebarrier.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corebarrier.inl +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corebarrier.inl + $(PROJECT_INCLUDE)/rtems/score/coremsg.inl: inline/rtems/score/coremsg.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremsg.inl PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremsg.inl +$(PROJECT_INCLUDE)/rtems/score/corerwlock.inl: inline/rtems/score/corerwlock.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corerwlock.inl +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corerwlock.inl + +$(PROJECT_INCLUDE)/rtems/score/corespinlock.inl: inline/rtems/score/corespinlock.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corespinlock.inl +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corespinlock.inl + $(PROJECT_INCLUDE)/rtems/score/coremutex.inl: inline/rtems/score/coremutex.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremutex.inl PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremutex.inl @@ -251,10 +275,22 @@ $(PROJECT_INCLUDE)/rtems/score/chain.inl: macros/rtems/score/chain.inl $(PROJECT $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/chain.inl PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/chain.inl +$(PROJECT_INCLUDE)/rtems/score/corebarrier.inl: macros/rtems/score/corebarrier.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corebarrier.inl +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corebarrier.inl + $(PROJECT_INCLUDE)/rtems/score/coremsg.inl: macros/rtems/score/coremsg.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremsg.inl PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremsg.inl +$(PROJECT_INCLUDE)/rtems/score/corerwlock.inl: macros/rtems/score/corerwlock.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corerwlock.inl +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corerwlock.inl + +$(PROJECT_INCLUDE)/rtems/score/corespinlock.inl: macros/rtems/score/corespinlock.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corespinlock.inl +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/corespinlock.inl + $(PROJECT_INCLUDE)/rtems/score/coremutex.inl: macros/rtems/score/coremutex.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/coremutex.inl PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/coremutex.inl diff --git a/cpukit/score/src/corebarrier.c b/cpukit/score/src/corebarrier.c new file mode 100644 index 0000000000..b118944bbe --- /dev/null +++ b/cpukit/score/src/corebarrier.c @@ -0,0 +1,60 @@ +/* + * SuperCore Barrier Handler + * + * DESCRIPTION: + * + * This package is part of the implementation of the SuperCore Barrier Handler. + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#if defined(RTEMS_MULTIPROCESSING) +#include +#endif + +/*PAGE + * + * _CORE_barrier_Initialize + * + * This function initialize a barrier and sets the initial value based + * on the given count. + * + * Input parameters: + * the_barrier - the barrier control block to initialize + * the_barrier_attributes - the attributes specified at create time + * + * Output parameters: NONE + */ + +void _CORE_barrier_Initialize( + CORE_barrier_Control *the_barrier, + CORE_barrier_Attributes *the_barrier_attributes +) +{ + + the_barrier->Attributes = *the_barrier_attributes; + the_barrier->number_of_waiting_threads = 0; + + _Thread_queue_Initialize( + &the_barrier->Wait_queue, + THREAD_QUEUE_DISCIPLINE_FIFO, + STATES_WAITING_FOR_BARRIER, + CORE_BARRIER_TIMEOUT + ); +} diff --git a/cpukit/score/src/corebarrierrelease.c b/cpukit/score/src/corebarrierrelease.c new file mode 100644 index 0000000000..a93efa4c70 --- /dev/null +++ b/cpukit/score/src/corebarrierrelease.c @@ -0,0 +1,68 @@ +/* + * SuperCore Barrier Handler + * + * DESCRIPTION: + * + * This package is part of the implementation of the SuperCore Barrier Handler. + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#if defined(RTEMS_MULTIPROCESSING) +#include +#endif + +/*PAGE + * + * _CORE_barrier_Release + * + * Input parameters: + * the_barrier - the barrier to be flushed + * id - id of the object for a remote unblock + * api_barrier_mp_support - api dependent MP support actions + * + * Output parameters: + * CORE_BARRIER_STATUS_SUCCESSFUL - if successful + * core error code - if unsuccessful + * + * Output parameters: + * returns number of threads unblocked + */ + +uint32_t _CORE_barrier_Release( + CORE_barrier_Control *the_barrier, + Objects_Id id, + CORE_barrier_API_mp_support_callout api_barrier_mp_support +) +{ + Thread_Control *the_thread; + uint32_t count; + + count = 0; + while ( (the_thread = _Thread_queue_Dequeue(&the_barrier->Wait_queue)) ) { +#if defined(RTEMS_MULTIPROCESSING) + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + (*api_barrier_mp_support) ( the_thread, id ); +#endif + count++; + } + the_barrier->number_of_waiting_threads = 0; + return count; +} diff --git a/cpukit/score/src/corebarrierwait.c b/cpukit/score/src/corebarrierwait.c new file mode 100644 index 0000000000..f00b3d73d5 --- /dev/null +++ b/cpukit/score/src/corebarrierwait.c @@ -0,0 +1,81 @@ +/* + * SuperCore Barrier Handler + * + * DESCRIPTION: + * + * This package is part of the implementation of the SuperCore Barrier Handler. + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#if defined(RTEMS_MULTIPROCESSING) +#include +#endif + +/*PAGE + * + * _CORE_barrier_Wait + * + * Input parameters: + * the_barrier - pointer to barrier control block + * id - id of object to wait on + * wait - TRUE if wait is allowed, FALSE otherwise + * timeout - number of ticks to wait (0 means forever) + * api_barrier_mp_support - api dependent MP support actions + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * available + * wait + */ + +void _CORE_barrier_Wait( + CORE_barrier_Control *the_barrier, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout, + CORE_barrier_API_mp_support_callout api_barrier_mp_support +) +{ + Thread_Control *executing; + ISR_Level level; + + executing = _Thread_Executing; + executing->Wait.return_code = CORE_BARRIER_STATUS_SUCCESSFUL; + _ISR_Disable( level ); + the_barrier->number_of_waiting_threads++; + if ( the_barrier->number_of_waiting_threads == + the_barrier->Attributes.maximum_count) { + if ( _CORE_barrier_Is_automatic( &the_barrier->Attributes ) ) { + executing->Wait.return_code = CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED; + _ISR_Enable( level ); + _CORE_barrier_Release( the_barrier, id, api_barrier_mp_support ); + return; + } + } + + _Thread_queue_Enter_critical_section( &the_barrier->Wait_queue ); + executing->Wait.queue = &the_barrier->Wait_queue; + executing->Wait.id = id; + _ISR_Enable( level ); + + _Thread_queue_Enqueue( &the_barrier->Wait_queue, timeout ); +} diff --git a/cpukit/score/src/corerwlock.c b/cpukit/score/src/corerwlock.c new file mode 100644 index 0000000000..3629f146aa --- /dev/null +++ b/cpukit/score/src/corerwlock.c @@ -0,0 +1,62 @@ +/* + * SuperCore RWLock Handler + * + * DESCRIPTION: + * + * This package is part of the implementation of the SuperCore RWLock Handler. + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#if defined(RTEMS_MULTIPROCESSING) +#include +#endif + +/*PAGE + * + * _CORE_RWLock_Initialize + * + * This function initialize a rwlock and sets the initial value based + * on the given count. + * + * Input parameters: + * the_rwlock - the rwlock control block to initialize + * the_rwlock_attributes - the attributes specified at create time + * + * Output parameters: NONE + */ + +void _CORE_RWLock_Initialize( + CORE_RWLock_Control *the_rwlock, + CORE_RWLock_Attributes *the_rwlock_attributes +) +{ + + the_rwlock->Attributes = *the_rwlock_attributes; +/* + the_rwlock->number_of_waiting_threads = 0; +*/ + + _Thread_queue_Initialize( + &the_rwlock->Wait_queue, + THREAD_QUEUE_DISCIPLINE_FIFO, + STATES_WAITING_FOR_RWLOCK, + CORE_RWLOCK_TIMEOUT + ); +} diff --git a/cpukit/score/src/corerwlockobtainread.c b/cpukit/score/src/corerwlockobtainread.c new file mode 100644 index 0000000000..c90bf02f07 --- /dev/null +++ b/cpukit/score/src/corerwlockobtainread.c @@ -0,0 +1,103 @@ +/* + * SuperCore RWLock Handler -- Obtain RWLock for reading + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +/*PAGE + * + * _CORE_rwlock_Obtain_for_reading + * + * This function waits for the rwlock to become available. Optionally, + * a limit may be placed on the duration of the spin. + * + * Input parameters: + * the_rwlock - the rwlock control block to initialize + * timeout_allowed - true if timeout allowed + * timeout - the maximum number of ticks to spin + * + * Output parameters: NONE + */ + +void _CORE_RWLock_Obtain_for_reading( + CORE_RWLock_Control *the_rwlock, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout, + CORE_RWLock_API_mp_support_callout api_rwlock_mp_support +) +{ + ISR_Level level; + Thread_Control *executing = _Thread_Executing; + + /* + * If unlocked, then OK to read. + * If locked for reading and no waiters, then OK to read. + * If any thread is waiting, then we wait. + */ + + _ISR_Disable( level ); + switch ( the_rwlock->current_state ) { + case CORE_RWLOCK_UNLOCKED: + the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING; + the_rwlock->number_of_readers += 1; + _ISR_Enable( level ); + executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL; + return; + + case CORE_RWLOCK_LOCKED_FOR_READING: { + Thread_Control *waiter; + waiter = _Thread_queue_First( &the_rwlock->Wait_queue ); + if ( !waiter ) { + the_rwlock->number_of_readers += 1; + _ISR_Enable( level ); + executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL; + return; + } + break; + } + case CORE_RWLOCK_LOCKED_FOR_WRITING: + break; + } + + /* + * If the thread is not willing to wait, then return immediately. + */ + + if ( !wait ) { + _ISR_Enable( level ); + executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE; + } + + /* + * We need to wait to enter this critical section + */ + + _Thread_queue_Enter_critical_section( &the_rwlock->Wait_queue ); + executing->Wait.queue = &the_rwlock->Wait_queue; + executing->Wait.id = id; + executing->Wait.option = CORE_RWLOCK_THREAD_WAITING_FOR_WRITE; + executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL; + _ISR_Enable( level ); + + _Thread_queue_Enqueue( &the_rwlock->Wait_queue, timeout ); + + /* return to API level so it can dispatch and we block */ +} diff --git a/cpukit/score/src/corerwlockobtainwrite.c b/cpukit/score/src/corerwlockobtainwrite.c new file mode 100644 index 0000000000..02e7906249 --- /dev/null +++ b/cpukit/score/src/corerwlockobtainwrite.c @@ -0,0 +1,93 @@ +/* + * SuperCore RWLock Handler -- Obtain RWLock for writing + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +/*PAGE + * + * _CORE_rwlock_Obtain_for_writing + * + * This function waits for the rwlock to become available. Optionally, + * a limit may be placed on the duration of the spin. + * + * Input parameters: + * the_rwlock - the rwlock control block to initialize + * timeout_allowed - true if timeout allowed + * timeout - the maximum number of ticks to spin + * + * Output parameters: NONE + */ + +void _CORE_RWLock_Obtain_for_writing( + CORE_RWLock_Control *the_rwlock, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout, + CORE_RWLock_API_mp_support_callout api_rwlock_mp_support +) +{ + ISR_Level level; + Thread_Control *executing = _Thread_Executing; + + /* + * If unlocked, then OK to read. + * Otherwise, we have to block. + * If locked for reading and no waiters, then OK to read. + * If any thread is waiting, then we wait. + */ + + _ISR_Disable( level ); + switch ( the_rwlock->current_state ) { + case CORE_RWLOCK_UNLOCKED: + the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING; + _ISR_Enable( level ); + executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL; + return; + + case CORE_RWLOCK_LOCKED_FOR_READING: + case CORE_RWLOCK_LOCKED_FOR_WRITING: + break; + } + + /* + * If the thread is not willing to wait, then return immediately. + */ + + if ( !wait ) { + _ISR_Enable( level ); + executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE; + } + + /* + * We need to wait to enter this critical section + */ + + _Thread_queue_Enter_critical_section( &the_rwlock->Wait_queue ); + executing->Wait.queue = &the_rwlock->Wait_queue; + executing->Wait.id = id; + executing->Wait.option = CORE_RWLOCK_THREAD_WAITING_FOR_WRITE; + executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL; + _ISR_Enable( level ); + + _Thread_queue_Enqueue( &the_rwlock->Wait_queue, timeout ); + + /* return to API level so it can dispatch and we block */ +} diff --git a/cpukit/score/src/corerwlockrelease.c b/cpukit/score/src/corerwlockrelease.c new file mode 100644 index 0000000000..5943785664 --- /dev/null +++ b/cpukit/score/src/corerwlockrelease.c @@ -0,0 +1,80 @@ +/* + * SuperCore RWLock Handler -- Release a RWLock + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +/*PAGE + * + * _CORE_RWLock_Release + * + * This function releases the rwlock. + * + * Input parameters: + * the_rwlock - the rwlock control block to initialize + * + * Output parameters: NONE + */ + +CORE_RWLock_Status _CORE_RWLock_Release( + CORE_RWLock_Control *the_rwlock +) +{ + ISR_Level level; + Thread_Control *executing = _Thread_Executing; + + /* + * If unlocked, then OK to read. + * Otherwise, we have to block. + * If locked for reading and no waiters, then OK to read. + * If any thread is waiting, then we wait. + */ + + _ISR_Disable( level ); + switch ( the_rwlock->current_state ) { + case CORE_RWLOCK_UNLOCKED: + _ISR_Enable( level ); + executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE; + return CORE_RWLOCK_SUCCESSFUL; + + case CORE_RWLOCK_LOCKED_FOR_READING: + the_rwlock->number_of_readers -= 1; + if ( the_rwlock->number_of_readers != 0 ) { + /* must be unlocked again */ + _ISR_Enable( level ); + return CORE_RWLOCK_SUCCESSFUL; + } + executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL; + break; + case CORE_RWLOCK_LOCKED_FOR_WRITING: + break; + } + + /* + * Implicitly transition to "unlocked" and find another thread interested + * in obtaining this rwlock. + */ + + /* XXX need to put read/write lock request indicator in Wait info */ + + /* XXX find one writer or multiple readers to take off */ + _ISR_Enable( level ); + return CORE_RWLOCK_SUCCESSFUL; +} diff --git a/cpukit/score/src/corespinlock.c b/cpukit/score/src/corespinlock.c new file mode 100644 index 0000000000..ff16057021 --- /dev/null +++ b/cpukit/score/src/corespinlock.c @@ -0,0 +1,56 @@ +/* + * SuperCore Spinlock Handler + * + * DESCRIPTION: + * + * This package is part of the implementation of the SuperCore Spinlock Handler. + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#if defined(RTEMS_MULTIPROCESSING) +#include +#endif + +/*PAGE + * + * _CORE_spinlock_Initialize + * + * This function initialize a spinlock and sets the initial value based + * on the given count. + * + * Input parameters: + * the_spinlock - the spinlock control block to initialize + * the_spinlock_attributes - the attributes specified at create time + * + * Output parameters: NONE + */ + +void _CORE_spinlock_Initialize( + CORE_spinlock_Control *the_spinlock, + CORE_spinlock_Attributes *the_spinlock_attributes +) +{ + + the_spinlock->Attributes = *the_spinlock_attributes; + + the_spinlock->lock = 0; + the_spinlock->users = 0; + the_spinlock->holder = 0; +} diff --git a/cpukit/score/src/corespinlockrelease.c b/cpukit/score/src/corespinlockrelease.c new file mode 100644 index 0000000000..05aec32c4c --- /dev/null +++ b/cpukit/score/src/corespinlockrelease.c @@ -0,0 +1,53 @@ +/* + * SuperCore Spinlock Handler -- Release a Spinlock + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +/*PAGE + * + * _CORE_spinlock_Release + * + * This function releases the spinlock. + * + * Input parameters: + * the_spinlock - the spinlock control block to initialize + * + * Output parameters: NONE + */ + +CORE_spinlock_Status _CORE_spinlock_Release( + CORE_spinlock_Control *the_spinlock +) +{ + ISR_Level level; + + _ISR_Disable( level ); + if ( the_spinlock->lock == CORE_SPINLOCK_UNLOCKED ) { + _ISR_Enable( level ); + return CORE_SPINLOCK_NOT_LOCKED; + } + + the_spinlock->users -= 1; + the_spinlock->lock = CORE_SPINLOCK_UNLOCKED; + the_spinlock->holder = 0; + _ISR_Enable( level ); + return CORE_SPINLOCK_SUCCESSFUL; +} diff --git a/cpukit/score/src/corespinlockwait.c b/cpukit/score/src/corespinlockwait.c new file mode 100644 index 0000000000..96c173855b --- /dev/null +++ b/cpukit/score/src/corespinlockwait.c @@ -0,0 +1,110 @@ +/* + * SuperCore Spinlock Handler -- Wait for Spinlock + * + * COPYRIGHT (c) 1989-2006. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +/*PAGE + * + * _CORE_spinlock_Wait + * + * This function waits for the spinlock to become available. Optionally, + * a limit may be placed on the duration of the spin. + * + * Input parameters: + * the_spinlock - the spinlock control block to initialize + * wait - true if willing to wait + * timeout - the maximum number of ticks to spin (0 is forever) + * + * Output parameters: NONE + */ + +CORE_spinlock_Status _CORE_spinlock_Wait( + CORE_spinlock_Control *the_spinlock, + boolean wait, + Watchdog_Interval timeout +) +{ + ISR_Level level; + Watchdog_Interval limit = _Watchdog_Ticks_since_boot + timeout; + + _ISR_Disable( level ); + if ( (the_spinlock->lock == CORE_SPINLOCK_LOCKED) && + (the_spinlock->holder == _Thread_Executing->Object.id) ) { + _ISR_Enable( level ); + return CORE_SPINLOCK_HOLDER_RELOCKING; + } + the_spinlock->users += 1; + for ( ;; ) { + if ( the_spinlock->lock == CORE_SPINLOCK_UNLOCKED ) { + the_spinlock->lock = CORE_SPINLOCK_LOCKED; + the_spinlock->holder = _Thread_Executing->Object.id; + _ISR_Enable( level ); + return CORE_SPINLOCK_SUCCESSFUL; + } + + /* + * Spinlock is unavailable. If not willing to wait, return. + */ + if ( !wait ) { + the_spinlock->users -= 1; + _ISR_Enable( level ); + return CORE_SPINLOCK_UNAVAILABLE; + } + + /* + * They are willing to wait but there could be a timeout. + */ + if ( timeout && (limit >= _Watchdog_Ticks_since_boot)) { + the_spinlock->users -= 1; + _ISR_Enable( level ); + return CORE_SPINLOCK_TIMEOUT; + } + + /* + * The thread is willing to spin so let's set things up so + * another thread has a chance of running. This spinlock has + * to be released by either another thread or an ISR. Since + * POSIX does not say anything about ISRs, that implies that + * another thread must be able to run while spinning. We are + * not blocking so that implies we are at least preemptible + * and possibly time-sliced. + * + * So first, we will enable interrpts to allow for them to happen. + * Then we will "flash" the thread dispatching critical section + * so other threads have a chance to run. + * + * A spinlock cannot be deleted while it is being used so we are + * safe from deletion. + */ + + _ISR_Enable( level ); + /* An ISR could occur here */ + + _Thread_Enable_dispatch(); + /* Another thread could get dispatched here */ + + /* Reenter the critical sections so we can attempt the lock again. */ + _Thread_Disable_dispatch(); + + _ISR_Disable( level ); + } + +} -- cgit v1.2.3