Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6299d1e

Browse files
committed
Speed up checking for signals and define intrcheck differently
1 parent c50158e commit 6299d1e

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

Modules/signalmodule.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3030
#include "intrcheck.h"
3131

3232
#include <signal.h>
33+
#include <errno.h>
3334

3435
struct signalhandler_list {
3536
int tripped;
3637
object *func;
3738
};
3839

3940
static struct signalhandler_list sig_list[NSIG];
41+
static int tripped = 0; /* Speed up sigcheck() when none tripped */
4042

4143
static object *default_sig_object;
4244
static object *default_ignore_object;
@@ -55,6 +57,7 @@ static RETSIGTYPE
5557
signal_handler(sig_num)
5658
int sig_num;
5759
{
60+
tripped++;
5861
sig_list[sig_num].tripped = 1;
5962
(void *)signal(sig_num, &signal_handler);
6063
}
@@ -148,7 +151,7 @@ initsignal()
148151

149152
sig_list[0].tripped = 0;
150153
for (i = 1; i < NSIG; i++) {
151-
void *t; /* type cop-out */
154+
RETSIGTYPE (*t)();
152155
t = signal(i, SIG_IGN);
153156
signal(i, t);
154157
sig_list[i].tripped = 0;
@@ -313,7 +316,10 @@ int
313316
sigcheck()
314317
{
315318
int i;
316-
object *f = getframe();
319+
object *f;
320+
if (!tripped)
321+
return 0;
322+
f = getframe();
317323
if (f == NULL)
318324
f = None;
319325
for (i = 1; i < NSIG; i++) {
@@ -334,6 +340,7 @@ sigcheck()
334340
}
335341
}
336342
}
343+
tripped = 0;
337344
return 0;
338345
}
339346

@@ -348,8 +355,9 @@ initintr()
348355
int
349356
intrcheck()
350357
{
351-
if (!sigcheck())
352-
return 0;
353-
err_clear();
354-
return 1;
358+
if (sig_list[SIGINT].tripped) {
359+
sig_list[SIGINT].tripped = 0;
360+
return 1;
361+
}
362+
return 0;
355363
}

0 commit comments

Comments
 (0)