diff options
author | Jan Kanis <jan.code@jankanis.nl> | 2012-12-23 16:37:43 +0100 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-12-24 23:06:09 -0800 |
commit | fde9842a8e552ab62900ccbdfc6e15e984a746ba (patch) | |
tree | 97246b4124bbfb0a378c0b17687f689862d3519c /event.cpp | |
parent | 3bf88110aa9a39f530680b4f72bca29be0637e5b (diff) |
fix signal race
Diffstat (limited to 'event.cpp')
-rw-r--r-- | event.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -40,15 +40,15 @@ typedef struct /** Number of delivered signals */ - int count; + volatile int count; /** Whether signals have been skipped */ - int overflow; + volatile int overflow; /** Array of signal events */ - int signal[SIG_UNHANDLED_MAX]; + volatile int signal[SIG_UNHANDLED_MAX]; } signal_list_t; @@ -62,7 +62,7 @@ static signal_list_t sig_list[]= {{0,0},{0,0}}; /** The index of sig_list that is the list of signals currently written to */ -static int active_list=0; +static volatile int active_list=0; typedef std::vector<event_t *> event_list_t; @@ -576,23 +576,26 @@ static void event_fire_delayed() blocked.swap(new_blocked); } - while (sig_list[active_list].count > 0) + int al = active_list; + + while (sig_list[al].count > 0) { signal_list_t *lst; /* Switch signal lists */ - sig_list[1-active_list].count=0; - sig_list[1-active_list].overflow=0; - active_list=1-active_list; + sig_list[1-al].count=0; + sig_list[1-al].overflow=0; + al = 1-al; + active_list=al; /* Set up */ + lst = &sig_list[1-al]; event_t e = event_t::signal_event(0); e.arguments.resize(1); - lst = &sig_list[1-active_list]; if (lst->overflow) { |