Added test app
authorWim Taymans <wim.taymans@gmail.com>
Sun, 12 Jan 2003 15:38:29 +0000 (15:38 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Sun, 12 Jan 2003 15:38:29 +0000 (15:38 +0000)
Original commit message from CVS:
Added test app

tests/threadstate/Makefile.am
tests/threadstate/test1.c [new file with mode: 0644]

index 37226cd..8b81eda 100644 (file)
@@ -1,4 +1,4 @@
-noinst_PROGRAMS = threadstate1 threadstate2 threadstate3 threadstate4 threadstate5
+noinst_PROGRAMS = threadstate1 threadstate2 threadstate3 threadstate4 threadstate5 test1
 
 LDADD = $(GST_LIBS)
 AM_CFLAGS = $(GST_CFLAGS)
diff --git a/tests/threadstate/test1.c b/tests/threadstate/test1.c
new file mode 100644 (file)
index 0000000..ce99419
--- /dev/null
@@ -0,0 +1,95 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+
+typedef struct
+{
+  GMutex *mutex;
+  GCond  *cond;
+} ThreadInfo;
+
+static void*
+thread_loop (void *arg)
+{
+  ThreadInfo *info = (ThreadInfo *) arg;
+
+  g_print ("thread: entering %p\n", info);
+
+  g_print ("thread: lock\n");
+  g_mutex_lock (info->mutex);
+  g_print ("thread: signal spinup\n");
+  g_cond_signal (info->cond);
+
+  g_print ("thread: wait ACK\n");
+  g_cond_wait (info->cond, info->mutex);
+  g_print ("thread: signal\n");
+  g_cond_signal (info->cond);
+  g_print ("thread: unlock\n");
+  g_mutex_unlock (info->mutex);
+
+  g_print ("thread: exit\n");
+  return NULL;
+}
+
+gint 
+main (gint argc, gchar *argv[]) 
+{
+  ThreadInfo *info;
+  GThread *thread;
+  GError *error = NULL;
+
+  if (!g_thread_supported ())
+    g_thread_init (NULL);
+
+
+  info = g_new (ThreadInfo, 1);
+  info->mutex = g_mutex_new ();
+  info->cond = g_cond_new ();
+  
+  g_print ("main: lock\n");
+  g_mutex_lock (info->mutex);
+
+  thread = g_thread_create (thread_loop,
+                           info, 
+                           TRUE, 
+                           &error);
+
+  if (error != NULL) {
+    g_print ("Unable to start thread: %s\n", error->message);
+    g_error_free (error);
+    return -1;
+  }
+
+  g_print ("main: wait spinup\n");
+  g_cond_wait (info->cond, info->mutex);
+
+  g_print ("main: signal ACK\n");
+  g_cond_signal (info->cond);
+  g_print ("main: wait\n");
+  g_cond_wait (info->cond, info->mutex);
+  g_print ("main: unlock\n");
+  g_mutex_unlock (info->mutex);
+
+  g_print ("main: join\n");
+  g_thread_join (thread);
+
+  return 0;
+}
+