summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.co.uk>2010-03-25 22:22:39 (GMT)
committerOlivier CrĂȘte <olivier.crete@collabora.co.uk>2010-09-09 08:28:52 (GMT)
commit8efb8187ee787afa032cb561b7b72bc1fd5f98ca (patch)
tree1bc6b97063514a6700719fbd22abaad03595761c
parent16eb6c449b63365a74498c89a176e49471c7c651 (diff)
downloadtelepathy-stream-engine-8efb8187ee787afa032cb561b7b72bc1fd5f98ca.tar.gz
telepathy-stream-engine-8efb8187ee787afa032cb561b7b72bc1fd5f98ca.tar.xz
Also separate thread leaving
-rw-r--r--src/thread-tracker.c21
-rw-r--r--src/thread-tracker.h5
-rw-r--r--src/tp-stream-engine.c16
3 files changed, 30 insertions, 12 deletions
diff --git a/src/thread-tracker.c b/src/thread-tracker.c
index 32ca90e..612fc67 100644
--- a/src/thread-tracker.c
+++ b/src/thread-tracker.c
@@ -22,6 +22,7 @@
#include "config.h"
#endif
+#include <pthread.h>
#include <sys/syscall.h>
#include <unistd.h>
@@ -33,7 +34,9 @@ static gboolean add_pad_locked (struct ObjectTrackingData *otd, GstPad *pad);
void
-thread_tracking_init (struct ThreadTrackingData *ttd, GMutex *mutex)
+thread_tracking_init (struct ThreadTrackingData *ttd,
+ GMutex *mutex,
+ setup_thread_prio restore_thread_prio)
{
ttd->object_threads =
g_hash_table_new (g_direct_hash, g_direct_equal);
@@ -41,6 +44,7 @@ thread_tracking_init (struct ThreadTrackingData *ttd, GMutex *mutex)
g_hash_table_new (g_direct_hash, g_direct_equal);
ttd->otds = g_ptr_array_new ();
ttd->mutex = mutex;
+ ttd->restore_thread_prio = restore_thread_prio;
}
void
@@ -294,3 +298,18 @@ enter_thread (struct ThreadTrackingData *ttd, GstObject *src)
g_mutex_unlock (ttd->mutex);
}
+
+
+void
+leave_thread (struct ThreadTrackingData *ttd, GstObject *src, GstElement *owner)
+{
+ pthread_t thread = pthread_self ();
+ pid_t tid = syscall (__NR_gettid);
+
+ g_mutex_lock (ttd->mutex);
+ g_hash_table_remove (ttd->object_threads, src);
+ g_hash_table_remove (ttd->object_tids, src);
+ g_mutex_unlock (ttd->mutex);
+
+ ttd->restore_thread_prio (thread, tid);
+}
diff --git a/src/thread-tracker.h b/src/thread-tracker.h
index 0a5bc7d..fb8a6bc 100644
--- a/src/thread-tracker.h
+++ b/src/thread-tracker.h
@@ -35,6 +35,8 @@ struct ThreadTrackingData {
GHashTable *object_tids;
GPtrArray *otds;
+
+ setup_thread_prio restore_thread_prio;
};
struct ObjectTrackingData {
@@ -45,7 +47,8 @@ struct ObjectTrackingData {
};
void thread_tracking_init (struct ThreadTrackingData *ttd,
- GMutex *mutex);
+ GMutex *mutex,
+ setup_thread_prio restore_thread_prio);
void object_tracking_init (struct ThreadTrackingData *ttd,
struct ObjectTrackingData *otd,
setup_thread_prio setup_thread_prio);
diff --git a/src/tp-stream-engine.c b/src/tp-stream-engine.c
index 1c9ae88..bc0054c 100644
--- a/src/tp-stream-engine.c
+++ b/src/tp-stream-engine.c
@@ -74,6 +74,7 @@ static void _create_pipeline (TpStreamEngine *self);
static void setup_realtime_thread (pthread_t thread, pid_t tid);
static void low_prio_thread (pthread_t thread, pid_t tid);
+static void restore_thread_prio (pthread_t thread, pid_t tid);
static void update_video_src_caps (TpStreamEngine *self, TfStream *forcedstream,
@@ -273,7 +274,8 @@ tp_stream_engine_init (TpStreamEngine *self)
priv->mutex = g_mutex_new ();
- thread_tracking_init (&priv->thread_tracking_data, priv->mutex);
+ thread_tracking_init (&priv->thread_tracking_data, priv->mutex,
+ restore_thread_prio);
object_tracking_init (&priv->thread_tracking_data,
&priv->audio_object_data, setup_realtime_thread);
object_tracking_init (&priv->thread_tracking_data,
@@ -1260,17 +1262,10 @@ low_prio_thread (pthread_t thread, pid_t tid)
}
static void
-leave_thread (struct ThreadTrackingData *ttd, GstObject *src, GstElement *owner)
+restore_thread_prio (pthread_t thread, pid_t tid)
{
- pthread_t thread = pthread_self ();
- pid_t tid = syscall (__NR_gettid);
struct sched_param param;
- g_mutex_lock (ttd->mutex);
- g_hash_table_remove (ttd->object_threads, src);
- g_hash_table_remove (ttd->object_tids, src);
- g_mutex_unlock (ttd->mutex);
-
if (setpriority (PRIO_PROCESS, tid, 0))
g_warning ("Could not restore thread priority to 0: %lX %s", (unsigned long int) thread, strerror (errno));
@@ -1278,6 +1273,7 @@ leave_thread (struct ThreadTrackingData *ttd, GstObject *src, GstElement *owner)
pthread_setschedparam (thread, SCHED_OTHER, &param);
}
+
static GstBusSyncReply
bus_sync_handler (GstBus *bus G_GNUC_UNUSED, GstMessage *message, gpointer data)
{
@@ -1351,7 +1347,7 @@ bus_sync_handler (GstBus *bus G_GNUC_UNUSED, GstMessage *message, gpointer data)
break;
case GST_STREAM_STATUS_TYPE_LEAVE:
leave_thread (&self->priv->thread_tracking_data,
- GST_MESSAGE_SRC (message), owner);
+ GST_MESSAGE_SRC (message));
break;
default:
break;