[libc-commits] [PATCH] D74653: [libc] Add simple implementations of mtx_lock and mtx_unlock.
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Fri Feb 14 15:43:44 PST 2020
sivachandra added a comment.
In D74653#1877328 <https://reviews.llvm.org/D74653#1877328>, @MaskRay wrote:
> A mutex implementation will need congestion counts. If only a shim is needed, a bi-state mutex is sufficient.
A tri-state mutex helps us avoid an unnecessary futext syscall.
> I think pthread_mutex_timedlock and pthread_mutex_unlock can be implemented first, then rebase mtx_lock and mtx_unlock on pthread. A libc eventually has to implement pthread to be usable on a POSIX platform. It can be a shim, with just the basic functionality. Even if you don't want to think of pthread initially, mtx_lock should be based on mtx_timedlock.
In LLVM libc, we want to take the opposite approach of implementing pthread as an extension over standard C thread library.
Agree mtx_lock could be a specialization of mtx_timedlock. As I said in the description, this patch is only a simple implementation of a plain mutex. It allows me to avoid worrying about he timespec API for now. Having a plain mutex available paves way for adding and testing other parts of the libc system.
> We can assume Linux>=2.6.22 and use FUTEX_PRIVATE_FLAG.
Agreed. I was not sure, but since you also bring it up, I can go ahead with that change. I will update in the next round.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74653/new/
https://reviews.llvm.org/D74653
More information about the libc-commits
mailing list