source: rtems/cpukit/rtems/src/taskwakewhen.c @ 66cb142

5
Last change on this file since 66cb142 was ed24ed4e, checked in by Sebastian Huber <sebastian.huber@…>, on 02/08/18 at 09:47:16

Use _Thread_Dispatch_direct()

Use _Thread_Dispatch_direct() for operations that block the executing
thread. This ensures that we get a fatal error
(INTERNAL_ERROR_BAD_THREAD_DISPATCH_DISABLE_LEVEL) if we try to block in
an invalid context, e.g. during system start or an interrupt handler.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Task Wake When
5 *  @ingroup ClassicTasks
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
10 *  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/rtems/tasks.h>
22#include <rtems/rtems/clock.h>
23#include <rtems/score/threadimpl.h>
24#include <rtems/score/todimpl.h>
25#include <rtems/score/watchdogimpl.h>
26
27rtems_status_code rtems_task_wake_when(
28  rtems_time_of_day *time_buffer
29)
30{
31  uint32_t         seconds;
32  Thread_Control  *executing;
33  Per_CPU_Control *cpu_self;
34
35  if ( !_TOD_Is_set() )
36    return RTEMS_NOT_DEFINED;
37
38  if ( !time_buffer )
39    return RTEMS_INVALID_ADDRESS;
40
41  time_buffer->ticks = 0;
42
43  if ( !_TOD_Validate( time_buffer ) )
44    return RTEMS_INVALID_CLOCK;
45
46  seconds = _TOD_To_seconds( time_buffer );
47
48  if ( seconds <= _TOD_Seconds_since_epoch() )
49    return RTEMS_INVALID_CLOCK;
50
51  cpu_self = _Thread_Dispatch_disable();
52    executing = _Per_CPU_Get_executing( cpu_self );
53    _Thread_Set_state( executing, STATES_WAITING_FOR_TIME );
54    _Thread_Wait_flags_set( executing, THREAD_WAIT_STATE_BLOCKED );
55    _Thread_Timer_insert_realtime(
56      executing,
57      cpu_self,
58      _Thread_Timeout,
59      _Watchdog_Ticks_from_seconds( seconds )
60    );
61  _Thread_Dispatch_direct( cpu_self );
62  return RTEMS_SUCCESSFUL;
63}
Note: See TracBrowser for help on using the repository browser.