Amiga.org

Amiga computer related discussion => Amiga/MorphOS/AROS Programmers Forum => Topic started by: nyteschayde on January 24, 2017, 05:30:58 PM

Title: Intuition Loops
Post by: nyteschayde on January 24, 2017, 05:30:58 PM
So, typically, there is a line in many Intuition loops that looks as follows:

Code: [Select]
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:

Title: Re: Intuition Loops
Post by: Thomas on January 25, 2017, 11:52:03 AM
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).
Title: Re: Intuition Loops
Post by: nyteschayde on January 25, 2017, 07:19:08 PM
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?

Code: [Select]
Wait(1 << mywin->UserPort->mp_SigBit | SIGBREAKF_CTRL_C);
Title: Re: Intuition Loops
Post by: Thomas on January 25, 2017, 09:15:24 PM
Exactly. But you need to add more brackets because | is stronger than <<.

Code: [Select]

Wait( (1 << mywin->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C);



Normally you would do something like this:

Code: [Select]

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 */
}