[bazelisk] Use a lock to avoid downloading Bazel lots of times
[bazelisk] Use a lock to avoid downloading Bazel lots of times

Before this change, running lots of instances of bazelisk.sh at once
meant downloading lots of copies of Bazel. Oops!

Now, if you run bazelisk.sh on its own on a clean checkout, the first
call to up_to_date will fail. We'll then take a lock, check again that
we need to download bazelisk (we do!) and then download it, finally
releasing the lock.

If we run bazelisk.sh in a clean checkout with 100 threads at once,
they will will all race to get the first flock. One of them will win
the race and follow the steps above. All of the others will sit and
wait for that first thread. Once it is done, they will run in order,
each checking that bazelisk is up to date (it is!) and then do
whatever job they are supposed to be doing.

Of course, the usual situation is that we've already got bazelisk
installed. In this case, the first call to up_to_date will pass and we
won't do any locking at all.

Signed-off-by: Rupert Swarbrick <290093e2ad2515ed2f14d749293c8cf8e02ca274@lowrisc.org>

lowRISC/opentitan,lowRISC/opentitan,lowRISC/opentitan,lowRISC/opentitan,lowRISC/opentitan,lowRISC/opentitan