25 |
|
|
26 |
#include <pt-internal.h> |
#include <pt-internal.h> |
27 |
|
|
28 |
#include <bits/atomic.h> |
#include <atomic.h> |
29 |
|
|
30 |
/* This braindamage is necessary because the standard says that some |
/* This braindamage is necessary because the standard says that some |
31 |
of the threads functions "shall fail" if "No thread could be found |
of the threads functions "shall fail" if "No thread could be found |
46 |
|
|
47 |
|
|
48 |
/* List of thread structures corresponding to free thread IDs. */ |
/* List of thread structures corresponding to free thread IDs. */ |
49 |
__atomicptr_t __pthread_free_threads; |
uatomicptr_t __pthread_free_threads; |
50 |
|
|
51 |
static inline error_t |
static inline error_t |
52 |
initialize_pthread (struct __pthread *new, int recycling) |
initialize_pthread (struct __pthread *new, int recycling) |
97 |
/* Try to re-use a thread structure before creating a new one. */ |
/* Try to re-use a thread structure before creating a new one. */ |
98 |
while ((new = (struct __pthread *)__pthread_free_threads)) |
while ((new = (struct __pthread *)__pthread_free_threads)) |
99 |
{ |
{ |
100 |
if (__atomicptr_compare_and_swap (&__pthread_free_threads, |
if (atomic_compare_and_exchange_val_acq (&__pthread_free_threads, |
101 |
new, new->next)) |
new, new->next)) |
102 |
{ |
{ |
103 |
/* Yes, we managed to get one. The thread number in the |
/* Yes, we managed to get one. The thread number in the |
104 |
thread structure still refers to the correct slot. */ |
thread structure still refers to the correct slot. */ |
110 |
while (1) |
while (1) |
111 |
{ |
{ |
112 |
new->next = (struct __pthread *)__pthread_free_threads; |
new->next = (struct __pthread *)__pthread_free_threads; |
113 |
if (__atomicptr_compare_and_swap (&__pthread_free_threads, |
if (atomic_compare_and_exchange_val_acq |
114 |
new->next, new)) |
(&__pthread_free_threads, new->next, new)) |
115 |
break; |
break; |
116 |
} |
} |
117 |
|
|