RTEMS
threadscheduler.c
1 /*
2  * Copyright (c) 2016 embedded brains GmbH. All rights reserved.
3  *
4  * embedded brains GmbH
5  * Dornierstr. 4
6  * 82178 Puchheim
7  * Germany
8  * <rtems@embedded-brains.de>
9  *
10  * The license and distribution terms for this file may be
11  * found in the file LICENSE in this distribution or at
12  * http://www.rtems.org/license/LICENSE.
13  */
14 
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
19 #include <rtems/score/threadimpl.h>
21 
22 #if defined(RTEMS_SMP)
24 {
25  ISR_lock_Context lock_context;
26  Scheduler_Node *scheduler_node;
27 
28  _Thread_Scheduler_acquire_critical( the_thread, &lock_context );
29 
30  scheduler_node = the_thread->Scheduler.requests;
31 
32  if ( scheduler_node != NULL ) {
33  Scheduler_Node *next;
34  Scheduler_Node *remove;
35 
36  the_thread->Scheduler.requests = NULL;
37  remove = NULL;
38 
39  do {
40  Scheduler_Node_request request;
41 
42  request = scheduler_node->Thread.request;
44 
45  next = scheduler_node->Thread.next_request;
46 #if defined(RTEMS_DEBUG)
47  scheduler_node->Thread.next_request = NULL;
48 #endif
49 
50  if ( request == SCHEDULER_NODE_REQUEST_ADD ) {
51  ++the_thread->Scheduler.helping_nodes;
53  &the_thread->Scheduler.Scheduler_nodes,
54  &scheduler_node->Thread.Scheduler_node.Chain
55  );
56  } else if ( request == SCHEDULER_NODE_REQUEST_REMOVE ) {
57  --the_thread->Scheduler.helping_nodes;
59  &scheduler_node->Thread.Scheduler_node.Chain
60  );
61  scheduler_node->Thread.Scheduler_node.next = remove;
62  remove = scheduler_node;
63  } else {
65  }
66 
67  scheduler_node = next;
68  } while ( scheduler_node != NULL );
69 
70  _Thread_Scheduler_release_critical( the_thread, &lock_context );
71 
72  scheduler_node = remove;
73 
74  while ( scheduler_node != NULL ) {
75  const Scheduler_Control *scheduler;
76  ISR_lock_Context lock_context;
77 
78  next = scheduler_node->Thread.Scheduler_node.next;
79 #if defined(RTEMS_DEBUG)
80  scheduler_node->Thread.Scheduler_node.next = NULL;
81 #endif
82 
83  scheduler = _Scheduler_Node_get_scheduler( scheduler_node );
84 
85  _Scheduler_Acquire_critical( scheduler, &lock_context );
86  ( *scheduler->Operations.withdraw_node )(
87  scheduler,
88  the_thread,
89  scheduler_node,
91  );
92  _Scheduler_Release_critical( scheduler, &lock_context );
93 
94  scheduler_node = next;
95  }
96  } else {
97  _Thread_Scheduler_release_critical( the_thread, &lock_context );
98  }
99 }
100 #endif
void _Thread_Scheduler_process_requests(Thread_Control *the_thread)
Process the thread&#39;s scheduler requests.
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).
Scheduler_Node * next_request
Link to the next scheduler node in the Thread_Control::Scheduler::requests list.
Inlined Routines Associated with the Manipulation of the Scheduler.
This thread is ready with respect to the scheduler.
Definition: thread.h:236
Thread_Scheduler_control Scheduler
Scheduler related control.
Definition: thread.h:764
void(* withdraw_node)(const Scheduler_Control *scheduler, Thread_Control *the_thread, Scheduler_Node *node, Thread_Scheduler_state next_state)
Withdraw node operation.
Definition: scheduler.h:130
Scheduler_Node_request
The scheduler node requests.
Definition: schedulernode.h:47
struct Scheduler_Node::@19 Thread
Block to register and manage this scheduler node in the thread control block of the owner of this sch...
Scheduler_Node * requests
List of pending scheduler node requests.
Definition: thread.h:316
Scheduler_Node_request request
The current scheduler node request.
There is a pending scheduler node request to remove this scheduler node from the Thread_Control::Sche...
Definition: schedulernode.h:63
size_t helping_nodes
Count of nodes scheduler nodes minus one.
Definition: thread.h:309
There is a pending scheduler node request to add this scheduler node to the Thread_Control::Scheduler...
Definition: schedulernode.h:57
static __inline__ void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Appends a node (unprotected).
Definition: chainimpl.h:680
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).
The scheduler node is not on the list of pending requests.
Definition: schedulernode.h:51
static __inline__ void _Chain_Extract_unprotected(Chain_Node *the_node)
Extracts this node (unprotected).
Definition: chainimpl.h:558
static __inline__ void _Thread_Scheduler_acquire_critical(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Acquires the lock context in a critical section.
Definition: threadimpl.h:1483
static __inline__ void _Thread_Scheduler_release_critical(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Releases the lock context in a critical section.
Definition: threadimpl.h:1497
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
Inlined Routines from the Thread Handler.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
The scheduler node is on the list of pending requests, but nothing should change. ...
Definition: schedulernode.h:69
union Scheduler_Node::@19::@22 Scheduler_node
Node to add this scheduler node to Thread_Control::Scheduler::Scheduler_nodes or a temporary remove l...
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100