summaryrefslogtreecommitdiff
path: root/cpukit/rtems/src/taskinitusers.c
blob: 0b23d8bc86d7894bb2bff4ca68efedd9de25170a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * @file
 *
 * @ingroup ClassicTasks Tasks
 *
 * @brief _RTEMS_tasks_Initialize_user_tasks_body
 */

/*
 *  COPYRIGHT (c) 1989-2008.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems/rtems/tasksimpl.h>
#include <rtems/score/assert.h>
#include <rtems/score/threadimpl.h>
#include <rtems/score/interr.h>

void _RTEMS_tasks_Initialize_user_task( void )
{
  rtems_id                                id;
  rtems_status_code                       return_value;
  const rtems_initialization_tasks_table *user_task;
  rtems_task_entry                        entry_point;

  user_task = &_RTEMS_tasks_User_task_table;
  return_value = rtems_task_create(
    user_task->name,
    user_task->initial_priority,
    user_task->stack_size,
    user_task->mode_set,
    user_task->attribute_set,
    &id
  );
  if ( !rtems_is_status_successful( return_value ) ) {
    _Internal_error( INTERNAL_ERROR_RTEMS_INIT_TASK_CREATE_FAILED );
  }

  entry_point = user_task->entry_point;
  if ( entry_point == NULL ) {
    _Internal_error( INTERNAL_ERROR_RTEMS_INIT_TASK_ENTRY_IS_NULL );
  }

  return_value = rtems_task_start(
    id,
    entry_point,
    user_task->argument
  );
  _Assert( rtems_is_status_successful( return_value ) );
  (void) return_value;

  _Assert( _Thread_Global_constructor == 0 );
  _Thread_Global_constructor = id;
}