1 | /* |
---|
2 | * Thread Handler |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1998. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * Copyright assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in found in the file LICENSE in this distribution or at |
---|
11 | * http://www.OARcorp.com/rtems/license.html. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/score/apiext.h> |
---|
18 | #include <rtems/score/context.h> |
---|
19 | #include <rtems/score/interr.h> |
---|
20 | #include <rtems/score/isr.h> |
---|
21 | #include <rtems/score/object.h> |
---|
22 | #include <rtems/score/priority.h> |
---|
23 | #include <rtems/score/states.h> |
---|
24 | #include <rtems/score/sysstate.h> |
---|
25 | #include <rtems/score/thread.h> |
---|
26 | #include <rtems/score/threadq.h> |
---|
27 | #include <rtems/score/userext.h> |
---|
28 | #include <rtems/score/wkspace.h> |
---|
29 | |
---|
30 | /*PAGE |
---|
31 | * |
---|
32 | * _Thread_Tickle_timeslice |
---|
33 | * |
---|
34 | * This scheduler routine determines if timeslicing is enabled |
---|
35 | * for the currently executing thread and, if so, updates the |
---|
36 | * timeslice count and checks for timeslice expiration. |
---|
37 | * |
---|
38 | * Input parameters: NONE |
---|
39 | * |
---|
40 | * Output parameters: NONE |
---|
41 | */ |
---|
42 | |
---|
43 | void _Thread_Tickle_timeslice( void ) |
---|
44 | { |
---|
45 | Thread_Control *executing; |
---|
46 | |
---|
47 | executing = _Thread_Executing; |
---|
48 | |
---|
49 | /* |
---|
50 | * Increment the number of ticks this thread has been executing |
---|
51 | */ |
---|
52 | |
---|
53 | executing->ticks_executed++; |
---|
54 | |
---|
55 | /* |
---|
56 | * If the thread is not preemptible or is not ready, then |
---|
57 | * just return. |
---|
58 | */ |
---|
59 | |
---|
60 | if ( !executing->is_preemptible ) |
---|
61 | return; |
---|
62 | |
---|
63 | if ( !_States_Is_ready( executing->current_state ) ) |
---|
64 | return; |
---|
65 | |
---|
66 | /* |
---|
67 | * The cpu budget algorithm determines what happens next. |
---|
68 | */ |
---|
69 | |
---|
70 | switch ( executing->budget_algorithm ) { |
---|
71 | case THREAD_CPU_BUDGET_ALGORITHM_NONE: |
---|
72 | break; |
---|
73 | |
---|
74 | case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE: |
---|
75 | case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE: |
---|
76 | if ( --executing->cpu_time_budget == 0 ) { |
---|
77 | _Thread_Reset_timeslice(); |
---|
78 | executing->cpu_time_budget = _Thread_Ticks_per_timeslice; |
---|
79 | } |
---|
80 | break; |
---|
81 | |
---|
82 | case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT: |
---|
83 | if ( --executing->cpu_time_budget == 0 ) |
---|
84 | (*executing->budget_callout)( executing ); |
---|
85 | break; |
---|
86 | } |
---|
87 | } |
---|