mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
Make _Thread_local work across platforms
We now rewrite the binary image at runtime on Windows and XNU to change mov %fs:0,%reg instructions to use %gs instead. There's also simpler threading API introduced by this change and it's called _spawn() and _join(), which has replaced most clone() usage.
This commit is contained in:
parent
e4d6e263d4
commit
5f4f6b0e69
51 changed files with 808 additions and 1043 deletions
|
@ -16,10 +16,10 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/atomic.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/futex.internal.h"
|
||||
#include "libc/intrin/wait0.internal.h"
|
||||
#include "libc/linux/futex.h"
|
||||
|
@ -31,13 +31,13 @@
|
|||
* by the clone() system call when a thread terminates. The purpose of
|
||||
* this operation is to know when it's safe to munmap() a thread stack.
|
||||
*/
|
||||
void _wait0(const int *ptid) {
|
||||
void _wait0(const int *ctid) {
|
||||
int x;
|
||||
for (;;) {
|
||||
if (!(x = atomic_load_explicit(ptid, memory_order_acquire))) {
|
||||
if (!(x = atomic_load_explicit(ctid, memory_order_acquire))) {
|
||||
break;
|
||||
} else if (IsLinux() /* || IsOpenbsd() */) {
|
||||
_futex_wait(ptid, x, &(struct timespec){2});
|
||||
_futex_wait(ctid, x, &(struct timespec){2});
|
||||
} else {
|
||||
sched_yield();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue