2003-01-12 15:59:00 +00:00
|
|
|
/* 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;
|
2004-03-13 15:27:01 +00:00
|
|
|
GCond *cond_t;
|
|
|
|
GCond *cond_p;
|
|
|
|
gint var;
|
2003-01-12 15:59:00 +00:00
|
|
|
} ThreadInfo;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void *
|
2003-01-12 15:59:00 +00:00
|
|
|
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_t);
|
|
|
|
|
|
|
|
g_print ("thread: wait ACK\n");
|
|
|
|
g_cond_wait (info->cond_p, info->mutex);
|
|
|
|
info->var = 1;
|
|
|
|
g_print ("thread: signal var change\n");
|
|
|
|
g_cond_signal (info->cond_t);
|
|
|
|
g_print ("thread: unlock\n");
|
|
|
|
g_mutex_unlock (info->mutex);
|
|
|
|
|
|
|
|
g_print ("thread: exit\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gint
|
|
|
|
main (gint argc, gchar * argv[])
|
2003-01-12 15:59:00 +00:00
|
|
|
{
|
|
|
|
ThreadInfo *info;
|
|
|
|
GThread *thread;
|
|
|
|
GError *error = NULL;
|
2003-01-27 21:38:51 +00:00
|
|
|
gint res = 0;
|
2003-01-12 15:59:00 +00:00
|
|
|
|
|
|
|
if (!g_thread_supported ())
|
|
|
|
g_thread_init (NULL);
|
|
|
|
|
|
|
|
info = g_new (ThreadInfo, 1);
|
|
|
|
info->mutex = g_mutex_new ();
|
|
|
|
info->cond_t = g_cond_new ();
|
|
|
|
info->cond_p = g_cond_new ();
|
|
|
|
info->var = 0;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-12 15:59:00 +00:00
|
|
|
g_print ("main: lock\n");
|
|
|
|
g_mutex_lock (info->mutex);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
thread = g_thread_create (thread_loop, info, TRUE, &error);
|
2003-01-12 15:59:00 +00:00
|
|
|
|
|
|
|
if (error != NULL) {
|
|
|
|
g_print ("Unable to start thread: %s\n", error->message);
|
|
|
|
g_error_free (error);
|
2003-01-27 21:38:51 +00:00
|
|
|
res = -1;
|
|
|
|
goto done;
|
2003-01-12 15:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_print ("main: wait spinup\n");
|
|
|
|
g_cond_wait (info->cond_t, info->mutex);
|
|
|
|
|
|
|
|
g_print ("main: signal ACK\n");
|
|
|
|
g_cond_signal (info->cond_p);
|
|
|
|
|
|
|
|
g_print ("main: waiting for thread to change var\n");
|
|
|
|
g_cond_wait (info->cond_t, info->mutex);
|
|
|
|
|
|
|
|
g_print ("main: var == %d\n", info->var);
|
2003-01-27 21:38:51 +00:00
|
|
|
if (info->var != 1) {
|
2003-01-12 15:59:00 +00:00
|
|
|
g_print ("main: !!error!! expected var == 1, got %d\n", info->var);
|
2003-01-27 21:38:51 +00:00
|
|
|
}
|
2003-01-12 15:59:00 +00:00
|
|
|
g_mutex_unlock (info->mutex);
|
|
|
|
|
|
|
|
g_print ("main: join\n");
|
|
|
|
g_thread_join (thread);
|
|
|
|
|
2003-01-27 21:38:51 +00:00
|
|
|
done:
|
2003-01-12 15:59:00 +00:00
|
|
|
g_mutex_free (info->mutex);
|
|
|
|
g_cond_free (info->cond_t);
|
|
|
|
g_cond_free (info->cond_p);
|
|
|
|
g_free (info);
|
|
|
|
|
2003-01-27 21:38:51 +00:00
|
|
|
return res;
|
2003-01-12 15:59:00 +00:00
|
|
|
}
|