Hi,

In message "[ruby-talk:01550] Re: Ruby/GTK and the mainloop"
    on 00/02/23, Ian Main <imain / gtk.org> writes:

|Yes, what I did was change the idle () function:
|
|static gint
|idle()
|{
|    struct timeval wait;
|    
|    wait.tv_sec  = 0;
|    wait.tv_usec = 1000; /* 100ms */
|    
|    CHECK_INTS;
|    if (!rb_thread_critical) rb_thread_wait_for(wait);
|  
|    return Qtrue;
|}
|
|If I am correct, what ends up happening in rb_thread_wait_for (), is that it
|calls thread_schedule with a timeout of (in this case) 100ms.  If there are
|no other active threads, it sits in select for 100ms, and then returns to
|give gtk a chance to run.  Changing the above to 10ms, means that gtk gets
|control back faster (so long as no other ruby threads are running).

Since you don't need to run idle function when there's only one
thread, you may use rb_thread_alone() to check threads.  It returns
true if there is only one thread (main_thread).

|GTK has good facilities for this.. from looking through ruby source code
|again, it looks like ruby needs only:
|
|* The ablity watch file descriptors for read/write readiness.
|* A timeout for sleep() and similar functions.
|
|What we can do is extrapolate that in the ruby core, so that when ruby needs
|these facilities, it calls a specific function in ruby.  We then set it up
|so that in the end these use function pointers, defaulting to the native
|ruby versions.  A function in ruby could then allow us to override these
|functions inside ruby, and in the case of the gtk bindings, they would
|provide ruby-compatible wrappers around gdk_input_add (), and
|gtk_timeout_add ().

Hmm, I have to participate in this discussion bit more seriously if
core modification needed. :-)

I haven't get the picture well yet.  Two features above can solve the
slow gtk problem?  Technically speaking, those features are fairly
easy to implement, except we need to decide *good* API beforehand.

|Yes, that's exactly why.  GTK is only getting a chance to refresh the screen
|every 100ms, which is noticible when scrolling, or typing etc.

Gtk's idle() function called too often.  How about using
gtk_add_timeout() again, like before?  What was the problem?

							matz.