[comp.sys.sun] Notifier question

mike@ames.arc.nasa.gov (Mike Smithwick) (04/26/89)

How do I "poll" the nofier while I am in a tight processing loop? I want
to check for a menu selection or button event so the user can quit the
operation if he(she) doesn't want to wait 3 minutes for it to complete.

What I am doing is simply. . .

main()
{

 . . .

 window_main_loop();

}

do_some_funky_stuff_notifier_proc()
{

   for(i=0;i<A_FEW_ZILLION;I++) 
   {
      [what can I do here to handle normal notifier events?]
   }
}


I tried to put an explicit call to notify_dispatch() in the loop, since
that is supposed check for events and call the appropriate routines, but
I gather if we're already in a notifier proc, the notifier event handling
is blocked to prevent us from attepting some recursive nonsense.


          *** mike (cerbral GURU, insert M&Ms to restart) smithwick***
"Oh, I'm just a NOP in the instruction set of life, oh, ohhhh, hmmmmm"

[disclaimer : nope, I don't work for NASA, I take full blame for my ideas]

weiser.pa@xerox.com (06/08/89)

It is a frequent question: "How do I "poll" the nofier while I am in a
tight processing loop?" Calling "notify_dispatch()" in the loop does not
work.  I use the following routine to force the poll, called
"window_update".  Its a kludge, but it works, because the notifier has to
take control around I/O calls, so this gets it a chance to get in and
handle some buttons, screen refreshes, signals, whatever.  Stick a call to
"window_update()" in your tight loop... (but not too often: "select" is
expensive.)

window_update()
{
  int width = 0;
  fd_set  readfds, writefds, exceptfds;
  struct timeval real_timeout;
  FD_ZERO(&writefds);
  FD_ZERO(&readfds);
  FD_ZERO(&exceptfds);
  real_timeout.tv_sec = 0;
  real_timeout.tv_usec = 0;
  select(width, &readfds, &writefds, &exceptfds, &real_timeout);
}

pereira@warbucks.ai.sri.com (Fernando Pereira) (06/09/89)

Mark Weiser (weiser.pa@xerox.com) suggests that "select" will more
reliably wake up window updating than "notify_dispatch". However, it
should be noted that libsunwindows.a defines its own version of "select"
in one of the notifier modules, so the call to "select" is doing more than
just calling the kernel "select".  In our own code, we have used
"notify_dispatch" extensively to wake up our windows outside
window_main_loop without problems, *except* for occasional delays of a few
seconds reacting events (mouse or keyboard). I may try to use the "select"
trick instead to see whether there is any difference in behavior. 

Fernando Pereira
AI Center, SRI International
pereira@ai.sri.com