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/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 ++- 6 files changed, 603 insertions(+), 17 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 (limited to 'cpukit/score/include') 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. */ -- cgit v1.2.3