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