Welcome, Guest. Please login or register.

Author Topic: Intuition Loops  (Read 1721 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show only replies by nyteschayde
    • http://www.nyteshade.com
Intuition Loops
« 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:

  • 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?
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Online Thomas

Re: Intuition Loops
« Reply #1 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).

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show only replies by nyteschayde
    • http://www.nyteshade.com
Re: Intuition Loops
« Reply #2 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);
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Online Thomas

Re: Intuition Loops
« Reply #3 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 */
}