pthread unsafe macros

Nick Burrett nick at dsvr.net
Tue Mar 2 14:08:33 PST 2004


Alex Waugh wrote:
> In message <3FFAB7B8.6070105 at dsvr.net>
>           Nick Burrett <nick at dsvr.net> wrote:
> 
> 
>>
>>Alex,
>>
>>Could you explain why the function Bfree in strtod.c requires 
>>PTHREAD_UNSAFE to be declared ?  I would have assumed that the 
>>declaration is only needed at the toplevel function i.e. strtod rather 
>>than at all child functions.
>>
>>Hmm.  On closer inspection of _ints.s, are you doing this so that 
>>interrupts are disabled for as little time as possible ?
> 
> 
> It's just a trade off between context switch latency and
> efficiency/simplicity. In general if a function was thread safe but its
> children weren't then I would only put PTHREAD_UNSAFE in the child
> functions, which made things simpler when the child function was in a
> different file or could be called from more than one parent function.
> In strtod's case all the child functions are static thus it doesn't
> really matter, and I suspect the difference would be unnoticable.

Well, maybe.  Consider the difference here, the former with 
PTHREAD_UNSAFE and the latter without.  It probably is unnoticable though.

|Bfree|
         KEEP |Bfree|
         ; args = 0, pretend = 0, frame = 0, alloca = 0
         ; frame_needed = 1, uses_anonymous_args = 0
         ; nonlocal_label = 0, nonlocal_goto = 0, leaf = 0
         mov     __ip, __sp
         stmfd   __sp!, {__v1, __fp, __ip, __lr, __pc}
         sub     __fp, __ip, #4
         mov     __v1, __a1
         ldr     __a4, |L..13|
         ldr     __a3, [__a4, #0]
         cmp     __sp, __sl
         bllt    |__rt_stkovf_split_small|
         cmp     __a3, #0
         bne     |L..12|
|L..10|
         cmp     __v1, #0
         ldr     __a2, |L..13|+4
         ldrne   __a3, [__v1, #4]
         ldrne   __a4, [__a2, __a3, asl #2]
         strne   __a4, [__v1, #0]
         strne   __v1, [__a2, __a3, asl #2]
         ldmea   __fp, {__v1, __fp, __sp, __pc}
|L..12|
         bl      |__pthread_protect_unsafe|
         b       |L..10|



|Bfree|
         KEEP |Bfree|
         ; args = 0, pretend = 0, frame = 0, alloca = 0
         ; frame_needed = 0, uses_anonymous_args = 0
         ; nonlocal_label = 0, nonlocal_goto = 0, leaf = 1
         ; link register save eliminated.
         cmp     __a1, #0
         ldr     __a2, |L..11|
         ldrne   __a3, [__a1, #4]
         ldrne   __a4, [__a2, __a3, asl #2]
         ; __lr needed for prologue
         strne   __a4, [__a1, #0]
         strne   __a1, [__a2, __a3, asl #2]
         mov     __pc, __lr








More information about the gcc mailing list