[chromium-dev] Re: POSIX: EINTR correctness

2009-05-04 Thread Darin Fisher
On Mon, May 4, 2009 at 11:06 AM, Adam Langley wrote: > 2009/5/4 Darin Fisher : > > Maybe we can reuse MakeTuple and DispatchToFunction from base/tuple.h ? > > -Darin > > I started looking at this, but it ends up being a fair amount of > template magic to deal with a situation which hasn't ever ac

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-04 Thread Adam Langley
2009/5/4 Darin Fisher : > Maybe we can reuse MakeTuple and DispatchToFunction from base/tuple.h ? > -Darin I started looking at this, but it ends up being a fair amount of template magic to deal with a situation which hasn't ever actually happened in the code (even without the macro, where it wou

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-04 Thread Darin Fisher
On Fri, May 1, 2009 at 1:46 PM, Albert J. Wong (王重傑) wrote: > On Fri, May 1, 2009 at 1:31 PM, Jeremy Orlow wrote: > >> On Fri, May 1, 2009 at 1:27 PM, Adam Langley wrote: >> >>> On Fri, May 1, 2009 at 12:53 PM, Jeremy Orlow wrote: >>> > I'm still kind of new here, so forgive me if this is a sil

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread 王重傑
On Fri, May 1, 2009 at 1:31 PM, Jeremy Orlow wrote: > On Fri, May 1, 2009 at 1:27 PM, Adam Langley wrote: > >> On Fri, May 1, 2009 at 12:53 PM, Jeremy Orlow wrote: >> > I'm still kind of new here, so forgive me if this is a silly question, >> but >> > why do this with a define and not an templa

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Marc-Antoine Ruel
What about NewRunnableFunction() in task.h? Slightly overkill because of heap usage and parameter copy but it is quite strict. It also requires writing the call in a different and less obvious way, which may counter the benefit. M-A On Fri, May 1, 2009 at 4:39 PM, Adam Langley wrote: > > On Fr

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Mike Belshe
On Fri, May 1, 2009 at 1:30 PM, Adam Langley wrote: > On Fri, May 1, 2009 at 1:23 PM, Mike Belshe wrote: > > It's been a while since I dealt with unix signals; but in the work I did, > > the common trick was to disable signals on all threads except one. Then, > > you only have to deal with hand

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Adam Langley
On Fri, May 1, 2009 at 1:32 PM, Adam Barth wrote: > There's also a problem if you write something like: > > HANDLE_EINTR(close(PromptUserForFileDescriptor())); > > Macros suck. > > What about something like base::close that's inline and knows how to loop? Yea, the macro will trigger multiple eva

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Adam Barth
There's also a problem if you write something like: HANDLE_EINTR(close(PromptUserForFileDescriptor())); Macros suck. What about something like base::close that's inline and knows how to loop? Adam On Fri, May 1, 2009 at 1:27 PM, Adam Langley wrote: > On Fri, May 1, 2009 at 1:13 PM, Elliot G

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Jeremy Orlow
On Fri, May 1, 2009 at 1:27 PM, Adam Langley wrote: > On Fri, May 1, 2009 at 12:53 PM, Jeremy Orlow wrote: > > I'm still kind of new here, so forgive me if this is a silly question, > but > > why do this with a define and not an template function? > > One could imagine a template function: > > t

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Adam Langley
On Fri, May 1, 2009 at 1:23 PM, Mike Belshe wrote: > It's been a while since I dealt with unix signals; but in the work I did, > the common trick was to disable signals on all threads except one.  Then, > you only have to deal with handling signals there.  Otherwise, you've pretty > much always g

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Adam Langley
On Fri, May 1, 2009 at 1:13 PM, Elliot Glaysher (Chromium) wrote: > Yes. Regretfully, C doesn't have hygienic macros. It probably would be > a good idea to change "ret" to a name less likely to conflict... Yep, good point. It's now __eintr_result__. Cheers AGL --~--~-~--~~---

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Adam Langley
On Fri, May 1, 2009 at 12:53 PM, Jeremy Orlow wrote: > I'm still kind of new here, so forgive me if this is a silly question, but > why do this with a define and not an template function? One could imagine a template function: template T handle_eintr(T &a) { .. } But when using it as: hand

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Mike Belshe
It's been a while since I dealt with unix signals; but in the work I did, the common trick was to disable signals on all threads except one. Then, you only have to deal with handling signals there. Otherwise, you've pretty much always got trouble because you never know which threads will service

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Elliot Glaysher (Chromium)
On Fri, May 1, 2009 at 1:07 PM, Adam Barth wrote: > Wow, that's pretty deep magic. > >> And you can use it like: >>  HANDLE_EINTR(close(fd)); > > Isn't it disaster if you say: > > HANDLE_EINTR(close(ret)); Yes. Regretfully, C doesn't have hygienic macros. It probably would be a good idea to chan

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Adam Barth
On Fri, May 1, 2009 at 12:35 PM, Adam Langley wrote: > On POSIX, it uses GCC magic to return the correct type based on the expression > and restarts the system call if it throws EINTR. Here it is: > > #define HANDLE_EINTR(x) ({ \ >  typeof(x) ret; \ >  do { \ >    ret = x; \ >  } while (ret == -1

[chromium-dev] Re: POSIX: EINTR correctness

2009-05-01 Thread Jeremy Orlow
I'm still kind of new here, so forgive me if this is a silly question, but why do this with a define and not an template function? On Fri, May 1, 2009 at 12:35 PM, Adam Langley wrote: > > On POSIX systems, system calls can be interrupted by signals. In this case, > they'll return EINTR, indicati