[PATCH]: Thread safe stdio with cygwin
Thomas Pfaff
tpfaff@gmx.net
Fri Jan 16 14:32:00 GMT 2004
Jeff,
i think that you are right, the memset stuff can be avoided when
lock_init_recursive does this.
Attached is a patch that will
1. Remove the unnecessary memset stuff in __sfp and __sbprintf.
2. Add calls to __lock_init_recursive and __lock_close_recursive in
__sbprintf.
Thomas
2004-01-16 Thomas Pfaff <tpfaff@gmx.net>
* libc/stdio/findfp.c (__sfp): Remove unnecessary memset.
* libc/stdio/vfprintf.c (__sbprintf): Ditto.
Add calls to __lock_init_recursive and __lock_close_recursive
instead.
Jeff Johnston wrote:
> I should have added that there is no reason not to check in your patch
> which I have just done.
> I can add the initialization/closing in __sbprintf().
>
> -- Jeff J.
>
> Jeff Johnston wrote:
>
>> Thomas Pfaff wrote:
>>
>>> Jeff,
>>>
>>> memset makes only sure that _lock does not contain random data before
>>> __lock_init_recursive. __lock_init_recursive is called later when the
>>> file is really opened.
>>
>>
>>
>> I assumed you were worried about something accessing the file pointer
>> before fopen/freopen returned the file pointer so it would then make
>> sense just to initialize it earlier. Otherwise, the
>> __lock_init_recursive should initialize the lock without need for
>> pre-initialization.
>>
>>>
>>> __sbprintf is a special case because it generates a fake FILE pointer
>>> and its associated buf on the stack, therefore there is no need to
>>> lock it fo thread safety.
>>
>>
>>
>> There may be no need to lock, but the VFPRINTF code attempts a lock
>> and unlock anyway. It then makes sense to ensure that the lock is
>> validly initialized/closed for any platform's lock implementation.
>> -- Jeff J.
>>
>>> Thomas
>>>
>>> Jeff Johnston wrote:
>>>
>>>> Thomas,
>>>>
>>>> You should be using __lock_init_recursive to initialize the locks
>>>> rather than zeroing them out.
>>>> The code in __sbprintf should probably be closing the lock after the
>>>> call to VFPRINTF as well.
>>>>
>>>> -- Jeff J.
>>>>
>>>> Thomas Pfaff wrote:
>>>>
>>>>> This patch adds support for thread safe stdio for Cygwin.
>>>>>
>>>>> Cygwin uses dynamic mutexes for locking, therefore it is
>>>>> necessary to:
>>>>>
>>>>> 1. Initialize FILE pointers _lock properly.
>>>>> 2. Destroy the lock when it is no longer needed.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Thomas
>>>>>
>>>>> 2004-01-12 Thomas Pfaff <tpfaff@gmx.net>
>>>>>
>>>>> * libc/stdio/fclose.c: Include sys/lock.h.
>>>>> (fclose): Destroy lock when file is closed.
>>>>> * libc/stdio/findfp.c (__sfp): Initialize file pointers _lock
>>>>> member.
>>>>> * libc/stdio/freopen.c: Include sys/lock.h.
>>>>> (_freopen_r): Destroy lock when file is closed.
>>>>> * libc/stdio/vfprintf.c (__sbprintf): Initialize file pointers
>>>>> _lock member.
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: newlib.patch
Type: plain/text
Size: 1156 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20040116/5fd5af56/attachment.bin>
More information about the Newlib
mailing list