source: rtems/cpukit/posix/src/timerinserthelper.c @ f9a2d36

4.115
Last change on this file since f9a2d36 was f9a2d36, checked in by Sebastian Huber <sebastian.huber@…>, on 06/02/15 at 11:57:35

posix: Fix _POSIX_Timer_Insert_helper() locking

Close #2358.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Helper Routine for POSIX TIMERS
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  Helper routine for POSIX timers
10 *
11 *  COPYRIGHT (c) 1989-2007.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <time.h>
24
25#include <rtems/system.h>
26#include <rtems/seterr.h>
27#include <rtems/score/isr.h>
28#include <rtems/score/watchdogimpl.h>
29#include <rtems/posix/timerimpl.h>
30#include <rtems/posix/ptimer.h>
31
32bool _POSIX_Timer_Insert_helper(
33  Watchdog_Control               *timer,
34  Watchdog_Interval               ticks,
35  Objects_Id                      id,
36  Watchdog_Service_routine_entry  TSR,
37  void                           *arg
38)
39{
40  ISR_lock_Context  lock_context;
41  Watchdog_Header  *header;
42
43  _Watchdog_Remove_ticks( timer );
44
45  header = &_Watchdog_Ticks_header;
46  _Watchdog_Acquire( header, &lock_context );
47
48    /*
49     *  Check to see if the watchdog has just been inserted by a
50     *  higher priority interrupt.  If so, abandon this insert.
51     */
52    if ( timer->state != WATCHDOG_INACTIVE ) {
53      _Watchdog_Release( header, &lock_context );
54      return false;
55    }
56
57    /*
58     *  OK.  Now we now the timer was not rescheduled by an interrupt
59     *  so we can atomically initialize it as in use.
60     */
61    _Watchdog_Initialize( timer, TSR, id, arg );
62    timer->initial = ticks;
63    _Watchdog_Insert_locked( header, timer, &lock_context );
64  _Watchdog_Release( header, &lock_context );
65  return true;
66}
Note: See TracBrowser for help on using the repository browser.