source: rtems/cpukit/score/src/schedulercbsunblock.c @ 5618c37a

4.115
Last change on this file since 5618c37a was 5618c37a, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 13:14:48

score: Create thread implementation header

Move implementation specific parts of thread.h and thread.inl into new
header file threadimpl.h. The thread.h contains now only the
application visible API.

Remove superfluous header file includes from various files.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Unblocks a Thread from the Queue
5 *
6 * @ingroup ScoreScheduler
7 */
8
9/*
10 *  Copyright (C) 2011 Petr Benes.
11 *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/schedulercbs.h>
23#include <rtems/score/schedulerimpl.h>
24#include <rtems/score/threadimpl.h>
25#include <rtems/score/watchdogimpl.h>
26
27void _Scheduler_CBS_Unblock(
28  Thread_Control    *the_thread
29)
30{
31  Scheduler_CBS_Per_thread *sched_info;
32  Scheduler_CBS_Server *serv_info;
33  Priority_Control new_priority;
34
35  _Scheduler_EDF_Enqueue(the_thread);
36  /* TODO: flash critical section? */
37
38  sched_info = (Scheduler_CBS_Per_thread *) the_thread->scheduler_info;
39  serv_info = (Scheduler_CBS_Server *) sched_info->cbs_server;
40
41  /*
42   * Late unblock rule for deadline-driven tasks. The remaining time to
43   * deadline must be sufficient to serve the remaining computation time
44   * without increased utilization of this task. It might cause a deadline
45   * miss of another task.
46   */
47  if (serv_info) {
48    time_t deadline = serv_info->parameters.deadline;
49    time_t budget = serv_info->parameters.budget;
50    time_t deadline_left = the_thread->cpu_time_budget;
51    time_t budget_left = the_thread->real_priority -
52                           _Watchdog_Ticks_since_boot;
53
54    if ( deadline*budget_left > budget*deadline_left ) {
55      /* Put late unblocked task to background until the end of period. */
56      new_priority = the_thread->Start.initial_priority;
57      if ( the_thread->real_priority != new_priority )
58        the_thread->real_priority = new_priority;
59      if ( the_thread->current_priority != new_priority )
60        _Thread_Change_priority(the_thread, new_priority, true);
61    }
62  }
63
64  /*
65   *  If the thread that was unblocked is more important than the heir,
66   *  then we have a new heir.  This may or may not result in a
67   *  context switch.
68   *
69   *  Normal case:
70   *    If the current thread is preemptible, then we need to do
71   *    a context switch.
72   *  Pseudo-ISR case:
73   *    Even if the thread isn't preemptible, if the new heir is
74   *    a pseudo-ISR system task, we need to do a context switch.
75   */
76  if ( _Scheduler_Is_priority_higher_than( the_thread->current_priority,
77       _Thread_Heir->current_priority)) {
78    _Thread_Heir = the_thread;
79    if ( _Thread_Executing->is_preemptible ||
80         the_thread->current_priority == 0 )
81      _Thread_Dispatch_necessary = true;
82  }
83}
Note: See TracBrowser for help on using the repository browser.