I am currently walking through existing and yet-to-be-implemented parts of synchronization utilities inside llvm-libc. I am doing this progressively and slowly, trying to cover ancient TODOs as much as I can ![]()
I am currently on my way towards a RWLock implementation. Here is the roadmap. As Pthread is indeed a large components, I am looking forward to more auditing and contributions to those interesting but not yet planned parts. Suggestions are recommended.
-
pthread_rwlock*(WIP)- expose futex for more internal usages
- support weak cmpxchg in
Atomicclasses - add internal utilities to manage absolute timeout (part1, part2, part3)
- separate
RawMutexfromMutex(planned, see below) - implement
RwLock(support timeout and read/writer preference adjustment) (planned)- figure out a good to expose internal structure to external interfaces (size&align consistency).
-
Performance Related Adjustments
- avoid cmpxchg on the fastpath of callonce
- add spin to
Mutex/RwLock(planned) - implement
gettid(not started but considerations are provided below) - implement
clock_gettimebased onvDSOinstead of plain syscall. (WIP, see part1, part2)
-
Other synchronization methods
- barrier
- condvar
- semaphore
- …
Separate RawMutex from Mutex
Current Mutex implementation has the following problems:
- It includes some extra fields (
is_shared,is_robust) reserved for pthread features. However, it makes it a less suitable candidate to be used internally (e.g. inRwLock). - It does not support timed APIs.
- It does not support shared memory.
To solve these problems, I will write another lock implementation more suitable for internal usage. Optionally, I may migrate current Mutex to use the internal Lock as no extra features other than plain mutex is implemented yet anyway.
Implement gettid
- In full build mode, internal
gettidshould directly get the date from TCB. This also requiresforkto update such data properly. - In overlay mode,
gettidshould usesyscallwith TLS cache, which also requires updates acrossfork.