libpth_mctx_la_SOURCES = pth_mctx.c pth_p.h pth_vers.c pth.h pth_acdef.h pth_acmac.h
noinst_PROGRAMS = test-pth test-pth-pthreads test-pthreads test-pth-pthreads2
-noinst_HEADERS = linuxthreads-internals.h
+noinst_HEADERS = linuxthreads.h
test_pth_LDADD = libpth-mctx.la
test_pth_pthreads_LDADD = libpth-mctx.la -lpthread
+++ /dev/null
-#ifndef CURRENT_STACK_FRAME
-#define CURRENT_STACK_FRAME ({ char __csf; &__csf; })
-#endif /* CURRENT_STACK_FRAME */
-
-#define STACK_SIZE 0x200000
--- /dev/null
+#ifndef _GNU_SOURCE /* pull in the nonposix static mutex initializers */
+#define _GNU_SOURCE
+#define __USE_GNU /* just to be sure */
+#endif
+
+#include <pthread.h>
+
+#ifndef CURRENT_STACK_FRAME
+#define CURRENT_STACK_FRAME ({ char __csf; &__csf; })
+#endif /* CURRENT_STACK_FRAME */
+
+#define STACK_SIZE 0x200000
+
+/* this function is only really necessary to get the main thread's
+ * pthread_descr, as the other threads store the pthread_descr (actually the
+ * first member of struct _pthread_descr_struct, which points to itself for the
+ * default non-indirected case) at the top of the stack. */
+static inline _pthread_descr __linuxthreads_self()
+{
+ pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+ _pthread_descr self;
+
+ pthread_mutex_lock (&mutex);
+ self = mutex.__m_owner;
+ pthread_mutex_unlock (&mutex);
+
+ printf ("pthread_self: %d\n", pthread_self());
+ printf ("descr: %p\n", self);
+ printf ("*descr: %p\n", *(int*)self);
+
+ return self;
+}
+
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
-#include <pthread.h>
-#include "linuxthreads-internals.h"
+#include "linuxthreads.h"
pth_mctx_t main_context;
int threadnum = 0;
-#define __USE_GNU /* non-posix functions */
-#include <pthread.h>
-#undef __USE_GNU
#include <stdio.h>
-#include "linuxthreads-internals.h"
-
-// the thread_self algorithm:
-/*
- char * sp = CURRENT_STACK_FRAME;
- int self = (int) pthread_self();
-
- if (self % PTHREAD_THREADS_MAX < 2)
- * we only support the main thread, not the manager. *
- return &__pthread_initial_thread;
-
-#ifdef _STACK_GROWS_DOWN
- return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1;
-#else
- return (pthread_descr)((unsigned long)sp &~ (STACK_SIZE-1));
-#endif
-*/
+#include "linuxthreads.h"
/* this function is only really necessary to get the main thread's
* pthread_descr, as the other threads store the pthread_descr (actually the