| 1 | # HG changeset patch |
|---|
| 2 | # User Jeroen Demeyer <jdemeyer@cage.ugent.be> |
|---|
| 3 | # Date 1333960909 -7200 |
|---|
| 4 | # Node ID b66fce9af3c17e52975f7a7d2fbae96a3af2da7c |
|---|
| 5 | # Parent 8b937382f6df038b680e6a91fdcd0f830ecbd0ef |
|---|
| 6 | Make sig_on() into a macro |
|---|
| 7 | |
|---|
| 8 | diff --git a/c_lib/include/interrupt.h b/c_lib/include/interrupt.h |
|---|
| 9 | --- a/c_lib/include/interrupt.h |
|---|
| 10 | +++ b/c_lib/include/interrupt.h |
|---|
| 11 | @@ -170,7 +170,46 @@ |
|---|
| 12 | * a short-circuiting operator (the second argument is only evaluated |
|---|
| 13 | * if the first returns 0). |
|---|
| 14 | */ |
|---|
| 15 | -#define _sig_on_(message) ( unlikely(_sig_on_prejmp(message, __FILE__, __LINE__)) || _sig_on_postjmp(sigsetjmp(_signals.env,0)) ) |
|---|
| 16 | +//#define _sig_on_(message) ( unlikely(_sig_on_prejmp(message, __FILE__, __LINE__)) || _sig_on_postjmp(sigsetjmp(_signals.env,0)) ) |
|---|
| 17 | +#define _sig_on_(message) \ |
|---|
| 18 | +( \ |
|---|
| 19 | + /* Set message if called as sig_str() */ \ |
|---|
| 20 | + _signals.s = message, \ |
|---|
| 21 | + \ |
|---|
| 22 | + (ENABLE_DEBUG_INTERRUPT == 0) ? 0 : \ |
|---|
| 23 | + ( \ |
|---|
| 24 | + fprintf(stderr, "sig_on (counter = %i) at %s:%i\n", _signals.sig_on_count+1, __FILE__, __LINE__), \ |
|---|
| 25 | + fflush(stderr) \ |
|---|
| 26 | + ), \ |
|---|
| 27 | + \ |
|---|
| 28 | + _signals.sig_on_count > 0 ? \ |
|---|
| 29 | + /* If we are already inside sig_on, simply increase the reference counter */ \ |
|---|
| 30 | + (++_signals.sig_on_count, 1) \ |
|---|
| 31 | + : \ |
|---|
| 32 | + ( \ |
|---|
| 33 | + /* At this point, _signals.sig_on_count == 0 */ \ |
|---|
| 34 | + unlikely(sigsetjmp(_signals.env, 0) > 0) ? \ |
|---|
| 35 | + ( \ |
|---|
| 36 | + /* An exception occured */ \ |
|---|
| 37 | + _sig_on_recover(), \ |
|---|
| 38 | + 0 \ |
|---|
| 39 | + ) \ |
|---|
| 40 | + : \ |
|---|
| 41 | + ( \ |
|---|
| 42 | + /* When we are here, it's either the original sig_on() call or we \ |
|---|
| 43 | + * got here after sig_retry(). */ \ |
|---|
| 44 | + _signals.sig_on_count = 1, \ |
|---|
| 45 | + \ |
|---|
| 46 | + /* Check whether we received an interrupt before this point. \ |
|---|
| 47 | + * _signals.interrupt_received can only be set by the interrupt \ |
|---|
| 48 | + * handler if _signals.sig_on_count is zero. Because of that and \ |
|---|
| 49 | + * because _signals.sig_on_count and _signals.interrupt_received are \ |
|---|
| 50 | + * volatile, we can safely evaluate _signals.interrupt_received here \ |
|---|
| 51 | + * without race conditions. */ \ |
|---|
| 52 | + unlikely(_signals.interrupt_received) ? _sig_on_interrupt_received() : 1 \ |
|---|
| 53 | + ) \ |
|---|
| 54 | + ) \ |
|---|
| 55 | +) |
|---|
| 56 | |
|---|
| 57 | /* This will be called during _sig_on_postjmp() when a SIGINT was |
|---|
| 58 | * received *before* the call to sig_on(). |
|---|