Changeset 419

Show
Ignore:
Timestamp:
01/31/2008 16:22:04 (7 months ago)
Author:
why
Message:
  • shoes/app.c: wonderful patch from erik eriksson which reduces shoes cpu use under gtk by getting rid of the idle event and using glib's main loop to schedule ruby threads. this is totally luxurious, thanks erik!
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/shoes/app.c

    r402 r419  
    7979} 
    8080 
    81 static gboolean 
    82 shoes_app_gtk_idle(gpointer data) 
    83 { 
    84   rb_rescue2(shoes_app_gtk_sleep, Qnil, shoes_app_gtk_exception, Qnil, rb_cObject, 0); 
    85   return TRUE; 
    86 } 
     81static gint                                                                                                                    
     82shoes_app_gtk_poll (GPollFD *fds, 
     83           guint    nfds, 
     84           gint     timeout) 
     85{ 
     86    struct timeval tv; 
     87    fd_set rset, wset, xset; 
     88    GPollFD *f; 
     89    int ready; 
     90    int maxfd = 0; 
     91 
     92    FD_ZERO (&rset); 
     93    FD_ZERO (&wset); 
     94    FD_ZERO (&xset); 
     95 
     96    for (f = fds; f < &fds[nfds]; ++f) 
     97       if (f->fd >= 0) 
     98       { 
     99           if (f->events & G_IO_IN) 
     100               FD_SET (f->fd, &rset); 
     101           if (f->events & G_IO_OUT) 
     102               FD_SET (f->fd, &wset); 
     103           if (f->events & G_IO_PRI) 
     104               FD_SET (f->fd, &xset); 
     105           if (f->fd > maxfd && (f->events & (G_IO_IN|G_IO_OUT|G_IO_PRI))) 
     106               maxfd = f->fd; 
     107       } 
     108    tv.tv_sec = timeout / 1000; 
     109    tv.tv_usec = (timeout % 1000) * 1000; 
     110 
     111    ready = rb_thread_select (maxfd + 1, &rset, &wset, &xset, 
     112                             timeout == -1 ? NULL : &tv); 
     113    if (ready > 0) 
     114       for (f = fds; f < &fds[nfds]; ++f) 
     115       { 
     116           f->revents = 0; 
     117           if (f->fd >= 0) 
     118           { 
     119               if (FD_ISSET (f->fd, &rset)) 
     120                   f->revents |= G_IO_IN; 
     121               if (FD_ISSET (f->fd, &wset)) 
     122                   f->revents |= G_IO_OUT; 
     123               if (FD_ISSET (f->fd, &xset)) 
     124                   f->revents |= G_IO_PRI; 
     125           } 
     126       } 
     127 
     128    return ready; 
     129} 
     130 
    87131 
    88132static gboolean  
     
    15281572#ifdef SHOES_GTK 
    15291573  gtk_widget_show_all(app->os.window); 
    1530   g_idle_add(shoes_app_gtk_idle, app); 
     1574  g_main_set_poll_func(shoes_app_gtk_poll); 
    15311575  gtk_main(); 
    15321576#endif