15 #ifndef _RTEMS_SCORE_MRSPIMPL_H 16 #define _RTEMS_SCORE_MRSPIMPL_H 20 #if defined(RTEMS_SMP) 84 _MRSP_Restore_priority_filter,
100 _Resource_Node_add_resource( &new_owner->Resource_node, &mrsp->Resource );
101 _Resource_Set_owner( &mrsp->Resource, &new_owner->Resource_node );
102 mrsp->initial_priority_of_owner = initial_priority;
103 _Scheduler_Thread_change_help_state( new_owner, SCHEDULER_HELP_ACTIVE_OWNER );
117 bool initially_locked
123 if ( initially_locked ) {
124 return MRSP_INVALID_NUMBER;
128 sizeof( *mrsp->ceiling_priorities ) * scheduler_count
130 if ( mrsp->ceiling_priorities == NULL ) {
131 return MRSP_NO_MEMORY;
134 for ( i = 0 ; i < scheduler_count ; ++i ) {
135 mrsp->ceiling_priorities[ i ] = ceiling_priority;
138 _Resource_Initialize( &mrsp->Resource );
142 return MRSP_SUCCESSFUL;
147 uint32_t scheduler_index
150 return mrsp->ceiling_priorities[ scheduler_index ];
155 uint32_t scheduler_index,
159 mrsp->ceiling_priorities[ scheduler_index ] = ceiling_priority;
167 MRSP_Rival *rival = arg;
168 MRSP_Control *mrsp = rival->resource;
176 if ( rival->status == MRSP_WAIT_FOR_OWNERSHIP ) {
179 _MRSP_Giant_acquire( &giant_lock_context );
182 _Resource_Node_extract( &thread->Resource_node );
183 _Resource_Node_set_dependency( &thread->Resource_node, NULL );
184 _Scheduler_Thread_change_help_state( thread, rival->initial_help_state );
185 _Scheduler_Thread_change_resource_root( thread, thread );
187 _MRSP_Giant_release( &giant_lock_context );
189 rival->status = MRSP_TIMEOUT;
209 bool initial_life_protection;
213 rival.thread = executing;
214 rival.resource = mrsp;
215 rival.initial_priority = initial_priority;
217 _MRSP_Giant_acquire( &giant_lock_context );
219 rival.initial_help_state =
220 _Scheduler_Thread_change_help_state( executing, SCHEDULER_HELP_ACTIVE_RIVAL );
221 rival.status = MRSP_WAIT_FOR_OWNERSHIP;
224 _Resource_Add_rival( &mrsp->Resource, &executing->Resource_node );
225 _Resource_Node_set_dependency( &executing->Resource_node, &mrsp->Resource );
226 _Scheduler_Thread_change_resource_root(
228 THREAD_RESOURCE_NODE_TO_THREAD( _Resource_Node_get_root( owner ) )
231 _MRSP_Giant_release( &giant_lock_context );
248 initial_life_protection = _Thread_Set_life_protection(
true );
251 _Assert( _Debug_Is_thread_dispatching_allowed() );
255 status = rival.status;
256 }
while ( status == MRSP_WAIT_FOR_OWNERSHIP );
258 _Thread_Set_life_protection( initial_life_protection );
261 _Watchdog_Remove_ticks( &executing->
Timer );
263 if ( status == MRSP_TIMEOUT ) {
264 _MRSP_Restore_priority( executing, initial_priority );
281 uint32_t scheduler_index = _Scheduler_Get_index( scheduler );
284 _MRSP_Get_ceiling_priority( mrsp, scheduler_index );
293 return MRSP_INVALID_PRIORITY;
297 owner = _Resource_Get_owner( &mrsp->Resource );
298 if ( owner == NULL ) {
299 _MRSP_Claim_ownership(
306 status = MRSP_SUCCESSFUL;
309 && _Resource_Node_get_root( owner ) != &executing->Resource_node
311 status = _MRSP_Wait_for_ownership(
323 status = MRSP_UNSATISFIED;
339 if ( _Resource_Get_owner( &mrsp->Resource ) != &executing->Resource_node ) {
341 return MRSP_NOT_OWNER_OF_RESOURCE;
347 &executing->Resource_node
351 return MRSP_INCORRECT_STATE;
354 initial_priority = mrsp->initial_priority_of_owner;
358 _MRSP_Giant_acquire( &giant_lock_context );
360 _Resource_Extract( &mrsp->Resource );
363 _Resource_Set_owner( &mrsp->Resource, NULL );
365 MRSP_Rival *rival = (MRSP_Rival *)
373 rival->status = MRSP_SUCCESSFUL;
375 new_owner = rival->thread;
376 mrsp->initial_priority_of_owner = rival->initial_priority;
377 _Resource_Node_extract( &new_owner->Resource_node );
378 _Resource_Node_set_dependency( &new_owner->Resource_node, NULL );
379 _Resource_Node_add_resource( &new_owner->Resource_node, &mrsp->Resource );
380 _Resource_Set_owner( &mrsp->Resource, &new_owner->Resource_node );
381 _Scheduler_Thread_change_help_state( new_owner, SCHEDULER_HELP_ACTIVE_OWNER );
382 _Scheduler_Thread_change_resource_root( new_owner, new_owner );
385 if ( !_Resource_Node_owns_resources( &executing->Resource_node ) ) {
386 _Scheduler_Thread_change_help_state( executing, SCHEDULER_HELP_YOURSELF );
389 _MRSP_Giant_release( &giant_lock_context );
394 _MRSP_Restore_priority( executing, initial_priority );
398 return MRSP_SUCCESSFUL;
403 if ( _Resource_Get_owner( &mrsp->Resource ) != NULL ) {
404 return MRSP_RESOUCE_IN_USE;
410 return MRSP_SUCCESSFUL;
RTEMS_INLINE_ROUTINE Priority_Control _Thread_Priority_highest(Priority_Control left, Priority_Control right)
Returns the highest priority of the left and right thread priorities in the intuitive sense of priori...
Definition: threadimpl.h:351
RTEMS_INLINE_ROUTINE void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Append a node (unprotected).
Definition: chainimpl.h:743
Scheduler control.
Definition: scheduler.h:192
Priority_Control current_priority
This field is the current priority state of this thread.
Definition: thread.h:683
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:205
#define _ISR_lock_Acquire(_lock, _context)
Acquires an ISR lock inside an ISR disabled section.
Definition: isrlock.h:257
Inlined Routines in the Watchdog Handler.
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
RTEMS_INLINE_ROUTINE void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
Definition: threaddispatch.h:304
Inlined Routines Associated with the Manipulation of the Scheduler.
#define _ISR_lock_Initialize(_lock, _name)
Initializes an ISR lock.
Definition: isrlock.h:167
RTEMS_INLINE_ROUTINE void _Chain_Extract_unprotected(Chain_Node *the_node)
Extract this node (unprotected).
Definition: chainimpl.h:639
void _Thread_Raise_priority(Thread_Control *the_thread, Priority_Control new_priority)
Raises the priority of a thread.
Definition: threadchangepriority.c:99
RTEMS_INLINE_ROUTINE void _Chain_Initialize_empty(Chain_Control *the_chain)
Initialize this chain as empty.
Definition: chainimpl.h:613
Resource node to reflect ownership of resources and a dependency on a resource.
Definition: resource.h:150
uint32_t Priority_Control
The following type defines the control block used to manage thread priorities.
Definition: priority.h:56
RTEMS_INLINE_ROUTINE bool _Chain_Is_empty(const Chain_Control *the_chain)
Is the chain empty.
Definition: chainimpl.h:499
RTEMS_INLINE_ROUTINE bool _Resource_Is_most_recently_obtained(const Resource_Control *resource, const Resource_Node *node)
Returns true if this is the most recently obtained resource of the node, and false otherwise...
Definition: resourceimpl.h:150
This structure defines the Thread Control Block (TCB).
Definition: thread.h:671
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:358
Per CPU Core Structure.
Definition: percpu.h:233
#define _ISR_lock_Release(_lock, _context)
Releases an ISR lock inside an ISR disabled section.
Definition: isrlock.h:279
Information Related to the RAM Workspace.
uint32_t resource_count
This field is the number of mutexes currently held by this thread.
Definition: thread.h:713
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:230
Priority_Control real_priority
This field is the base priority of this thread.
Definition: thread.h:691
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:83
RTEMS_INLINE_ROUTINE bool _Thread_Priority_less_than(Priority_Control left, Priority_Control right)
Returns true if the left thread priority is less than the right thread priority in the intuitive sens...
Definition: threadimpl.h:339
RTEMS_INLINE_ROUTINE void _Watchdog_Initialize(Watchdog_Control *the_watchdog, Watchdog_Service_routine_entry routine, Objects_Id id, void *user_data)
This routine initializes the specified watchdog.
Definition: watchdogimpl.h:299
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
Definition: watchdog.h:47
void _Workspace_Free(void *block)
Free memory to the workspace.
Definition: wkspace.c:172
Watchdog_Control Timer
This field is the Watchdog used to manage thread delays and timeouts.
Definition: thread.h:717
void _Thread_Change_priority(Thread_Control *the_thread, Priority_Control new_priority, void *arg, Thread_Change_priority_filter filter, bool prepend_it)
Changes the priority of a thread if allowed by the filter function.
Definition: threadchangepriority.c:25
RTEMS_INLINE_ROUTINE Chain_Node * _Chain_Get_first_unprotected(Chain_Control *the_chain)
Get the first node (unprotected).
Definition: chainimpl.h:667
RTEMS_INLINE_ROUTINE Per_CPU_Control * _Thread_Dispatch_disable_critical(const ISR_lock_Context *lock_context)
Disables thread dispatching inside a critical section (interrupts disabled).
Definition: threaddispatch.h:251
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
uint32_t Objects_Id
The following type defines the control block used to manage object IDs.
Definition: object.h:122
void * _Workspace_Allocate(size_t size)
Allocate memory from workspace.
Definition: wkspace.c:145
#define _ISR_lock_Destroy(_lock)
Destroys an ISR lock.
Definition: isrlock.h:181
RTEMS_INLINE_ROUTINE void _Watchdog_Insert_ticks(Watchdog_Control *the_watchdog, Watchdog_Interval units)
This routine inserts THE_WATCHDOG into the ticks watchdog chain for a time of UNITS ticks...
Definition: watchdogimpl.h:371
#define _Scheduler_Count
Count of registered schedulers.
Definition: scheduler.h:352