OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // This file implements runtime support for signal handling. | 5 // This file implements runtime support for signal handling. |
6 // | 6 // |
7 // Most synchronization primitives are not available from | 7 // Most synchronization primitives are not available from |
8 // the signal handler (it cannot block and cannot use locks) | 8 // the signal handler (it cannot block and cannot use locks) |
9 // so the handler communicates with a processing goroutine | 9 // so the handler communicates with a processing goroutine |
10 // via struct sig, below. | 10 // via struct sig, below. |
11 // | 11 // |
12 // Ownership for sig.Note passes back and forth between | 12 // Ownership for sig.Note passes back and forth between |
13 // the signal handler and the signal goroutine in rounds. | 13 // the signal handler and the signal goroutine in rounds. |
14 // The initial state is that sig.note is cleared (setup by siginit). | 14 // The initial state is that sig.note is cleared (setup by signal_enable). |
15 // At the beginning of each round, mask == 0. | 15 // At the beginning of each round, mask == 0. |
16 // The round goes through three stages: | 16 // The round goes through three stages: |
17 // | 17 // |
18 // (In parallel) | 18 // (In parallel) |
19 // 1a) One or more signals arrive and are handled | 19 // 1a) One or more signals arrive and are handled |
20 // by sigsend using cas to set bits in sig.mask. | 20 // by sigsend using cas to set bits in sig.mask. |
21 // The handler that changes sig.mask from zero to non-zero | 21 // The handler that changes sig.mask from zero to non-zero |
22 // calls notewakeup(&sig). | 22 // calls notewakeup(&sig). |
23 // 1b) Sigrecv calls notesleep(&sig) to wait for the wakeup. | 23 // 1b) Sigrecv calls notesleep(&sig) to wait for the wakeup. |
24 // | 24 // |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // Special case: want everything. | 140 // Special case: want everything. |
141 for(i=0; i<nelem(sig.wanted); i++) | 141 for(i=0; i<nelem(sig.wanted); i++) |
142 sig.wanted[i] = ~(uint32)0; | 142 sig.wanted[i] = ~(uint32)0; |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 if(s >= nelem(sig.wanted)*32) | 146 if(s >= nelem(sig.wanted)*32) |
147 return; | 147 return; |
148 sig.wanted[s/32] |= 1U<<(s&31); | 148 sig.wanted[s/32] |= 1U<<(s&31); |
149 } | 149 } |
OLD | NEW |