summaryrefslogtreecommitdiffstats
path: root/base/message_pump_glib.cc
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 21:37:31 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 21:37:31 +0000
commit157c61b07b3ce5e308db6230da9d93ff74a16ca3 (patch)
tree7a627dd3c11b684852e2a3ffe84bcfc079bf1316 /base/message_pump_glib.cc
parent105414ec43286c5ba9953eaf66f147a9a1a6afd5 (diff)
downloadchromium_src-157c61b07b3ce5e308db6230da9d93ff74a16ca3.zip
chromium_src-157c61b07b3ce5e308db6230da9d93ff74a16ca3.tar.gz
chromium_src-157c61b07b3ce5e308db6230da9d93ff74a16ca3.tar.bz2
POSIX: Add a macro for handling EINTR.
On POSIX systems, system calls can be interrupted by signals. In this case, they'll return EINTR, indicating that the system call needs to be restarted. (The situation is a little more complicated than this with SA_RESTART, but you can read man 7 signal if you like.) The short of it is that you need to catch EINTR and restart the call for these system calls: * read, readv, write, writev, ioctl * open() when dealing with a fifo * wait* * Anything socket based (send*, recv*, connect, accept etc) * flock and lock control with fcntl * mq_ functions which can block * futex * sem_wait (and timed wait) * pause, sigsuspend, sigtimedwait, sigwaitinfo * poll, epoll_wait, select and 'p' versions of the same * msgrcv, msgsnd, semop, semtimedop * close (although, on Linux, EINTR won't happen here) * any sleep functions (careful, you need to handle this are restart with different arguments) We've been a little sloppy with this until now. This patch adds a macro for dealing with this and corrects every case of these system calls (that I found). The macro is HANDLE_EINTR in base/eintr_wrapper.h. It's safe to include on Windows and is a no-op there. On POSIX, it uses GCC magic to return the correct type based on the expression and restarts the system call if it throws EINTR. And you can use it like: HANDLE_EINTR(close(fd)); Or: ssize_t bytes_read = HANDLE_EINTR(read(fd, buffer, len)); *BEWARE* that it will evaluate the argument multiple times, so this is not safe: HANDLE_EINTR(close(FireMissiles())); http://groups.google.com/group/chromium-dev/browse_thread/thread/41a35b2a457d73a0 http://codereview.chromium.org/100225 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15102 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_glib.cc')
-rw-r--r--base/message_pump_glib.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/base/message_pump_glib.cc b/base/message_pump_glib.cc
index c18bfd3..da40f26 100644
--- a/base/message_pump_glib.cc
+++ b/base/message_pump_glib.cc
@@ -7,6 +7,7 @@
#include <fcntl.h>
#include <math.h>
+#include "base/eintr_wrapper.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/platform_thread.h"
@@ -177,7 +178,7 @@ void MessagePumpForUI::HandleDispatch() {
// poll will tell us whether there was data, so this read shouldn't block.
if (wakeup_gpollfd_.revents & G_IO_IN) {
char msg;
- if (read(wakeup_pipe_read_, &msg, 1) != 1 || msg != '!') {
+ if (HANDLE_EINTR(read(wakeup_pipe_read_, &msg, 1)) != 1 || msg != '!') {
NOTREACHED() << "Error reading from the wakeup pipe.";
}
}
@@ -222,7 +223,7 @@ void MessagePumpForUI::ScheduleWork() {
// variables as we would then need locks all over. This ensures that if
// we are sleeping in a poll that we will wake up.
char msg = '!';
- if (write(wakeup_pipe_write_, &msg, 1) != 1) {
+ if (HANDLE_EINTR(write(wakeup_pipe_write_, &msg, 1)) != 1) {
NOTREACHED() << "Could not write to the UI message loop wakeup pipe!";
}
}