#include "gstbufferstraw.h"
-static GCond *cond = NULL;
-static GMutex *lock = NULL;
+static GCond cond;
+static GMutex lock;
static GstBuffer *buf = NULL;
static gulong id;
{
GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
- g_mutex_lock (lock);
+ g_mutex_lock (&lock);
while (buf != NULL)
- g_cond_wait (cond, lock);
+ g_cond_wait (&cond, &lock);
/* increase the refcount because we store it globally for others to use */
buf = gst_buffer_ref (buffer);
- g_cond_signal (cond);
+ g_cond_signal (&cond);
- g_mutex_unlock (lock);
+ g_mutex_unlock (&lock);
return GST_PAD_PROBE_OK;
}
id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
buffer_probe, NULL, NULL);
- cond = g_cond_new ();
- lock = g_mutex_new ();
-
ret = gst_element_set_state (bin, GST_STATE_PLAYING);
fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not start test pipeline");
if (ret == GST_STATE_CHANGE_ASYNC) {
{
GstBuffer *ret;
- g_mutex_lock (lock);
+ g_mutex_lock (&lock);
while (buf == NULL)
- g_cond_wait (cond, lock);
+ g_cond_wait (&cond, &lock);
ret = buf;
buf = NULL;
- g_cond_signal (cond);
+ g_cond_signal (&cond);
- g_mutex_unlock (lock);
+ g_mutex_unlock (&lock);
return ret;
}
{
GstStateChangeReturn ret;
- g_mutex_lock (lock);
+ g_mutex_lock (&lock);
if (buf)
gst_buffer_unref (buf);
buf = NULL;
gst_pad_remove_probe (pad, (guint) id);
id = 0;
- g_cond_signal (cond);
- g_mutex_unlock (lock);
+ g_cond_signal (&cond);
+ g_mutex_unlock (&lock);
ret = gst_element_set_state (bin, GST_STATE_NULL);
fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not stop test pipeline");
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not stop test pipeline");
}
- g_mutex_lock (lock);
+ g_mutex_lock (&lock);
if (buf)
gst_buffer_unref (buf);
buf = NULL;
- g_mutex_unlock (lock);
-
- g_mutex_free (lock);
- g_cond_free (cond);
-
- lock = NULL;
- cond = NULL;
+ g_mutex_unlock (&lock);
}
gboolean _gst_check_threads_running = FALSE;
GList *thread_list = NULL;
-GMutex *mutex;
-GCond *start_cond; /* used to notify main thread of thread startups */
-GCond *sync_cond; /* used to synchronize all threads and main thread */
+GMutex mutex;
+GCond start_cond; /* used to notify main thread of thread startups */
+GCond sync_cond; /* used to synchronize all threads and main thread */
GList *buffers = NULL;
-GMutex *check_mutex = NULL;
-GCond *check_cond = NULL;
+GMutex check_mutex;
+GCond check_cond;
/* FIXME 0.11: shouldn't _gst_check_debug be static? Not used anywhere */
gboolean _gst_check_debug = FALSE;
gst_check_log_critical_func, NULL);
print_plugins ();
-
- check_cond = g_cond_new ();
- check_mutex = g_mutex_new ();
}
/* message checking */
GST_DEBUG_OBJECT (pad, "chain_func: received buffer %p", buffer);
buffers = g_list_append (buffers, buffer);
- g_mutex_lock (check_mutex);
- g_cond_signal (check_cond);
- g_mutex_unlock (check_mutex);
+ g_mutex_lock (&check_mutex);
+ g_cond_signal (&check_cond);
+ g_mutex_unlock (&check_mutex);
return GST_FLOW_OK;
}
/* global variables used in test methods */
extern GList * buffers;
-extern GMutex *check_mutex;
-extern GCond *check_cond;
+extern GMutex check_mutex;
+extern GCond check_cond;
typedef struct
{
* thread test macros and variables
*/
extern GList *thread_list;
-extern GMutex *mutex;
-extern GCond *start_cond; /* used to notify main thread of thread startups */
-extern GCond *sync_cond; /* used to synchronize all threads and main thread */
+extern GMutex mutex;
+extern GCond start_cond; /* used to notify main thread of thread startups */
+extern GCond sync_cond; /* used to synchronize all threads and main thread */
#define MAIN_START_THREADS(count, function, data) \
MAIN_INIT(); \
#define MAIN_INIT() \
G_STMT_START { \
_gst_check_threads_running = TRUE; \
- \
- if (mutex == NULL) { \
- mutex = g_mutex_new (); \
- start_cond = g_cond_new (); \
- sync_cond = g_cond_new (); \
- } \
} G_STMT_END;
#define MAIN_START_THREAD_FUNCTIONS(count, function, data) \
G_STMT_START { \
GThread *thread = NULL; \
GST_DEBUG ("MAIN: creating thread %d", i); \
- g_mutex_lock (mutex); \
- thread = g_thread_create ((GThreadFunc) function, data, \
- TRUE, NULL); \
+ g_mutex_lock (&mutex); \
+ thread = g_thread_try_new ("gst-check", \
+ (GThreadFunc) function, data, NULL); \
/* wait for thread to signal us that it's ready */ \
GST_DEBUG ("MAIN: waiting for thread %d", i); \
- g_cond_wait (start_cond, mutex); \
- g_mutex_unlock (mutex); \
+ g_cond_wait (&start_cond, &mutex); \
+ g_mutex_unlock (&mutex); \
\
thread_list = g_list_append (thread_list, thread); \
} G_STMT_END;
#define MAIN_SYNCHRONIZE() \
G_STMT_START { \
GST_DEBUG ("MAIN: synchronizing"); \
- g_cond_broadcast (sync_cond); \
+ g_cond_broadcast (&sync_cond); \
GST_DEBUG ("MAIN: synchronized"); \
} G_STMT_END;
G_STMT_START { \
/* signal main thread that we started */ \
GST_DEBUG ("THREAD %p: started", g_thread_self ()); \
- g_mutex_lock (mutex); \
- g_cond_signal (start_cond); \
+ g_mutex_lock (&mutex); \
+ g_cond_signal (&start_cond); \
} G_STMT_END;
#define THREAD_SYNCHRONIZE() \
G_STMT_START { \
/* synchronize everyone */ \
GST_DEBUG ("THREAD %p: syncing", g_thread_self ()); \
- g_cond_wait (sync_cond, mutex); \
+ g_cond_wait (&sync_cond, &mutex); \
GST_DEBUG ("THREAD %p: synced", g_thread_self ()); \
- g_mutex_unlock (mutex); \
+ g_mutex_unlock (&mutex); \
} G_STMT_END;
#define THREAD_SWITCH() \
fail_unless (overrun_count == 1);
/* lock the check_mutex to block the first buffer pushed to mysinkpad */
- g_mutex_lock (check_mutex);
+ g_mutex_lock (&check_mutex);
/* now let the queue push all buffers */
while (g_list_length (buffers) < 3) {
- g_cond_wait (check_cond, check_mutex);
+ g_cond_wait (&check_cond, &check_mutex);
}
- g_mutex_unlock (check_mutex);
+ g_mutex_unlock (&check_mutex);
fail_unless (overrun_count == 1);
/* make sure we get the underrun signal before we check underrun_count */
BufferAllocHarness *h = data;
/* Signal that we are about to call release_request_pad(). */
- g_mutex_lock (check_mutex);
+ g_mutex_lock (&check_mutex);
h->app_thread_prepped = TRUE;
- g_cond_signal (check_cond);
- g_mutex_unlock (check_mutex);
+ g_cond_signal (&check_cond);
+ g_mutex_unlock (&check_mutex);
/* Simulate that the app releases the pad while the streaming thread is in
* buffer_alloc below. */
gst_element_release_request_pad (h->tee, h->tee_srcpad);
/* Signal the bufferalloc function below if it's still waiting. */
- g_mutex_lock (check_mutex);
+ g_mutex_lock (&check_mutex);
h->bufferalloc_blocked = FALSE;
- g_cond_signal (check_cond);
- g_mutex_unlock (check_mutex);
+ g_cond_signal (&check_cond);
+ g_mutex_unlock (&check_mutex);
return NULL;
}
fail_if (h->app_thread == NULL);
/* Wait for the app thread to get ready to call release_request_pad(). */
- g_mutex_lock (check_mutex);
+ g_mutex_lock (&check_mutex);
while (!h->app_thread_prepped)
- g_cond_wait (check_cond, check_mutex);
- g_mutex_unlock (check_mutex);
+ g_cond_wait (&check_cond, &check_mutex);
+ g_mutex_unlock (&check_mutex);
/* Now wait for it to do that within a second, to avoid deadlocking
* in the event of future changes to the locking semantics. */
- g_mutex_lock (check_mutex);
+ g_mutex_lock (&check_mutex);
g_get_current_time (&deadline);
deadline.tv_sec += 1;
while (h->bufferalloc_blocked) {
- if (!g_cond_timed_wait (check_cond, check_mutex, &deadline))
+ if (!g_cond_timed_wait (&check_cond, &check_mutex, &deadline))
break;
}
- g_mutex_unlock (check_mutex);
+ g_mutex_unlock (&check_mutex);
}
*buf = gst_buffer_new_and_alloc (size);