a couple of fixen
authorAndy Wingo <wingo@pobox.com>
Sun, 27 Jan 2002 20:11:58 +0000 (20:11 +0000)
committerAndy Wingo <wingo@pobox.com>
Sun, 27 Jan 2002 20:11:58 +0000 (20:11 +0000)
Original commit message from CVS:
a couple of fixen

gst/cothreads/Makefile.am
gst/cothreads/linuxthreads-internals.h [deleted file]
gst/cothreads/linuxthreads.h [new file with mode: 0644]
gst/cothreads/test-pth-pthreads.c
gst/cothreads/test-pthreads.c

index b508b83..2f45005 100644 (file)
@@ -9,7 +9,7 @@ noinst_LTLIBRARIES = libpth-mctx.la
 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
diff --git a/gst/cothreads/linuxthreads-internals.h b/gst/cothreads/linuxthreads-internals.h
deleted file mode 100644 (file)
index ccf07d7..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#ifndef CURRENT_STACK_FRAME
-#define CURRENT_STACK_FRAME  ({ char __csf; &__csf; })
-#endif /* CURRENT_STACK_FRAME */
-
-#define STACK_SIZE 0x200000
diff --git a/gst/cothreads/linuxthreads.h b/gst/cothreads/linuxthreads.h
new file mode 100644 (file)
index 0000000..dcdd9e8
--- /dev/null
@@ -0,0 +1,33 @@
+#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;
+}
+
index 7121514..8941a03 100644 (file)
@@ -2,8 +2,7 @@
 #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;
index 98dec59..beb34a8 100644 (file)
@@ -1,24 +1,5 @@
-#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