some compile fixes, api changes, and i added the ability to create new chunks on...
[platform/upstream/gstreamer.git] / gst / cothreads / test-cothreads.c
index d734d88..b93126d 100644 (file)
@@ -1,5 +1,12 @@
 #include <cothreads.h>
 
+#define METHOD COTHREADS_CONFIG_GTHREAD_INITIALIZER
+
+#define NGTHREADS 2
+#define NCOTHREADS 5
+
+//#define USE_GTHREADS
+
 void co_thread (int argc, void **argv)
 {
   int pthreadnum =  *(int*)argv[0];
@@ -14,16 +21,16 @@ void co_thread (int argc, void **argv)
   cothread_switch (self, main);
 }
 
-void pthread (void* _pthreadnum) 
+void *pthread (void* _pthreadnum) 
 {
   int pthreadnum = *(int*) _pthreadnum;
   int cothreadnum = 0;
   cothread *main, *new;
-  char *argv[4];
+  void *argv[4];
   
   main = cothread_create (NULL, 0, NULL);
   
-  while (cothreadnum++ < 25) {
+  while (cothreadnum++ < NCOTHREADS) {
     printf ("%d: spawning a new cothread\n", pthreadnum);
     
     argv[0] = &pthreadnum;
@@ -34,32 +41,40 @@ void pthread (void* _pthreadnum)
     
     printf ("%d: switching to cothread %d...\n", pthreadnum, cothreadnum);
     cothread_switch (main, new);
-    
-    printf ("%d: back now, looping\n", pthreadnum);
   }
+  return NULL;
 }
 
-#define NTHREADS 2
-
 int main (int argc, char *argv[])
 {
-  GThread *thread[NTHREADS];
+  GThread *thread[NGTHREADS];
   int pthreadnum[4], i;
+  cothreads_config config = METHOD;
   
   g_thread_init(NULL);
-  cothreads_init(NULL);
+
+  cothreads_init(&config);
   
-  printf ("0: creating the gthreads\n");
+#ifdef USE_GTHREADS
+  cothread_create (NULL, 0, NULL); /* just to see where the stack is */
+#endif
   
-  for (i=0; i<NTHREADS; i++) {
+#ifdef USE_GTHREADS
+  printf ("0: creating the gthreads\n");
+  for (i=0; i<NGTHREADS; i++) {
     pthreadnum[i] = i+1;
     thread[i] = g_thread_create (pthread, &pthreadnum[i], TRUE, NULL);
   }
   
   printf ("0: joining the gthreads\n");
-  for (i=0; i<NTHREADS; i++) {
+  for (i=0; i<NGTHREADS; i++) {
     g_thread_join (thread[i]);
   }
+#else
+  printf ("0: calling the pthread function directly\n");
+  pthreadnum[0] = 1;
+  pthread (&pthreadnum[0]);
+#endif
   
   printf ("exiting\n");