RTEMS
threadunpin.c
1 /*
2  * Copyright (c) 2018 embedded brains GmbH
3  *
4  * The license and distribution terms for this file may be
5  * found in the file LICENSE in this distribution or at
6  * http://www.rtems.org/license/LICENSE.
7  */
8 
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12 
14 
15 void _Thread_Do_unpin( Thread_Control *executing, Per_CPU_Control *cpu_self )
16 {
17  ISR_lock_Context state_lock_context;
18  ISR_lock_Context scheduler_lock_context;
19  Scheduler_Node *pinned_node;
20  const Scheduler_Control *pinned_scheduler;
21  Scheduler_Node *home_node;
22  const Scheduler_Control *home_scheduler;
23  const Scheduler_Control *scheduler;
24 
25  _Thread_State_acquire( executing, &state_lock_context );
26 
27  executing->Scheduler.pin_level = 0;
28 
29  pinned_node = SCHEDULER_NODE_OF_THREAD_SCHEDULER_NODE(
31  );
32  pinned_scheduler = _Scheduler_Node_get_scheduler( pinned_node );
33  home_node = _Thread_Scheduler_get_home_node( executing );
34  home_scheduler = _Thread_Scheduler_get_home( executing );
35  scheduler = pinned_scheduler;
36 
37  executing->Scheduler.pinned_scheduler = NULL;
38 
39  _Scheduler_Acquire_critical( scheduler, &scheduler_lock_context );
40 
41  if ( _Thread_Is_ready( executing ) ) {
42  ( *scheduler->Operations.block )( scheduler, executing, pinned_node );
43  }
44 
45  ( *scheduler->Operations.unpin )(
46  scheduler,
47  executing,
48  pinned_node,
49  cpu_self
50  );
51 
52  if ( home_node != pinned_node ) {
53  _Scheduler_Release_critical( scheduler, &scheduler_lock_context );
54 
57  &executing->Scheduler.Scheduler_nodes,
58  &home_node->Thread.Scheduler_node.Chain
59  );
60  scheduler = home_scheduler;
61 
62  _Scheduler_Acquire_critical( scheduler, &scheduler_lock_context );
63  }
64 
65  if ( _Thread_Is_ready( executing ) ) {
66  ( *scheduler->Operations.unblock )( scheduler, executing, home_node );
67  }
68 
69  _Scheduler_Release_critical( scheduler, &scheduler_lock_context );
70 
71  _Thread_State_release( executing, &state_lock_context );
72 }
static __inline__ Chain_Node * _Chain_First(const Chain_Control *the_chain)
Returns pointer to chain's first node.
Definition: chainimpl.h:260
static __inline__ void _Scheduler_Acquire_critical(const Scheduler_Control *scheduler, ISR_lock_Context *lock_context)
Acquires the scheduler instance inside a critical section (interrupts disabled).
static __inline__ const Scheduler_Control * _Thread_Scheduler_get_home(const Thread_Control *the_thread)
Gets the home scheduler of the thread.
Definition: threadimpl.h:1419
void(* block)(const Scheduler_Control *, Thread_Control *, Scheduler_Node *)
Definition: scheduler.h:58
Inlined Routines Associated with the Manipulation of the Scheduler.
void _Thread_Do_unpin(Thread_Control *executing, Per_CPU_Control *cpu_self)
Unpins the thread.
Definition: threadunpin.c:15
Thread_Scheduler_control Scheduler
Scheduler related control.
Definition: thread.h:764
static __inline__ void _Thread_State_release(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Releases the lock context and enables interrupts.
Definition: threadimpl.h:592
struct Scheduler_Node::@19 Thread
Block to register and manage this scheduler node in the thread control block of the owner of this sch...
static __inline__ void _Scheduler_Release_critical(const Scheduler_Control *scheduler, ISR_lock_Context *lock_context)
Releases the scheduler instance inside a critical section (interrupts disabled).
static __inline__ void _Chain_Prepend_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Prepends a node (unprotected).
Definition: chainimpl.h:732
int pin_level
The thread pinning to current processor level.
Definition: thread.h:338
Per CPU Core Structure.
Definition: percpu.h:347
static __inline__ Scheduler_Node * _Thread_Scheduler_get_home_node(const Thread_Control *the_thread)
Gets the scheduler's home node.
Definition: threadimpl.h:1438
void(* unpin)(const Scheduler_Control *scheduler, Thread_Control *the_thread, Scheduler_Node *node, struct Per_CPU_Control *cpu)
Unpin thread operation.
Definition: scheduler.h:160
static __inline__ void _Chain_Extract_unprotected(Chain_Node *the_node)
Extracts this node (unprotected).
Definition: chainimpl.h:558
void(* unblock)(const Scheduler_Control *, Thread_Control *, Scheduler_Node *)
Definition: scheduler.h:65
const struct _Scheduler_Control * pinned_scheduler
The pinned scheduler of this thread.
Definition: thread.h:263
Chain_Control Scheduler_nodes
Scheduler nodes immediately available to the schedulers for this thread.
Definition: thread.h:294
static __inline__ const Scheduler_Control * _Scheduler_Node_get_scheduler(const Scheduler_Node *node)
Gets the scheduler of the node.
Scheduler_Operations Operations
The scheduler operations.
Definition: scheduler.h:273
Scheduler control.
Definition: scheduler.h:264
Scheduler node for per-thread data.
Definition: schedulernode.h:79
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
static __inline__ bool _Thread_Is_ready(const Thread_Control *the_thread)
Checks if the thread is ready.
Definition: threadimpl.h:401
static __inline__ void _Thread_State_acquire(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Disables interrupts and acquires the lock_context.
Definition: threadimpl.h:542
union Scheduler_Node::@19::@22 Scheduler_node
Node to add this scheduler node to Thread_Control::Scheduler::Scheduler_nodes or a temporary remove l...