From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] unify the use of FUTEX_PRIVATE
Date: Sat, 24 Jun 2017 18:16:30 -0400 [thread overview]
Message-ID: <20170624221630.GV1627@brightrain.aerifal.cx> (raw)
In-Reply-To: <20170624233104.63545cf2@inria.fr>
On Sat, Jun 24, 2017 at 11:31:04PM +0200, Jens Gustedt wrote:
> Hello,
>
> On Sat, 24 Jun 2017 19:51:27 +0200 Jens Gustedt <jens.gustedt@inria.fr>
> wrote:
>
> > Am 24. Juni 2017 18:40:26 MESZ schrieb Szabolcs Nagy <nsz@port70.net>:
> > >i think some of these are the same flag
> >
> > I don't think so.
> > For mutexes the sense is "shared" so just the opposite meaning, and
> > for rwlock, too, it seems. For sem it is just a screwed Boolean..
> >
> > I would merely tend to have different names for them, but that's a
> > bit invasive.
>
> We could do something like
>
> /* Shared and private flags for different control structures use the
> same bit to favor optimization. */
> /* for mutex, mutexattr and rwlock */
> #define PSHARED FUTEX_PRIVATE
> /* for sem */
> #define PRIVATE FUTEX_PRIVATE
>
> But then it could also be confusing that condattr uses bit 31 for the
> same purpose, and pthread_cond_t uses a pointer type. This could lead
> to
>
> /* Some shared and private flags for different control structures use
> the same bit to favor optimization. */
> #define MTX_SHARED FUTEX_PRIVATE
> #define MATR_SHARED FUTEX_PRIVATE
> #define RWL_SHARED FUTEX_PRIVATE
> #define RWATR_SHARED 1
> #define CND_SHARED (void*)-1
> #define CATR_SHARED (1<<31)
> /* Maybe replace by 1? */
> #define SEM_PRIVATE FUTEX_PRIVATE
>
> To set the bit, in some places we use bit shift, in some
> multiplication with 128 or 128U. To read the bit some do just masking
> and then use the result as a "Boolean", some use bit shift and then
> %2 to filter out the bit.
>
> Probably I still overlooked some usages, and the naming could still be
> improved.
>
> I could try to produce a patch in that sense, if there is consensus to
> go in that direction.
For now let's just use a macro for FUTEX_PRIVATE. My concern was
mainly about whether there are cases where it's assumed that the 128
or ^128 translates to FUTEX_PRIVATE by arithmetic ops. The __wait,
__timedwait, and __wake interfaces just treat their argument as a
boolean now, so I think the only places there might be remaining
assumptions of that sort is where a flag bit from the sync object is
passed directly into a futex __syscall -- places like the condvar
implementation. You've looked at all this code just now so you
probably have a better idea if there are any such places; if so I
think the assumption that the bits match up should just be replaced by
a conditional (e.g. flags & 128 ? 0 : FUTEX_PRIVATE or such).
Rich
next prev parent reply other threads:[~2017-06-24 22:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-24 8:18 Jens Gustedt
2017-06-24 16:40 ` Szabolcs Nagy
2017-06-24 17:51 ` Jens Gustedt
2017-06-24 21:31 ` Jens Gustedt
2017-06-24 22:16 ` Rich Felker [this message]
2017-06-25 7:29 ` Jens Gustedt
2017-07-04 21:14 ` Rich Felker
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=20170624221630.GV1627@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).