it works, yo
authorAndy Wingo <wingo@pobox.com>
Mon, 28 Jan 2002 01:56:17 +0000 (01:56 +0000)
committerAndy Wingo <wingo@pobox.com>
Mon, 28 Jan 2002 01:56:17 +0000 (01:56 +0000)
Original commit message from CVS:
it works, yo

gst/cothreads/Makefile.am
gst/cothreads/cothreads.c
gst/cothreads/test-cothreads.c [new file with mode: 0644]

index 3014df1..0027398 100644 (file)
@@ -12,13 +12,15 @@ libgstcothreads_la_SOURCES = cothreads.c cothread-stack.c cothreads.h
 libgstcothreads_la_LIBADD = libpth-mctx.la $(GLIB_LIBS)
 libgstcothreads_la_CFLAGS = $(GLIB_CFLAGS)
 
-noinst_PROGRAMS = test-pth test-pth-pthreads test-pthreads test-pth-pthreads2
+noinst_PROGRAMS = test-pth test-pth-pthreads test-pthreads test-pth-pthreads2 test-cothreads
 noinst_HEADERS = linuxthreads.h cothreads-private.h cothreads.h
 
 test_pth_LDADD = libpth-mctx.la
 test_pth_pthreads_LDADD = libpth-mctx.la -lpthread
 test_pthreads_LDADD = -lpthread
 test_pth_pthreads2_LDADD = -lpthread libpth-mctx.la
+test_cothreads_CFLAGS = $(GLIB_CFLAGS)
+test_cothreads_LDADD = libgstcothreads.la
 
 BUILT_SOURCES = pth_p.h
 
index 3ea4e8d..5dc6cce 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "cothreads-private.h"
 
+#define HAVE_LINUXTHREADS
 
 #ifdef HAVE_LINUXTHREADS
 static cothread_attr cothread_attr_default = 
diff --git a/gst/cothreads/test-cothreads.c b/gst/cothreads/test-cothreads.c
new file mode 100644 (file)
index 0000000..009c8f2
--- /dev/null
@@ -0,0 +1,51 @@
+#include <cothreads.h>
+
+cothread *main_context;
+cothread *ctx;
+int threadnum = 0;
+
+void co_thread (void)
+{
+  printf ("1.%d: sleeping 1s in thread %d...\n", threadnum, threadnum);
+  sleep (1);
+  printf ("1.%d: returning to cothread 0\n", threadnum);
+  cothread_switch (ctx, main_context);
+}
+
+void pthread (void* unused) 
+{
+  char *skaddr;
+  
+  printf ("1: saving the main context\n");
+  main_context = cothread_init(NULL);
+  
+  while (threadnum < 25) {
+    printf ("1: spawning a new cothread\n");
+    ctx = cothread_create (co_thread);
+    
+    printf ("1: switching to cothread %d...\n", ++threadnum);
+    cothread_switch (main_context, ctx);
+  
+    printf ("1: back now, looping\n");
+  }
+}
+
+
+int main (int argc, char *argv[])
+{
+  GThread *thread;
+  
+  g_thread_init(NULL);
+  
+  printf ("0: creating the gthread\n");
+
+  thread = g_thread_create (pthread, NULL, TRUE, NULL);
+
+  printf ("joining the gthread\n");
+  g_thread_join (thread);
+
+  printf ("exiting\n");
+  
+  exit (0);
+}
+