Commit 69b7a292 authored by Wim Taymans's avatar Wim Taymans

Added a runtime option to use a dummy threading implementation that uses

Original commit message from CVS:
Added a runtime option to use a dummy threading implementation that uses
NOPs for all synchronisation and threading operations.
parent 694b7ee9
......@@ -74,6 +74,7 @@ libgstreamer_la_SOURCES = \
gstscheduler.c \
gstsystemclock.c \
gstthread.c \
gstthreaddummy.c \
$(GST_TRACE_SRC) \
gsttype.c \
$(GST_TYPEFIND_SRC) \
......
......@@ -41,9 +41,13 @@ gboolean _gst_registry_auto_load = TRUE;
static GstRegistry *_global_registry;
static GstRegistry *_user_registry;
static gboolean _gst_registry_fixed = FALSE;
static gboolean _nothreads = FALSE;
extern gint _gst_trace_on;
extern GThreadFunctions gst_thread_dummy_functions;
static void load_plugin_func (gpointer data, gpointer user_data);
static void init_popt_callback (poptContext context, enum poptCallbackReason reason,
const struct poptOption *option, const char *arg, void *data);
......@@ -76,6 +80,7 @@ enum {
ARG_PLUGIN_PATH,
ARG_PLUGIN_LOAD,
ARG_SCHEDULER,
ARG_NOTHREADS,
ARG_REGISTRY
};
......@@ -95,6 +100,7 @@ static const struct poptOption options[] = {
{"gst-plugin-path", NUL, POPT_ARG_STRING|POPT_ARGFLAG_STRIP, NULL, ARG_PLUGIN_PATH, "'" G_SEARCHPATH_SEPARATOR_S "'--separated path list for loading plugins", "PATHS"},
{"gst-plugin-load", NUL, POPT_ARG_STRING|POPT_ARGFLAG_STRIP, NULL, ARG_PLUGIN_LOAD, "comma-separated list of plugins to preload in addition to the list stored in env variable GST_PLUGIN_PATH", "PLUGINS"},
{"gst-scheduler", NUL, POPT_ARG_STRING|POPT_ARGFLAG_STRIP, NULL, ARG_SCHEDULER, "scheduler to use ('standard' is the default)", "SCHEDULER"},
{"gst-nothreads", NUL, POPT_ARG_NONE|POPT_ARGFLAG_STRIP, NULL, ARG_NOTHREADS, "use NOPs for all threading and locking operations", NULL},
{"gst-registry", NUL, POPT_ARG_STRING|POPT_ARGFLAG_STRIP, NULL, ARG_REGISTRY, "registry to use" , "REGISTRY"},
POPT_TABLEEND
};
......@@ -271,9 +277,6 @@ init_pre (void)
const gchar *homedir;
gchar *user_reg;
if (!g_thread_supported ())
g_thread_init (NULL);
g_type_init();
_global_registry = gst_xml_registry_new ("global_registry", GLOBAL_REGISTRY_FILE);
......@@ -334,12 +337,19 @@ init_post (void)
#ifndef GST_DISABLE_TRACE
GstTrace *gst_trace;
#endif
if (!g_thread_supported ()) {
if (_nothreads)
g_thread_init (&gst_thread_dummy_functions);
else
g_thread_init (NULL);
}
llf = G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL;
g_log_set_handler(g_log_domain_gstreamer, llf, debug_log_handler, NULL);
GST_INFO (GST_CAT_GST_INIT, "Initializing GStreamer Core Library version %s",
GST_VERSION);
GST_INFO (GST_CAT_GST_INIT, "Initializing GStreamer Core Library version %s %s",
GST_VERSION, _nothreads?"(no threads)":"");
gst_object_get_type ();
gst_pad_get_type ();
......@@ -482,6 +492,9 @@ init_popt_callback (poptContext context, enum poptCallbackReason reason,
case ARG_SCHEDULER:
gst_scheduler_factory_set_default_name (arg);
break;
case ARG_NOTHREADS:
_nothreads = TRUE;
break;
case ARG_REGISTRY:
g_object_set (G_OBJECT (_user_registry), "location", arg, NULL);
_gst_registry_fixed = TRUE;
......@@ -497,6 +510,13 @@ init_popt_callback (poptContext context, enum poptCallbackReason reason,
}
}
gboolean
gst_with_threads (void)
{
return !_nothreads;
}
static GSList *mainloops = NULL;
/**
......
......@@ -67,6 +67,8 @@ void gst_init_with_popt_table (int *argc, char **argv[],
const struct poptOption *popt_options);
const struct poptOption* gst_init_get_popt_table (void);
gboolean gst_with_threads (void);
void gst_main (void);
void gst_main_quit (void);
......
......@@ -25,6 +25,7 @@
/* #define GST_DEBUG_ENABLED */
#include "gst_private.h"
#include "gst.h"
#include "gstthread.h"
#include "gstscheduler.h"
#include "gstqueue.h"
......@@ -246,7 +247,8 @@ gst_thread_change_state (GstElement * element)
void *stack;
glong stacksize;
g_return_val_if_fail (GST_IS_THREAD (element), FALSE);
g_return_val_if_fail (GST_IS_THREAD (element), GST_STATE_FAILURE);
g_return_val_if_fail (gst_with_threads (), GST_STATE_FAILURE);
thread = GST_THREAD (element);
......
/* 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 <sys/time.h>
#include <glib.h>
#include "gstlog.h"
static GMutex *mutex = NULL;
static GCond *cond = NULL;
static GMutex*
gst_mutex_new_dummy_impl (void)
{
if (!mutex)
mutex = g_malloc (8);
return mutex;
}
static void gst_mutex_dummy_impl (GMutex *mutex) { /* NOP */ }
static gboolean
gst_mutex_trylock_dummy_impl (GMutex *mutex)
{
return TRUE;
}
static GCond*
gst_cond_new_dummy_impl (void)
{
if (!cond)
cond = g_malloc (8);
return cond;
}
static void
gst_cond_dummy_impl (GCond *cond) { /* NOP */ }
static gboolean
gst_cond_timed_wait_dummy_impl (GCond *cond, GMutex *mutex, GTimeVal *end_time)
{
struct timeval tvtarget;
GTimeVal tvnow;
guint64 now, target;
gint64 diff;
target = end_time->tv_sec * 1000000 + end_time->tv_usec;
g_get_current_time (&tvnow);
now = tvnow.tv_sec * 1000000 + tvnow.tv_usec;
diff = target - now;
if (diff > 1000) {
tvtarget.tv_usec = diff % 1000000;
tvtarget.tv_sec = diff / 1000000;
select(0, NULL, NULL, NULL, &tvtarget);
}
return TRUE;
}
static GPrivate*
gst_private_new_dummy_impl (GDestroyNotify destructor)
{
gpointer data;
data = g_new0 (gpointer, 1);
return (GPrivate *) data;
}
static gpointer
gst_private_get_dummy_impl (GPrivate *private_key)
{
gpointer *data = (gpointer) private_key;
return *data;
}
static void
gst_private_set_dummy_impl (GPrivate *private_key, gpointer data)
{
*((gpointer*)private_key) = data;
}
static void
gst_thread_create_dummy_impl (GThreadFunc func, gpointer data, gulong stack_size,
gboolean joinable, gboolean bound, GThreadPriority priority,
gpointer thread, GError **error)
{
g_warning ("GStreamer configured to not use threads");
}
static void
gst_thread_dummy_impl (void) { /* NOP */ }
static void
gst_thread_dummy_impl_1 (gpointer thread) { /* NOP */ }
static void
gst_thread_set_priority_dummy_impl (gpointer thread, GThreadPriority priority) { /* NOP */ }
static gboolean
gst_thread_equal_dummy_impl (gpointer thread1, gpointer thread2)
{
return (thread1 == thread2);
}
GThreadFunctions
gst_thread_dummy_functions =
{
gst_mutex_new_dummy_impl,
(void (*)(GMutex *)) gst_mutex_dummy_impl,
gst_mutex_trylock_dummy_impl,
(void (*)(GMutex *)) gst_mutex_dummy_impl,
gst_mutex_dummy_impl,
gst_cond_new_dummy_impl,
(void (*)(GCond *)) gst_cond_dummy_impl,
(void (*)(GCond *)) gst_cond_dummy_impl,
(void (*)(GCond *, GMutex *)) gst_cond_dummy_impl,
gst_cond_timed_wait_dummy_impl,
gst_cond_dummy_impl,
gst_private_new_dummy_impl,
gst_private_get_dummy_impl,
gst_private_set_dummy_impl,
gst_thread_create_dummy_impl,
gst_thread_dummy_impl,
gst_thread_dummy_impl_1,
gst_thread_dummy_impl,
gst_thread_set_priority_dummy_impl,
gst_thread_dummy_impl_1,
gst_thread_equal_dummy_impl
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment