Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix signal race

  • Loading branch information...
commit fde9842a8e552ab62900ccbdfc6e15e984a746ba 1 parent 3bf8811
@JanKanis JanKanis authored ridiculousfish committed
Showing with 12 additions and 9 deletions.
  1. +12 −9 event.cpp
View
21 event.cpp
@@ -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)
{

0 comments on commit fde9842

Please sign in to comment.
Something went wrong with that request. Please try again.