+void __tl_lock(void)
+{
+ if (!a_cas(&__thread_list_lock, 0, 1)) return;
+ do {
+ a_cas(&__thread_list_lock, 1, 2);
+ __futexwait(&__thread_list_lock, 2, 0);
+ } while (a_cas(&__thread_list_lock, 0, 2));
+}
+
+void __tl_unlock(void)
+{
+ if (a_swap(&__thread_list_lock, 0)==2)
+ __wake(&__thread_list_lock, 1, 0);
+}
+
+void __tl_sync(pthread_t td)
+{
+ a_barrier();
+ if (!__thread_list_lock) return;
+ a_cas(&__thread_list_lock, 1, 2);
+ __wait(&__thread_list_lock, 0, 2, 0);
+ __wake(&__thread_list_lock, 1, 0);
+}
+