source: rtems/cpukit/rtems/src/signalcatch.c @ ba316313

4.115
Last change on this file since ba316313 was ba316313, checked in by Sebastian Huber <sebastian.huber@…>, on 11/28/12 at 12:33:11

rtems: Add signal post switch extension on the fly

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Catch Signal
5 *  @ingroup ClassicSignal
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.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/rtems/status.h>
23#include <rtems/rtems/asr.h>
24#include <rtems/score/isr.h>
25#include <rtems/rtems/modes.h>
26#include <rtems/rtems/signal.h>
27#include <rtems/score/thread.h>
28#include <rtems/score/apiext.h>
29#include <rtems/rtems/tasks.h>
30
31static void _RTEMS_signal_Post_switch_hook( Thread_Control *executing )
32{
33  ISR_Level          level;
34  RTEMS_API_Control *api;
35  ASR_Information   *asr;
36  rtems_signal_set   signal_set;
37  Modes_Control      prev_mode;
38
39  api = executing->API_Extensions[ THREAD_API_RTEMS ];
40  if ( !api )
41    return;
42
43  /*
44   *  Signal Processing
45   */
46
47  asr = &api->Signal;
48
49  _ISR_Disable( level );
50    signal_set = asr->signals_posted;
51    asr->signals_posted = 0;
52  _ISR_Enable( level );
53
54
55  if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
56    return;
57
58  asr->nest_level += 1;
59  rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
60
61  (*asr->handler)( signal_set );
62
63  asr->nest_level -= 1;
64  rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
65
66}
67
68static API_extensions_Post_switch_control _RTEMS_signal_Post_switch = {
69  .hook = _RTEMS_signal_Post_switch_hook
70};
71
72rtems_status_code rtems_signal_catch(
73  rtems_asr_entry   asr_handler,
74  rtems_mode        mode_set
75)
76{
77  Thread_Control     *executing;
78  RTEMS_API_Control  *api;
79  ASR_Information    *asr;
80
81/* XXX normalize mode */
82  executing = _Thread_Executing;
83  api = (RTEMS_API_Control*)executing->API_Extensions[ THREAD_API_RTEMS ];
84  asr = &api->Signal;
85
86  _Thread_Disable_dispatch(); /* cannot reschedule while */
87                              /*   the thread is inconsistent */
88
89  _API_extensions_Add_post_switch( &_RTEMS_signal_Post_switch );
90
91  if ( !_ASR_Is_null_handler( asr_handler ) ) {
92    asr->mode_set = mode_set;
93    asr->handler = asr_handler;
94  }
95  else
96    _ASR_Initialize( asr );
97  _Thread_Enable_dispatch();
98  return RTEMS_SUCCESSFUL;
99}
Note: See TracBrowser for help on using the repository browser.