1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Scheduler CBS Get Remaining Budget |
---|
5 | * @ingroup ScoreScheduler |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (C) 2011 Petr Benes. |
---|
10 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/schedulercbs.h> |
---|
22 | #include <rtems/score/threadimpl.h> |
---|
23 | |
---|
24 | int _Scheduler_CBS_Get_remaining_budget ( |
---|
25 | Scheduler_CBS_Server_id server_id, |
---|
26 | time_t *remaining_budget |
---|
27 | ) |
---|
28 | { |
---|
29 | Scheduler_CBS_Server *server; |
---|
30 | ISR_lock_Context lock_context; |
---|
31 | Thread_Control *the_thread; |
---|
32 | |
---|
33 | if ( server_id >= _Scheduler_CBS_Maximum_servers ) { |
---|
34 | return SCHEDULER_CBS_ERROR_INVALID_PARAMETER; |
---|
35 | } |
---|
36 | |
---|
37 | server = &_Scheduler_CBS_Server_list[ server_id ]; |
---|
38 | |
---|
39 | if ( !server->initialized ) { |
---|
40 | return SCHEDULER_CBS_ERROR_NOSERVER; |
---|
41 | } |
---|
42 | |
---|
43 | if ( server->task_id == -1 ) { |
---|
44 | *remaining_budget = server->parameters.budget; |
---|
45 | return SCHEDULER_CBS_OK; |
---|
46 | } |
---|
47 | |
---|
48 | the_thread = _Thread_Get( server->task_id, &lock_context ); |
---|
49 | |
---|
50 | if ( the_thread != NULL ) { |
---|
51 | *remaining_budget = the_thread->cpu_time_budget; |
---|
52 | _ISR_lock_ISR_enable( &lock_context ); |
---|
53 | } else { |
---|
54 | *remaining_budget = 0; |
---|
55 | } |
---|
56 | |
---|
57 | return SCHEDULER_CBS_OK; |
---|
58 | } |
---|