Commit ae87d97c authored by Wim Taymans's avatar Wim Taymans

- Removed unused locking from the cothreads

Original commit message from CVS:
- Removed unused locking from the cothreads
- use G_*_DECLS in .h files
- remove gstlog.h include from gstobject.h, add to .c files
- removed unused refcounting code from gstobject
- small fixes in #includes
- Added Scheduling policy and priority properties to gstthread so that
SCHED_FIFO and SCHED_RR threads can be constructed.
parent 160f5b16
......@@ -20,7 +20,6 @@
*/
#include <gst/gst.h>
#include "../cothreads.h"
GstElementDetails gst_autoplugcache_details = {
"AutoplugCache",
......
......@@ -58,9 +58,7 @@
#include <gst/gstextratypes.h>
#include <gst/gstenumtypes.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
/* initialize GST */
void gst_init (int *argc, char **argv[]);
......@@ -74,9 +72,7 @@ gboolean gst_has_threads (void);
void gst_main (void);
void gst_main_quit (void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#include <gst/gstlog.h>
......
......@@ -28,6 +28,7 @@
#include "gstautoplug.h"
#include "gstregistry.h"
#include "gstlog.h"
enum {
NEW_OBJECT,
......
......@@ -28,9 +28,7 @@
#include <gst/gstelement.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
#define GST_TYPE_AUTOPLUG \
(gst_autoplug_get_type())
......@@ -118,9 +116,7 @@ GstAutoplugFactory* gst_autoplug_factory_find (const gchar *name);
GstAutoplug* gst_autoplug_factory_create (GstAutoplugFactory *factory);
GstAutoplug* gst_autoplug_factory_make (const gchar *name);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#else /* GST_DISABLE_AUTOPLUG */
......
......@@ -27,6 +27,7 @@
#include "gstevent.h"
#include "gstbin.h"
#include "gstxml.h"
#include "gstlog.h"
#include "gstscheduler.h"
......
......@@ -26,9 +26,7 @@
#include <gst/gstelement.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
extern GstElementDetails gst_bin_details;
extern GType _gst_bin_type;
......@@ -133,9 +131,8 @@ void gst_bin_child_state_change (GstBin *bin, GstElementState oldstate,
void gst_bin_set_pre_iterate_function (GstBin *bin, GstBinPrePostIterateFunction func, gpointer func_data);
void gst_bin_set_post_iterate_function (GstBin *bin, GstBinPrePostIterateFunction func, gpointer func_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_BIN_H__ */
......
......@@ -25,6 +25,7 @@
#include "gstcaps.h"
#include "gsttype.h"
#include "gstlog.h"
static GMemChunk *_gst_caps_chunk;
static GMutex *_gst_caps_chunk_lock;
......
......@@ -24,13 +24,9 @@
#ifndef __GST_CAPS_H__
#define __GST_CAPS_H__
#include <gst/gstconfig.h>
#include <gst/gstprops.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
typedef struct _GstCaps GstCaps;
......@@ -140,8 +136,6 @@ xmlNodePtr gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent);
GstCaps* gst_caps_load_thyself (xmlNodePtr parent);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_CAPS_H__ */
......@@ -24,12 +24,10 @@
#ifndef __GST_CLOCK_H__
#define __GST_CLOCK_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <gst/gstobject.h>
G_BEGIN_DECLS
#define GST_TYPE_CLOCK \
(gst_clock_get_type())
#define GST_CLOCK(obj) \
......@@ -130,8 +128,6 @@ GstClockTime gst_clock_id_get_time (GstClockID id);
void gst_clock_set_resolution (GstClock *clock, guint64 resolution);
guint64 gst_clock_get_resolution (GstClock *clock);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_CLOCK_H__ */
......@@ -25,7 +25,6 @@
#define __GST_ELEMENT_H__
#include <gst/gstconfig.h>
#include <gst/gsttypes.h>
#include <gst/gstobject.h>
#include <gst/gstpad.h>
......
......@@ -25,6 +25,7 @@
#include "gstelement.h"
#include "gstregistry.h"
#include "gstlog.h"
static void gst_element_factory_class_init (GstElementFactoryClass *klass);
static void gst_element_factory_init (GstElementFactory *factory);
......
......@@ -24,18 +24,13 @@
#ifndef __GST_EXTRA_TYPES_H__
#define __GST_EXTRA_TYPES_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
#define GST_TYPE_FILENAME (gst_extra_get_filename_type())
GType gst_extra_get_filename_type(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_EXTRA_TYPES_H__ */
......@@ -23,6 +23,7 @@
#include "gst_private.h"
#include "gstobject.h"
#include "gstlog.h"
/* Object signals and args */
enum {
......@@ -165,7 +166,6 @@ gst_object_ref (GstObject *object)
g_object_ref (G_OBJECT (object));
return object;
}
#define gst_object_ref gst_object_ref
/**
* gst_object_unref:
......@@ -184,7 +184,6 @@ gst_object_unref (GstObject *object)
g_object_unref (G_OBJECT (object));
}
#define gst_object_unref gst_object_unref
/**
* gst_object_sink:
......@@ -395,87 +394,6 @@ gst_object_unparent (GstObject *object)
gst_object_unref (object);
}
/**
* gst_object_ref:
* @object: GstObject to reference
*
* Increments the refence count on the object.
*
* Returns: Apointer to the Object
*/
#ifndef gst_object_ref
GstObject*
gst_object_ref (GstObject *object)
{
g_return_if_fail (object != NULL, NULL);
g_return_if_fail (GST_IS_OBJECT (object), NULL);
/* #ifdef HAVE_ATOMIC_H */
/* g_return_if_fail (atomic_read (&(object->refcount)) > 0); */
/* atomic_inc (&(object->refcount)) */
/* #else */
g_return_if_fail (object->refcount > 0);
GST_LOCK (object);
/* object->refcount++; */
g_object_ref((GObject *)object);
GST_UNLOCK (object);
/* #endif */
return object;
}
#endif /* gst_object_ref */
/**
* gst_object_unref:
* @object: GstObject to unreference
*
* Decrements the refence count on the object. If reference count hits
* zero, destroy the object.
*/
#ifndef gst_object_unref
void
gst_object_unref (GstObject *object)
{
int reftest;
g_return_if_fail (object != NULL);
g_return_if_fail (GST_IS_OBJECT (object));
#ifdef HAVE_ATOMIC_H
g_return_if_fail (atomic_read (&(object->refcount)) > 0);
reftest = atomic_dec_and_test (&(object->refcount))
#else
g_return_if_fail (object->refcount > 0);
GST_LOCK (object);
object->refcount--;
reftest = (object->refcount == 0);
GST_UNLOCK (object);
#endif
/* if we ended up with the refcount at zero */
if (reftest) {
/* get the count to 1 for gtk_object_destroy() */
#ifdef HAVE_ATOMIC_H
atomic_set (&(object->refcount),1);
#else
object->refcount = 1;
#endif
/* destroy it */
gtk_object_destroy (G_OBJECT (object));
/* drop the refcount back to zero */
#ifdef HAVE_ATOMIC_H
atomic_set (&(object->refcount),0);
#else
object->refcount = 0;
#endif
/* finalize the object */
/* FIXME this is an evil hack that should be killed */
/* FIXMEFIXMEFIXMEFIXME */
/* gtk_object_finalize(G_OBJECT(object)); */
}
}
#endif /* gst_object_unref */
/**
* gst_object_check_uniqueness:
* @list: a list of #GstObject to check through
......
......@@ -36,12 +36,7 @@
#include <gst/gsttrace.h>
#include <gst/gsttypes.h>
/* FIXME */
#include "gstlog.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
extern GType _gst_object_type;
......@@ -75,14 +70,8 @@ struct _GstObject {
GObject object;
gchar *name;
/* have to have a refcount for the object */
#ifdef HAVE_ATOMIC_H
atomic_t refcount;
#else
gint refcount;
#endif
/* locking for all sorts of things (like the refcount) */
/* locking for all sorts of things */
GMutex *lock;
/* this object's parent */
GstObject *parent;
......@@ -176,10 +165,7 @@ void gst_class_signal_emit_by_name (GstObject *object,
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_OBJECT_H__ */
......@@ -25,6 +25,7 @@
#include "gstparse.h"
#include "gstinfo.h"
#include "gstlog.h"
#include "parse/types.h"
typedef struct _gst_parse_delayed_pad gst_parse_delayed_pad;
......
......@@ -23,7 +23,7 @@
#ifndef __GST_PARSE_H__
#define __GST_PARSE_H__
#include <gst/gstpipeline.h>
#include <gst/gstbin.h>
G_BEGIN_DECLS
......
......@@ -23,6 +23,7 @@
#include "gst_private.h"
#include "gstpipeline.h"
#include "gstlog.h"
#include "gstscheduler.h"
GstElementDetails gst_pipeline_details = {
......
......@@ -26,9 +26,7 @@
#include <gst/gstbin.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
extern GstElementDetails gst_pipeline_details;
......@@ -59,10 +57,7 @@ GstElement* gst_pipeline_new (const gchar *name);
#define gst_pipeline_destroy(pipeline) gst_object_destroy(GST_OBJECT(pipeline))
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_PIPELINE_H__ */
......@@ -29,6 +29,7 @@
#include "gstplugin.h"
#include "gstversion.h"
#include "gstregistry.h"
#include "gstlog.h"
#include "config.h"
static GModule *main_module;
......
......@@ -27,9 +27,10 @@
#include <gst/gstconfig.h>
#include <gmodule.h>
#include <gst/gstpluginfeature.h>
G_BEGIN_DECLS
GQuark gst_plugin_error_quark (void);
#define GST_PLUGIN_ERROR gst_plugin_error_quark ()
......@@ -119,5 +120,6 @@ void gst_plugin_add_feature (GstPlugin *plugin, GstPluginFeature *feature);
gboolean gst_plugin_load (const gchar *name);
gboolean gst_library_load (const gchar *name);
G_END_DECLS
#endif /* __GST_PLUGIN_H__ */
......@@ -24,11 +24,12 @@
#include "gstpluginfeature.h"
#include "gstplugin.h"
#include "gstregistry.h"
#include "gstlog.h"
static void gst_plugin_feature_class_init (GstPluginFeatureClass *klass);
static void gst_plugin_feature_init (GstPluginFeature *feature);
static GstObjectClass *parent_class = NULL;
static GObjectClass *parent_class = NULL;
/* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
GType
......
......@@ -24,11 +24,9 @@
#ifndef __GST_PLUGIN_FEATURE_H__
#define __GST_PLUGIN_FEATURE_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <glib-object.h>
#include <gst/gstobject.h>
G_BEGIN_DECLS
#define GST_TYPE_PLUGIN_FEATURE \
(gst_plugin_feature_get_type())
......@@ -67,9 +65,7 @@ GType gst_plugin_feature_get_type (void);
gboolean gst_plugin_feature_ensure_loaded (GstPluginFeature *feature);
void gst_plugin_feature_unload_thyself (GstPluginFeature *feature);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_PLUGIN_FEATURE_H__ */
......
......@@ -28,9 +28,7 @@
#include <glib-object.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
typedef struct _GstProps GstProps;
extern GType _gst_props_type;
......@@ -140,8 +138,6 @@ GstProps* gst_props_load_thyself (xmlNodePtr parent);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_PROPS_H__ */
......@@ -30,6 +30,8 @@
#include "gstinfo.h"
#include "gstregistry.h"
#include "gstlog.h"
#include "gstmarshal.h"
#define CLASS(registry) GST_REGISTRY_CLASS (G_OBJECT_GET_CLASS (registry))
......
......@@ -26,6 +26,7 @@
#include "gstsystemclock.h"
#include "gstscheduler.h"
#include "gstlog.h"
#include "gstregistry.h"
static void gst_scheduler_class_init (GstSchedulerClass *klass);
......
......@@ -28,10 +28,7 @@
#include <gst/gstelement.h>
#include <gst/gstbin.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
#define GST_TYPE_SCHEDULER \
(gst_scheduler_get_type())
......@@ -184,8 +181,6 @@ void gst_scheduler_factory_set_default_name (const gchar* name);
const gchar* gst_scheduler_factory_get_default_name (void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_SCHEDULER_H__ */
......@@ -26,9 +26,7 @@
#include <gst/gstclock.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
#define GST_TYPE_SYSTEM_CLOCK \
(gst_system_clock_get_type())
......@@ -57,9 +55,6 @@ GType gst_system_clock_get_type (void);
GstClock* gst_system_clock_obtain (void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_SYSTEM_CLOCK_H__ */
......@@ -42,6 +42,7 @@ GstElementDetails gst_thread_details = {
/* Thread signals and args */
enum {
SHUTDOWN,
/* FILL ME */
LAST_SIGNAL
};
......@@ -54,6 +55,8 @@ enum {
enum {
ARG_0,
ARG_SCHEDPOLICY,
ARG_PRIORITY,
};
......@@ -75,8 +78,24 @@ static void gst_thread_restore_thyself (GstObject *object, xmlNodePtr self);
static void* gst_thread_main_loop (void *arg);
#define GST_TYPE_THREAD_SCHEDPOLICY (gst_thread_schedpolicy_get_type())
static GType
gst_thread_schedpolicy_get_type(void) {
static GType thread_schedpolicy_type = 0;
static GEnumValue thread_schedpolicy[] = {
{SCHED_OTHER, "SCHED_OTHER", "Normal Scheduling"},
{SCHED_FIFO, "SCHED_FIFO", "FIFO Scheduling (requires root)"},
{SCHED_RR, "SCHED_RR", "Round-Robin Scheduling (requires root)"},
{0, NULL, NULL},
};
if (!thread_schedpolicy_type) {
thread_schedpolicy_type = g_enum_register_static("GstThreadSchedPolicy", thread_schedpolicy);
}
return thread_schedpolicy_type;
}
static GstBinClass *parent_class = NULL;
/* static guint gst_thread_signals[LAST_SIGNAL] = { 0 }; */
static guint gst_thread_signals[LAST_SIGNAL] = { 0 };
GType
gst_thread_get_type(void) {
......@@ -115,6 +134,18 @@ gst_thread_class_init (GstThreadClass *klass)
parent_class = g_type_class_ref (GST_TYPE_BIN);
g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_SCHEDPOLICY,
g_param_spec_enum("schedpolicy", "Scheduling Policy", "The scheduling policy of the thread",
GST_TYPE_THREAD_SCHEDPOLICY, SCHED_OTHER, G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_PRIORITY,
g_param_spec_int("priority", "Scheduling Priority", "The scheduling priority of the thread",
0, 99, 0, G_PARAM_READWRITE));
gst_thread_signals[SHUTDOWN] =
g_signal_new ("shutdown", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstThreadClass, shutdown), NULL, NULL,
gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
gobject_class->dispose = gst_thread_dispose;
#ifndef GST_DISABLE_LOADSAVE
......@@ -148,6 +179,8 @@ gst_thread_init (GstThread *thread)
thread->ppid = getpid ();
thread->thread_id = -1;
thread->sched_policy = SCHED_OTHER;
thread->priority = 0;
}
static void
......@@ -170,10 +203,20 @@ gst_thread_dispose (GObject *object)
static void
gst_thread_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
GstThread *thread;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_THREAD (object));
thread = GST_THREAD (object);
switch (prop_id) {
case ARG_SCHEDPOLICY:
thread->sched_policy = g_value_get_enum (value);
break;
case ARG_PRIORITY:
thread->priority = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -183,10 +226,20 @@ gst_thread_set_property (GObject *object, guint prop_id, const GValue *value, GP
static void
gst_thread_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
GstThread *thread;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_THREAD (object));
thread = GST_THREAD (object);
switch (prop_id) {
case ARG_SCHEDPOLICY:
g_value_set_enum (value, thread->sched_policy);
break;
case ARG_PRIORITY:
g_value_set_int (value, thread->priority);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -275,6 +328,7 @@ gst_thread_change_state (GstElement * element)
if (pthread_attr_init (&thread->attr) != 0)
g_warning ("pthread_attr_init returned an error !");
if (gst_scheduler_get_preferred_stack (GST_ELEMENT_SCHED (element), &thread->stack, &stacksize)) {
if (pthread_attr_setstack (&thread->attr, thread->stack, stacksize) != 0) {
g_warning ("pthread_attr_setstack failed");
......@@ -465,6 +519,20 @@ gst_thread_main_loop (void *arg)
thread = GST_THREAD (arg);
g_mutex_lock (thread->lock);
if (thread->sched_policy != SCHED_OTHER) {
struct sched_param sched_param;
memset (&sched_param, 0, sizeof (sched_param));
if (thread->priority == 0) {
thread->priority = sched_get_priority_max (thread->sched_policy);
}
sched_param.sched_priority = thread->priority;
if (sched_setscheduler (0, thread->sched_policy, &sched_param) != 0) {
GST_DEBUG (GST_CAT_THREAD, "not running with real-time priority");
}
}
gst_scheduler_setup (GST_ELEMENT_SCHED (thread));
GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING);
......@@ -600,6 +668,9 @@ gst_thread_main_loop (void *arg)
GST_INFO (GST_CAT_THREAD, "gstthread: thread \"%s\" is stopped",
GST_ELEMENT_NAME (thread));
g_signal_emit (G_OBJECT (thread), gst_thread_signals[SHUTDOWN], 0);
return NULL;
}
......
......@@ -30,9 +30,7 @@
#include <gst/gstbin.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
extern GstElementDetails gst_thread_details;
......@@ -62,30 +60,33 @@ typedef struct _GstThread GstThread;
typedef struct _GstThreadClass GstThreadClass;
struct _GstThread {
GstBin bin;
pthread_t thread_id; /* id of the thread, if any */
pthread_attr_t attr; /* attributes for the stack space */
void *stack; /* set with gst_scheduler_get_preferred_stack */
gint pid; /* the pid of the thread */
gint ppid; /* the pid of the thread's parent process */
GMutex *lock; /* thread lock/condititon pair ... */
GCond *cond; /* .... used to control the thread */
gint transition; /* the current state transition */
GstBin bin;