Re: [PATCH 4/4] Only attempt to ftxwake in sempost if there might be a waiter.
[Thread Prev] | [Thread Next]
- Subject: Re: [PATCH 4/4] Only attempt to ftxwake in sempost if there might be a waiter.
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Sun, 19 Aug 2018 21:03:35 -0700
- To: myrddin-dev@xxxxxxxxxxxxxx
- Cc: iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Fixed a couple of bugs in the futex timeout patches, and pushed
the updated series. We now have rwlocks, thanks!
On Sat, 11 Aug 2018 19:15:59 -0700, iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> ---
> lib/thread/sem+futex.myr | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/lib/thread/sem+futex.myr b/lib/thread/sem+futex.myr
> index 434e195d..711dcf93 100644
> --- a/lib/thread/sem+futex.myr
> +++ b/lib/thread/sem+futex.myr
> @@ -5,13 +5,14 @@ use "futex"
>
> pkg thread =
> type sem = struct
> - _val : ftxtag
> + _val : ftxtag
> + _nwaiters : uint32
> ;;
>
> - const mksem : (v : uint32 -> sem)
> - const semwait : (s : sem# -> void)
> + const mksem : (v : uint32 -> sem)
> + const semwait : (s : sem# -> void)
> const semtrywait : (s : sem# -> bool)
> - const sempost : (s : sem# -> void)
> + const sempost : (s : sem# -> void)
> ;;
>
> const mksem = {v
> @@ -21,9 +22,11 @@ const mksem = {v
> const semwait = {s
> var v = 0
>
> + xadd(&s._nwaiters, 1)
> for ; ;
> while (v = s._val) > 0
> if xcas(&s._val, v, v - 1) == v
> + xadd(&s._nwaiters, -1)
> -> void
> ;;
> ;;
> @@ -47,6 +50,7 @@ const semtrywait = {s
> const sempost = {s
> std.assert((xadd(&s._val, 1) : uint32) != ~0x0, "error: semaphore overflowed\n")
>
> - /* Unconditionally wake one waiter */
> - ftxwake(&s._val)
> + if xget(&s._nwaiters) > 0
> + ftxwake(&s._val)
> + ;;
> }
> --
> 2.18.0
>
>
--
Ori Bernstein
| [PATCH 4/4] Only attempt to ftxwake in sempost if there might be a waiter. | iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> |
- Prev by Date: Re: Make-bootstrap failed
- Next by Date: Add rwlocks to libthread documentation.
- Previous by thread: [PATCH 4/4] Only attempt to ftxwake in sempost if there might be a waiter.
- Next by thread: What IRC network does Myrddin use?
- Index(es):