mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
SysClocks need their own mutex/cond pair, as we have multiple (via subclasses). Use a static mutex for setting THE sy...
Original commit message from CVS: SysClocks need their own mutex/cond pair, as we have multiple (via subclasses). Use a static mutex for setting THE system clock
This commit is contained in:
parent
b74e6f24f2
commit
e8bc3500f3
2 changed files with 25 additions and 15 deletions
|
@ -38,8 +38,7 @@ static guint64 gst_system_clock_get_resolution (GstClock *clock);
|
||||||
static GstClockEntryStatus gst_system_clock_wait (GstClock *clock, GstClockEntry *entry);
|
static GstClockEntryStatus gst_system_clock_wait (GstClock *clock, GstClockEntry *entry);
|
||||||
static void gst_system_clock_unlock (GstClock *clock, GstClockEntry *entry);
|
static void gst_system_clock_unlock (GstClock *clock, GstClockEntry *entry);
|
||||||
|
|
||||||
static GCond *_gst_sysclock_cond = NULL;
|
static GStaticMutex _gst_sysclock_mutex = G_STATIC_MUTEX_INIT;
|
||||||
static GMutex *_gst_sysclock_mutex = NULL;
|
|
||||||
|
|
||||||
static GstClockClass *parent_class = NULL;
|
static GstClockClass *parent_class = NULL;
|
||||||
/* static guint gst_system_clock_signals[LAST_SIGNAL] = { 0 }; */
|
/* static guint gst_system_clock_signals[LAST_SIGNAL] = { 0 }; */
|
||||||
|
@ -87,20 +86,20 @@ gst_system_clock_class_init (GstSystemClockClass *klass)
|
||||||
gstclock_class->get_resolution = gst_system_clock_get_resolution;
|
gstclock_class->get_resolution = gst_system_clock_get_resolution;
|
||||||
gstclock_class->wait = gst_system_clock_wait;
|
gstclock_class->wait = gst_system_clock_wait;
|
||||||
gstclock_class->unlock = gst_system_clock_unlock;
|
gstclock_class->unlock = gst_system_clock_unlock;
|
||||||
|
|
||||||
_gst_sysclock_cond = g_cond_new ();
|
|
||||||
_gst_sysclock_mutex = g_mutex_new ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_system_clock_init (GstSystemClock *clock)
|
gst_system_clock_init (GstSystemClock *clock)
|
||||||
{
|
{
|
||||||
|
clock->mutex = g_mutex_new();
|
||||||
|
clock->cond = g_cond_new ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_system_clock_dispose (GObject *object)
|
gst_system_clock_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
GstClock *clock = (GstClock *) object;
|
GstClock *clock = (GstClock *) object;
|
||||||
|
GstSystemClock *sysclock = (GstSystemClock *) object;
|
||||||
|
|
||||||
/* there are subclasses of GstSystemClock running around... */
|
/* there are subclasses of GstSystemClock running around... */
|
||||||
if (_the_system_clock == clock) {
|
if (_the_system_clock == clock) {
|
||||||
|
@ -109,6 +108,10 @@ gst_system_clock_dispose (GObject *object)
|
||||||
/* no parent dispose here, this is bad enough already */
|
/* no parent dispose here, this is bad enough already */
|
||||||
} else {
|
} else {
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
|
|
||||||
|
/* FIXME: Notifying before freeing? */
|
||||||
|
g_cond_free (sysclock->cond);
|
||||||
|
g_mutex_free (sysclock->mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,9 +128,10 @@ gst_system_clock_obtain (void)
|
||||||
GstClock *clock = _the_system_clock;
|
GstClock *clock = _the_system_clock;
|
||||||
|
|
||||||
if (clock == NULL) {
|
if (clock == NULL) {
|
||||||
g_mutex_lock (_gst_sysclock_mutex);
|
g_static_mutex_lock (&_gst_sysclock_mutex);
|
||||||
if (clock != NULL) {
|
if (_the_system_clock != NULL) {
|
||||||
g_mutex_unlock (_gst_sysclock_mutex);
|
clock = _the_system_clock;
|
||||||
|
g_static_mutex_unlock (&_gst_sysclock_mutex);
|
||||||
goto have_clock;
|
goto have_clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +143,7 @@ gst_system_clock_obtain (void)
|
||||||
gst_object_sink (GST_OBJECT (clock));
|
gst_object_sink (GST_OBJECT (clock));
|
||||||
|
|
||||||
_the_system_clock = clock;
|
_the_system_clock = clock;
|
||||||
g_mutex_unlock (_gst_sysclock_mutex);
|
g_static_mutex_unlock (&_gst_sysclock_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
have_clock:
|
have_clock:
|
||||||
|
@ -169,6 +173,7 @@ gst_system_clock_wait (GstClock *clock, GstClockEntry *entry)
|
||||||
GstClockEntryStatus res;
|
GstClockEntryStatus res;
|
||||||
GstClockTime current, target;
|
GstClockTime current, target;
|
||||||
gint64 diff;
|
gint64 diff;
|
||||||
|
GstSystemClock *sysclock = GST_SYSTEM_CLOCK (clock);
|
||||||
|
|
||||||
current = gst_clock_get_time (clock);
|
current = gst_clock_get_time (clock);
|
||||||
diff = GST_CLOCK_ENTRY_TIME (entry) - current;
|
diff = GST_CLOCK_ENTRY_TIME (entry) - current;
|
||||||
|
@ -190,9 +195,9 @@ gst_system_clock_wait (GstClock *clock, GstClockEntry *entry)
|
||||||
GTimeVal tv;
|
GTimeVal tv;
|
||||||
|
|
||||||
GST_TIME_TO_TIMEVAL (target, tv);
|
GST_TIME_TO_TIMEVAL (target, tv);
|
||||||
g_mutex_lock (_gst_sysclock_mutex);
|
g_mutex_lock (sysclock->mutex);
|
||||||
g_cond_timed_wait (_gst_sysclock_cond, _gst_sysclock_mutex, &tv);
|
g_cond_timed_wait (sysclock->cond, sysclock->mutex, &tv);
|
||||||
g_mutex_unlock (_gst_sysclock_mutex);
|
g_mutex_unlock (sysclock->mutex);
|
||||||
res = entry->status;
|
res = entry->status;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -204,7 +209,9 @@ gst_system_clock_wait (GstClock *clock, GstClockEntry *entry)
|
||||||
static void
|
static void
|
||||||
gst_system_clock_unlock (GstClock *clock, GstClockEntry *entry)
|
gst_system_clock_unlock (GstClock *clock, GstClockEntry *entry)
|
||||||
{
|
{
|
||||||
g_mutex_lock (_gst_sysclock_mutex);
|
GstSystemClock *sysclock = GST_SYSTEM_CLOCK (clock);
|
||||||
g_cond_broadcast (_gst_sysclock_cond);
|
|
||||||
g_mutex_unlock (_gst_sysclock_mutex);
|
g_mutex_lock (sysclock->mutex);
|
||||||
|
g_cond_broadcast (sysclock->cond);
|
||||||
|
g_mutex_unlock (sysclock->mutex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ typedef struct _GstSystemClockClass GstSystemClockClass;
|
||||||
|
|
||||||
struct _GstSystemClock {
|
struct _GstSystemClock {
|
||||||
GstClock clock;
|
GstClock clock;
|
||||||
|
|
||||||
|
GMutex * mutex;
|
||||||
|
GCond * cond;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstSystemClockClass {
|
struct _GstSystemClockClass {
|
||||||
|
|
Loading…
Reference in a new issue