public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Thomas Preudhomme <thomas.preudhomme@foss.arm.com>
To: newlib@sourceware.org
Subject: Re: [PATCH 2/3, newlib] Only define static locks in multithreaded mode
Date: Thu, 02 Feb 2017 14:32:00 -0000	[thread overview]
Message-ID: <bbadd5ae-77bf-19f8-3efa-da64421058f1@foss.arm.com> (raw)
In-Reply-To: <1485938923.1269.3.camel@op.pl>

On 01/02/17 08:48, Freddie Chopin wrote:
> On Tue, 2017-01-31 at 17:10 +0000, Thomas Preudhomme wrote:
>> It also makes sure locking macros in lock.h are noop in single thread
>> mode.
>
> Doesn't it make all the guards in the code superfluous? If the lock
> initialization macros are defined to be ";" and lock functions are
> defined to be "(void)0", then the guards in the code actually guard
> nothing, as things like:
>
>  #if !defined(__SINGLE_THREAD__) && defined(HAVE_DD_LOCK)
>  __LOCK_INIT(static, __dd_hash_mutex);
>  #endif
>
>  #ifndef __SINGLE_THREAD__
>         __lock_acquire(__dd_hash_mutex);
>  #endif
>
> will then be equivalent to:
>
>  #if !defined(__SINGLE_THREAD__) && defined(HAVE_DD_LOCK)
>  ;
>  #endif
>
>  #ifndef __SINGLE_THREAD__
>         (void)0;
>  #endif

Yes it does and I started to remove them but noticed that removing the guard 
made code more inconsistent. The example you give is a nice one because then we 
would still have a condition with HAVE_DD_LOCK which might induce people to 
think that's the only case where this line does nothing.

In some other case __SINGLE_THREAD__ guards more than just the lock. For 
instance in newlib/libc/stdio/findfp.c __SINGLE_THREAD__ is used to guard 
whether some function are defined. This would need to be kept so the only change 
that could be done is take the lock out of the __SINGLE_THREAD__ guarded block 
which would look weird again.

I then wondered whether making the code noop in lock.h was the right approach 
but decided that provided more safety that the code would not be compiled in in 
case of missing guard (as you discovered for some of the locks). It also goes 
with what is currently being done when targeting bare-metal since the lock 
routines themselves are noop in that case. Only the declarations are not. The 
one thing that could be done is to make the declaration noop in both cases, thus 
reducing the complexity.

Any thoughts on that?

Best regards,

Thomas

  reply	other threads:[~2017-02-02 14:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-31 17:10 Thomas Preudhomme
2017-01-31 17:21 ` Thomas Preudhomme
2017-02-10 11:12   ` Thomas Preudhomme
2017-02-13 22:16     ` Jeff Johnston
2017-02-01  8:49 ` Freddie Chopin
2017-02-02 14:32   ` Thomas Preudhomme [this message]
2017-02-02 15:46     ` Craig Howland
2017-02-03  9:01       ` Thomas Preudhomme

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bbadd5ae-77bf-19f8-3efa-da64421058f1@foss.arm.com \
    --to=thomas.preudhomme@foss.arm.com \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).