Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jan 28, 2022

The functions __lock and __unlock are never called directly within
musl but always via the LOCK() and UNLOCK() macros.

They are implemented internally using an atomic integer along with the
__wake and __futexwait internal function which emscripten already
supports.

Not to be confused with __lockfile/__unlockfile which are used to
implement the FLOCK()/FUNLOCK() macros (which we already support and
have enabled).

In theory this could help remove data races and crashed within musl.
In practice many of the uses of LOCK/UNLOCK are in places not compiled
into emscripten. However I noticed at least these 3 that we do depend
on and they do look useful/valid:

  • stdio/ofl.c: Open file lock used in fclose.c/fflush.c/__stdio_exit.c (We
    don't use __stdio_exit.c under emscripten)
  • random/srandom: Used as a mutex for the prng generator
  • dirent/rewinddir/seekdir: Used a mutex on an open directory handle

@sbc100 sbc100 requested review from kleisauke and kripken January 28, 2022 00:51
The functions `__lock` and `__unlock` are never called directly within
musl but always via the `LOCK()` and `UNLOCK()` macros.

They are implemented internally using an atomic integer along with the
`__wake` and `__futexwait` internal function which emscripten already
supports.

Not to be confused with `__lockfile/__unlockfile` which are used to
implement the `FLOCK()/FUNLOCK()` macros (which we already support and
have enabled).

In theory this could help remove data races and crashed within musl.
In practice many of the uses of `LOCK/UNLOCK` are in places not compiled
into emscripten.  However I noticed at least these 3 that we do depend
on and they do look useful/valid:

- stdio/ofl.c: Open file lock used in fclose.c/fflush.c/__stdio_exit.c (We
  don't use __stdio_exit.c under emscripten)
- random/srandom: Used as a mutex for the prng generator
- dirent/rewinddir/seekdir: Used a mutex on an open directory handle
@sbc100 sbc100 requested a review from kripken January 28, 2022 01:39
@kleisauke
Copy link
Collaborator

CI appears to have some issues. GitHub marks some test suites as pending, but when I look at the details, the tests have already been completed successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants