Commit 3dd3895e authored by Wim Taymans's avatar Wim Taymans
Browse files

Added _get_prefered_stack to the scheduler

Original commit message from CVS:
Added _get_prefered_stack to the scheduler
parent 87b24741
......@@ -122,6 +122,7 @@ typedef enum {
GST_PAD_QUERY_TOTAL,
GST_PAD_QUERY_POSITION,
GST_PAD_QUERY_LATENCY,
GST_PAD_QUERY_JITTER,
} GstPadQueryType;
/* this defines the functions used to chain buffers
......
......@@ -93,6 +93,27 @@ gst_scheduler_setup (GstScheduler *sched)
CLASS (sched)->setup (sched);
}
/**
* gst_scheduler_get_prefered_stack:
* @sched: the scheduler
* @stack: a pointer to the location of the prefered stack
* @size: a pointer to the size of the prefered stack
*
* Get the prefered stack location and size of this scheduler.
*
* Returns: TRUE if the scheduler suggested a prefered stacksize and location.
*/
gboolean
gst_scheduler_get_prefered_stack (GstScheduler *sched, gpointer *stack, gulong *size)
{
g_return_val_if_fail (GST_IS_SCHEDULER (sched), FALSE);
if (CLASS (sched)->get_prefered_stack)
return CLASS (sched)->get_prefered_stack (sched, stack, size);
return FALSE;
}
/**
* gst_scheduler_reset:
* @sched: the scheduler
......
......@@ -85,6 +85,7 @@ struct _GstSchedulerClass {
/* virtual methods */
void (*setup) (GstScheduler *sched);
gboolean (*get_prefered_stack) (GstScheduler *sched, gpointer *stack, gulong *size);
void (*reset) (GstScheduler *sched);
void (*add_element) (GstScheduler *sched, GstElement *element);
void (*remove_element) (GstScheduler *sched, GstElement *element);
......@@ -114,6 +115,7 @@ GType gst_scheduler_get_type (void);
void gst_scheduler_setup (GstScheduler *sched);
gboolean gst_scheduler_get_prefered_stack(GstScheduler *sched, gpointer *stack, gulong *size);
void gst_scheduler_reset (GstScheduler *sched);
void gst_scheduler_add_element (GstScheduler *sched, GstElement *element);
void gst_scheduler_remove_element (GstScheduler *sched, GstElement *element);
......
......@@ -243,6 +243,8 @@ gst_thread_change_state (GstElement * element)
gboolean stateset = GST_STATE_SUCCESS;
gint transition;
pthread_t self = pthread_self ();
void *stack;
glong stacksize;
g_return_val_if_fail (GST_IS_THREAD (element), FALSE);
......@@ -270,8 +272,12 @@ gst_thread_change_state (GstElement * element)
g_mutex_lock (thread->lock);
pthread_attr_init (&thread->attr);
if (gst_scheduler_get_prefered_stack (GST_ELEMENT_SCHED (element), &stack, &stacksize)) {
pthread_attr_setstack (&thread->attr, stack, stacksize);
}
/* create the thread */
if (pthread_create (&thread->thread_id, NULL, gst_thread_main_loop, thread) != 0) {
if (pthread_create (&thread->thread_id, &thread->attr, gst_thread_main_loop, thread) != 0) {
g_mutex_unlock (thread->lock);
THR_DEBUG ("could not create thread \"%s\"", GST_ELEMENT_NAME (element));
return GST_STATE_FAILURE;
......
......@@ -65,6 +65,7 @@ struct _GstThread {
GstBin bin;
pthread_t thread_id; /* id of the thread, if any */
pthread_attr_t attr; /* attributes for the stack space */
gint pid; /* the pid of the thread */
gint ppid; /* the pid of the thread's parent process */
GMutex *lock; /* thread lock/condititon pair ... */
......
......@@ -40,6 +40,8 @@ typedef cothread_state cothread;
*/
#define do_cothreads_init(x) /* NOP */
#define do_cothreads_stackquery(stack,size) FALSE
#define do_cothread_switch(to) cothread_switch(to)
#define do_cothread_create(new_thread, context, func, argc, argv) \
......@@ -91,6 +93,9 @@ typedef cothread cothread_context;
cothreads_init(x); \
}G_STMT_END
#define do_cothreads_stackquery(stack,size) \
cothreads_alloc_thread_stack (stack, size)
#define do_cothread_switch(to) G_STMT_START{ \
cothread *from = cothread_self (); \
if (from == (to)) { \
......
......@@ -109,6 +109,7 @@ static void gst_basic_scheduler_init (GstBasicScheduler * scheduler);
static void gst_basic_scheduler_dispose (GObject *object);
static void gst_basic_scheduler_setup (GstScheduler *sched);
static gboolean gst_basic_scheduler_get_prefered_stack (GstScheduler *sched, gpointer *stack, gulong *size);
static void gst_basic_scheduler_reset (GstScheduler *sched);
static void gst_basic_scheduler_add_element (GstScheduler *sched, GstElement *element);
static void gst_basic_scheduler_remove_element (GstScheduler *sched, GstElement *element);
......@@ -200,6 +201,7 @@ gst_basic_scheduler_class_init (GstBasicSchedulerClass * klass)
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_basic_scheduler_dispose);
gstscheduler_class->setup = GST_DEBUG_FUNCPTR (gst_basic_scheduler_setup);
gstscheduler_class->get_prefered_stack= GST_DEBUG_FUNCPTR (gst_basic_scheduler_get_prefered_stack);
gstscheduler_class->reset = GST_DEBUG_FUNCPTR (gst_basic_scheduler_reset);
gstscheduler_class->add_element = GST_DEBUG_FUNCPTR (gst_basic_scheduler_add_element);
gstscheduler_class->remove_element = GST_DEBUG_FUNCPTR (gst_basic_scheduler_remove_element);
......@@ -931,7 +933,6 @@ gst_basic_scheduler_chain_recursive_add (GstSchedulerChain * chain, GstElement *
static void
gst_basic_scheduler_setup (GstScheduler *sched)
{
/* first create thread context */
if (GST_BASIC_SCHEDULER_CAST (sched)->context == NULL) {
GST_DEBUG (GST_CAT_SCHEDULING, "initializing cothread context");
......@@ -939,6 +940,16 @@ gst_basic_scheduler_setup (GstScheduler *sched)
}
}
static gboolean
gst_basic_scheduler_get_prefered_stack (GstScheduler *sched, gpointer *stack, gulong *size)
{
if (do_cothreads_stackquery (stack, size)) {
GST_DEBUG (GST_CAT_SCHEDULING, "getting prefered stack size as %p and %lu", *stack, *size);
return TRUE;
}
return FALSE;
}
static void
gst_basic_scheduler_reset (GstScheduler *sched)
{
......
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