Two more Gtk questions (fast frame rates and thread safety)




I'm considering migrating our research code from motif to gtk, and I
wasnted to figure out the best way to handle two things we're doing
now in motif with gtk.

First of all, we need to display small image streams at high frame
rates.  Currently we use a motif DrawingArea widget with a fixed 3/3/2
colormap where we know the mapping from indexes to colors.  We then
use XPutImage with a properly constructed image pixel index array to
display each image.  (This implementation is reasonably fast, but does
have the restriction (because of the 3/3/2 trick) that it only works
on some 8-bit visuals).  What would be the best way(s) to handle this
in gtk?

Second, we have many threads running in our code, and any of them
might call widget routines.  To handle the synchronization problems
(and to deal with the fact that motif's not thread safe and we can't
recompile it), we created one big mutex which is always locked by any
code that's inside *any* X routines.  To make this work we have to do
the following (in addition to manually locking and unlocking the mutex
for any X calls in our own code):

  1) make sure that all our X callbacks release the mutex as soon as
     they are called and reacquire it before they return.

  2) set up our main event loop so that it acquires the X lock before
     entering motif's event handler, and always releases when in a
     specially designed primary work proc which also sleeps to allow
     other threads to do their work.  Something like this):

       void
       run_ui() {
         xprotect.acquire();
         XtAppMainLoop(_app_context);
         xprotect.release();
         exit(_exit_status);
       }

       Boolean
       primary_work_proc(XtPointer /*client_data*/) {
         // Let other threads run (and use X)
         xprotect.release();
         usleep(sleep_time);
         xprotect.acquire();
         return(False);
       }

It looks like we might be able to structure our code in almost the
same way with gtk_idle_add, or restructure our code to drop the
work_proc, and use gtk_main_iteration instead.  Reasonable? 

Thanks, and sorry for the length.
-- 
Rob



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]