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

5
Last change on this file since 66cb142 was 1fcac5ad, checked in by Sebastian Huber <sebastian.huber@…>, on 07/25/16 at 14:35:37

score: Turn thread lock into thread wait lock

The _Thread_Lock_acquire() function had a potentially infinite run-time
due to the lack of fairness at atomic operations level.

Update #2412.
Update #2556.
Update #2765.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ClassicEventSystem
5 *
6 * @brief rtems_event_system_receive() implementation.
7 */
8
9/*
10 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#if HAVE_CONFIG_H
24  #include "config.h"
25#endif
26
27#include <rtems/rtems/eventimpl.h>
28#include <rtems/rtems/tasks.h>
29#include <rtems/score/statesimpl.h>
30#include <rtems/score/threadimpl.h>
31
32rtems_status_code rtems_event_system_receive(
33  rtems_event_set  event_in,
34  rtems_option     option_set,
35  rtems_interval   ticks,
36  rtems_event_set *event_out
37)
38{
39  rtems_status_code sc;
40
41  if ( event_out != NULL ) {
42    ISR_lock_Context   lock_context;
43    Thread_Control    *executing;
44    RTEMS_API_Control *api;
45    Event_Control     *event;
46
47    executing = _Thread_Wait_acquire_default_for_executing( &lock_context );
48    api = executing->API_Extensions[ THREAD_API_RTEMS ];
49    event = &api->System_event;
50
51    if ( !_Event_sets_Is_empty( event_in ) ) {
52      sc = _Event_Seize(
53        event_in,
54        option_set,
55        ticks,
56        event_out,
57        executing,
58        event,
59        THREAD_WAIT_CLASS_SYSTEM_EVENT,
60        STATES_WAITING_FOR_SYSTEM_EVENT,
61        &lock_context
62      );
63    } else {
64      *event_out = event->pending_events;
65      _Thread_Wait_release_default( executing, &lock_context );
66      sc = RTEMS_SUCCESSFUL;
67    }
68  } else {
69    sc = RTEMS_INVALID_ADDRESS;
70  }
71
72  return sc;
73}
Note: See TracBrowser for help on using the repository browser.