|
|
1.1 root 1: #include "task.h"
2:
3: const NASS = NSIG;
4:
5: static Interrupt_handler* hnd[NASS]; // hnd[i] is used for signal i
6: // static SIG_TYP old_handlers[NASS]; // for old compilers
7: static SIG_FUNC_TYP* old_handlers[NASS];
8:
9: Interrupt_alerter::Interrupt_alerter()
10: : ("Interrupt_alerter")
11: {
12: for(;;) {
13: sleep();
14: // fprintf(stderr, "Interrupt_alerter loop\n");
15: for (register Interrupt_handler** p = &hnd[0]; p < &hnd[NASS]; p++)
16: if (*p && (*p)->got_interrupt)
17: (*p)->alert();
18: }
19: }
20:
21: void
22: sigFunc(int sigNo
23: #ifdef BSD
24: , int, sigcontext*
25: #endif
26: )
27: {
28: // fprintf(stderr, "signal #%d\n", sigNo);
29: if ((unsigned)sigNo >= (unsigned)NASS)
30: ((object*)0)->task_error (E_BADSIG);
31: Interrupt_handler* as = hnd[sigNo];
32: if (as == 0)
33: ((object*)0)->task_error(E_NO_HNDLR);
34: as->interrupt();
35: as->got_interrupt = 1;
36: sched::priority_sched = &interrupt_alerter;
37: signal(sigNo, sigFunc);
38: // fprintf(stderr, "return from interrupt #%d\n", sigNo);
39: return;
40: }
41:
42: Interrupt_handler::Interrupt_handler(int vecid)
43: : id(vecid), got_interrupt(0)
44: {
45: // fprintf(stderr, "Interrupt_handler::Interrupt_handler #%d\n", vecid);
46: if ((unsigned)id >= (unsigned)NASS)
47: task_error(E_BADSIG);
48: if((old = hnd[id]) == 0)
49: old_handlers[id] = signal(id, sigFunc);
50: else
51: if (old->got_interrupt)
52: old->alert();
53: hnd[id] = this;
54: this_task()->keep_waiting();
55: }
56:
57: Interrupt_handler::~Interrupt_handler()
58: {
59: // fprintf(stderr, "Interrupt_handler::~Interrupt_handler #%d\n", id);
60: this_task()->dont_wait();
61: for(register Interrupt_handler** as = &hnd[id];; as = &(*as)->old) {
62: if (*as == this) break;
63: if (*as == 0)
64: task_error(E_LOSTHNDLR);
65: }
66: if ((*as = old) == 0)
67: signal(id, old_handlers[id]);
68: }
69:
70: void
71: Interrupt_handler::interrupt()
72: {
73: }
74:
75: int
76: Interrupt_handler::pending()
77: {
78: if (!got_interrupt)
79: return 1;
80: got_interrupt = 0;
81: return 0;
82: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.