Waiting for events and select()

I’v seen this subject in the mailing list but without
a satisfying answer, so I’d like to bring this up
again:

in a graphics server I write (the berlin windowing system)
we have a thread responsible for event handling and redrawing.
The redrawing is done as a result of a ‘damage’ request for
some regions, which might come from arbitrary other sources
(other threads, other processes, etc.). In the current console
implementation, which is based on GGI, the following will
happen:

  • the event/drawing thread sleeps, waiting for an event
  • a different thread damages a region, waking up the other
    thread
  • thread one wakes up, repairs the damaged regions and goes
    back to sleep

The wait-for-event is implemented with a select() call, so
I can add my own fd’s, i.e. in the case above a simple pipe
which other threads can write a character into just to make
the main thread return from select().

For various reasons I’d like to be able to implement the
console layer in berlin with SDL as well, so I’m looking for
a way to do the above with SDL API. Unfortunately, it appears
as if there is no event waiting mechanism which allows me to
add my own sources or to interrupt the WaitEvent call.

Can you help me ?

Thanks a lot, Stefan_______________________________________________________

Stefan Seefeld
Departement de Physique
Universite de Montreal
email: @Stefan_Seefeld


  ...ich hab' noch einen Koffer in Berlin...

Stefan Seefeld wrote:

For various reasons I’d like to be able to implement the
console layer in berlin with SDL as well, so I’m looking for
a way to do the above with SDL API. Unfortunately, it appears
as if there is no event waiting mechanism which allows me to
add my own sources or to interrupt the WaitEvent call.

What would be nice would be to have a function to get a fd (or an HANDLE
in some unnamed OS) from SDL that could be used with
select()/poll()/WaitForMultipleObjects() (not sure of that last one).
With the X implementation, it could just pass the X fd, with others it
could create a pipe and write a byte into it from a SIGIO handler to
wake up the application…

Stefan Seefeld
Departement de Physique
Universite de Montreal
email: seefelds at magellan.umontreal.ca

UdeM? I didn’t know you were in Montr?al, Stefan! It would be great to
meet and discuss… :-)–
“Unix is the worst operating system; except for all others.”
– Berry Kercheval

What would be nice would be to have a function to get a fd (or an HANDLE
in some unnamed OS) from SDL that could be used with
select()/poll()/WaitForMultipleObjects() (not sure of that last one).
With the X implementation, it could just pass the X fd, with others it
could create a pipe and write a byte into it from a SIGIO handler to
wake up the application…

You can already get this from SDL by using the SDL_syswm.h interfaces.
Unfortunately SDL also handles other types of events, such as joysticks,
user events, signals, etc. that also need to be handled.

I have possibly a better solution which I’ll suggest when I get a chance.

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

I’v seen this subject in the mailing list but without
a satisfying answer, so I’d like to bring this up
again:

For various reasons I’d like to be able to implement the
console layer in berlin with SDL as well, so I’m looking for
a way to do the above with SDL API. Unfortunately, it appears
as if there is no event waiting mechanism which allows me to
add my own sources or to interrupt the WaitEvent call.

Can you help me ?

I would recommend that you create a user event and add it to the
SDL event queue with the function SDL_PushEvent():
http://sdldoc.sourceforge.net/r4347.htm

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sam Lantinga wrote:

For various reasons I’d like to be able to implement the
console layer in berlin with SDL as well, so I’m looking for
a way to do the above with SDL API. Unfortunately, it appears
as if there is no event waiting mechanism which allows me to
add my own sources or to interrupt the WaitEvent call.

Can you help me ?

I would recommend that you create a user event and add it to the
SDL event queue with the function SDL_PushEvent():
http://sdldoc.sourceforge.net/r4347.htm

This would work from another thread? Nice…–
“Unix is the worst operating system; except for all others.”
– Berry Kercheval

Sam Lantinga wrote:

For various reasons I’d like to be able to implement the
console layer in berlin with SDL as well, so I’m looking for
a way to do the above with SDL API. Unfortunately, it appears
as if there is no event waiting mechanism which allows me to
add my own sources or to interrupt the WaitEvent call.

Can you help me ?

I would recommend that you create a user event and add it to the
SDL event queue with the function SDL_PushEvent():
http://sdldoc.sourceforge.net/r4347.htm

This would work from another thread? Nice…

Yup, the queue is completely thread-safe.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software