Joakim Tjernlund a écrit :
>> Index: libc/sysdeps/linux/common/poll.c
>> ===================================================================
>> --- libc/sysdeps/linux/common/poll.c (revision 20316)
>> +++ libc/sysdeps/linux/common/poll.c (working copy)
>> @@ -37,8 +37,14 @@
>>      if (timeout > 0) {
>>              tval.tv_sec = timeout / 1000;
>>              tval.tv_nsec = (timeout % 1000) * 1000000;
>> -            ts = &tval;
>> +    } else if (timeout == 0) {
>> +            tval.tv_sec = 0;
>> +            tval.tv_nsec = 0;
>> +    } else {
>> +            tval.tv_sec = -1;
>> +            tval.tv_nsec = 0;
>>      }
>> +    ts = &tval;
>>      return ppoll(fds, nfds, ts, NULL);
>>  }
> 
> can't you just do:
> if (timeout >= 0) {
>       tval.tv_sec = timeout / 1000;
>       tval.tv_nsec = (timeout % 1000) * 1000000;
>       ts = &tval;
> or is the timeout=0 case performance sensitive?

Yes it should work. But as the test for positive value already exists we 
can use it to bypass a division, a modulo, and a multiplication of a 
zero value. On a Blackfin processor for example a division is really slow.

> 
> And why not pass NULL as it was before?
> } else {
>       tval.tv_sec = -1; /* ~0 instead ? */
>       tval.tv_nsec = 0;
> }
> ts = &tval;

Because it's not obviouse that the kernel will do the same for a null 
pointer or a negative value. I don't have the POSIX.1-2001 to verify 
what is exactly specified in case of a null pointer.

The constant ~0 should work, but I find far more readable the -1.

_______________________________________________
uClibc mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/uclibc

Reply via email to