Re: [Quickfix-developers] process_sleep has unitialized pointer
Brought to you by:
orenmnero
From: Joerg T. <Joe...@ma...> - 2004-06-22 08:33:12
|
Oren Miller wrote: > Actually, if we aren't making use of that parameter, we can just use > NULL. The only time that the structure is written out if a signal has > been delivered to the process, thus interrupting the call and allowing > us to continue with the remainder. I don't think this is a situation we > need to really concern ourselves with, and it certainly isn't handling > this case right now. I would suggest to do it right now. nanosleep() is the POSIX compliant way to wait and it is designed to make restarts after a signal easy: while( -1 == nanosleep( &time_to_sleep, &remainder ) ) { time_to_sleep = remainder; } > If the structure is set to NULL, the system call > will not try to write to the structure. So perhaps we should just change > the method to the following. > > void process_sleep( double s ) > { QF_STACK_PUSH(process_sleep) > > #ifdef _MSC_VER > Sleep( ( long ) s * 1000 ); > #else > timespec time; timespec time, remainder; > double intpart; > time.tv_nsec = (int)modf(s, &intpart); > time.tv_nsec *= 1000000000; Am I stupid? If I cast the fractional part returned from modf() to int, wouldn't it get 0? I would expect something like: time.tv_nsec = (long) ((modf(s, &intpart) * 1e6); > time.tv_sec = (int)intpart; time.tv_sec = (time_t) intpart; > nanosleep(&time, NULL); while ( -1 == nanosleep( &time, &remainder ) ) { time = remainder; } > #endif > > QF_STACK_POP > } -- Joerg Thoennes http://macd.com Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen |