1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Attach Scheduler CBS Thread |
---|
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_Attach_thread ( |
---|
25 | Scheduler_CBS_Server_id server_id, |
---|
26 | rtems_id task_id |
---|
27 | ) |
---|
28 | { |
---|
29 | Objects_Locations location; |
---|
30 | Thread_Control *the_thread; |
---|
31 | |
---|
32 | if ( server_id >= _Scheduler_CBS_Maximum_servers ) |
---|
33 | return SCHEDULER_CBS_ERROR_INVALID_PARAMETER; |
---|
34 | |
---|
35 | /* Server is not valid. */ |
---|
36 | if ( !_Scheduler_CBS_Server_list[server_id] ) |
---|
37 | return SCHEDULER_CBS_ERROR_NOSERVER; |
---|
38 | |
---|
39 | /* Server is already attached to a thread. */ |
---|
40 | if ( _Scheduler_CBS_Server_list[server_id]->task_id != -1 ) |
---|
41 | return SCHEDULER_CBS_ERROR_FULL; |
---|
42 | |
---|
43 | the_thread = _Thread_Get(task_id, &location); |
---|
44 | /* The routine _Thread_Get may disable dispatch and not enable again. */ |
---|
45 | if ( the_thread ) { |
---|
46 | Scheduler_CBS_Per_thread *sched_info; |
---|
47 | |
---|
48 | sched_info = (Scheduler_CBS_Per_thread *) the_thread->scheduler_info; |
---|
49 | |
---|
50 | /* Thread is already attached to a server. */ |
---|
51 | if ( sched_info->cbs_server ) { |
---|
52 | _Objects_Put( &the_thread->Object ); |
---|
53 | return SCHEDULER_CBS_ERROR_FULL; |
---|
54 | } |
---|
55 | |
---|
56 | _Scheduler_CBS_Server_list[server_id]->task_id = task_id; |
---|
57 | sched_info->cbs_server = (void *) _Scheduler_CBS_Server_list[server_id]; |
---|
58 | |
---|
59 | the_thread->budget_callout = _Scheduler_CBS_Budget_callout; |
---|
60 | the_thread->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT; |
---|
61 | the_thread->is_preemptible = true; |
---|
62 | |
---|
63 | _Objects_Put( &the_thread->Object ); |
---|
64 | } else { |
---|
65 | return SCHEDULER_CBS_ERROR_INVALID_PARAMETER; |
---|
66 | } |
---|
67 | |
---|
68 | return SCHEDULER_CBS_OK; |
---|
69 | } |
---|