diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 19:39:42 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 19:39:42 +0000 |
commit | fbe9feca244761a0c88436effdaaf7282b404cad (patch) | |
tree | 925b69cdb4b27522e0658d0b4f207392ba521bdf /base/message_pump_glib.h | |
parent | a4ffa8cf38d76e3ed86f55e5abe5bb9650fb6383 (diff) | |
download | chromium_src-fbe9feca244761a0c88436effdaaf7282b404cad.zip chromium_src-fbe9feca244761a0c88436effdaaf7282b404cad.tar.gz chromium_src-fbe9feca244761a0c88436effdaaf7282b404cad.tar.bz2 |
Rewrite the glib UI pump. Although the previous pump was correct in terms of test coverage, it was mis-handling the concept of idle work. This meant we were effectively polling the pump, causing full CPU usage. The new pump is greatly simplified, and follows the pattern used on Windows. All tests still pass.
Review URL: http://codereview.chromium.org/10833
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_glib.h')
-rw-r--r-- | base/message_pump_glib.h | 43 |
1 files changed, 5 insertions, 38 deletions
diff --git a/base/message_pump_glib.h b/base/message_pump_glib.h index 01cd4b6..26aec49 100644 --- a/base/message_pump_glib.h +++ b/base/message_pump_glib.h @@ -29,47 +29,14 @@ class MessagePumpForUI : public MessagePump { // We may make recursive calls to Run, so we save state that needs to be // separate between them in this structure type. struct RunState { - // This is the delegate argument passed to Run. Delegate* delegate; - // This tells us when to exit the event pump. - bool keep_running; - // This tells our work source when to dispatch DoWork and DoDelayedWork. - bool should_do_work; - // This tells our idle source when to dispatch DoIdleWork. - bool should_do_idle_work; - // Unlike the work source, which is shared by all calls to Run, each Run - // call gets its own idle source because we need to destroy it when we have - // no idle work, and we don't want to destroy someone else's source. - GSource* idle_source; - }; - struct WorkSource : GSource { - MessagePumpForUI* self; - }; + // Used to flag that the current Run() invocation should return ASAP. + bool should_quit; - // The source with these callbacks remain in the main loop forever. They - // will dispatch DoWork and DoDelayedWork, and calculate when and how long - // to block when GLib calls poll internally. - static GSourceFuncs WorkSourceFuncs; - static gboolean WorkSourcePrepare(GSource* source, gint* timeout_ms); - static gboolean WorkSourceCheck(GSource* source); - static gboolean WorkSourceDispatch(GSource* source, GSourceFunc unused_func, - gpointer unused_data); - - // The source that uses these callbacks is added as an idle source, which - // means GLib will call it when there is no other work to do. We continue - // doing work as long as DoIdleWork or the other work functions return true. - // Once no work remains, we remove the idle source so GLib will block instead - // of firing it. Then we re-add it when we wake up. - static GSourceFuncs IdleSourceFuncs; - static gboolean IdleSourcePrepare(GSource* source, gint* timeout_ms); - static gboolean IdleSourceCheck(GSource* source); - static gboolean IdleSourceDispatch(GSource* source, GSourceFunc unused_func, - gpointer unused_data); - - // This adds a GLib source to the main loop. - GSource* AddSource(GSourceFuncs* funcs, gint priority, - GPollFD* optional_poll_fd); + // Used to count how many Run() invocations are on the stack. + int run_depth; + }; RunState* state_; |