Amiga.org
Amiga computer related discussion => Amiga/MorphOS/AROS Programmers Forum => Topic started by: nyteschayde on January 24, 2017, 05:30:58 PM
-
So, typically, there is a line in many Intuition loops that looks as follows:
Wait (1 << mywin->UserPort->mp_SigBit);
I presume that this is telling the OS that it shouldn't spend cycles on this code until a signal is sent via the window's UserPort via the mp_SigBit. This is typically important since this code is usually in a while(true) or while(trueUntilFlagSet) loop which could easily hog the CPU.
My questions are:
- Are my assumptions about the functionality correct?
- What is the significance of using bit shift operator here. Why 1 << mp_SigBit? Are there other values or messages that are potentially encoded in that signal? What would they be? How can we find them?
-
1. yes
2. Wait() takes a signal mask. This means you wait for each signal whose bit is set in the mask. This way you can wait for multiple signals at once. The mp_SigBit field contains the signal number, so you have to shift 1 by that number to get the right bit set in the mask.
There are a few signals which are reserved for the system. The most popular is the signal you receive when the user hits Ctrl-C: it has the signal number 12 (SIGBREAKB_CTRL_F) and the signal mask is 1 << 12 a.k.a. 0x1000 (SIGBREAKF_CTRL_C).
-
Thanks Thomas. You're my guru. So in this case, would you do something like the following if you wanted to wait for intuition based feedback *and* check for CTRL-C?
Wait(1 << mywin->UserPort->mp_SigBit | SIGBREAKF_CTRL_C);
-
Exactly. But you need to add more brackets because | is stronger than <<.
Wait( (1 << mywin->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C);
Normally you would do something like this:
window_signal = 1 << mywin->UserPort->mp_SigBit;
signals_received = Wait(window_signal | SIGBREAKF_CTRL_C);
if (signals_received & window_signal)
{
/* handle window input a.k.a. IDCMP */
}
if (signals_received & SIGBREAKF_CTRL_C)
{
/* handle Ctrl-C */
}