clutter: Remove multi thread mutexes

The mutexes was used by ClutterTexture's async upload and to match GDK's
mutexes on X11. GDK's X11 connection does not share anything with
Clutter's, we don't have the Gdk Clutter backend left, and we have
already removed ClutterTexture, so lets remove these mutexes as well.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
This commit is contained in:
Jonas Ådahl 2020-05-23 22:50:43 +02:00
parent 34be97d855
commit de99dd7eb6
5 changed files with 6 additions and 115 deletions

View File

@ -83,10 +83,6 @@
/* main context */ /* main context */
static ClutterMainContext *ClutterCntx = NULL; static ClutterMainContext *ClutterCntx = NULL;
G_LOCK_DEFINE_STATIC (ClutterCntx);
/* main lock and locking/unlocking functions */
static GMutex clutter_threads_mutex;
/* command line options */ /* command line options */
static gboolean clutter_is_initialized = FALSE; static gboolean clutter_is_initialized = FALSE;
@ -145,12 +141,6 @@ static const GDebugKey clutter_paint_debug_keys[] = {
{ "damage-region", CLUTTER_DEBUG_PAINT_DAMAGE_REGION }, { "damage-region", CLUTTER_DEBUG_PAINT_DAMAGE_REGION },
}; };
static inline void
clutter_threads_init_default (void)
{
g_mutex_init (&clutter_threads_mutex);
}
#define ENVIRONMENT_GROUP "Environment" #define ENVIRONMENT_GROUP "Environment"
#define DEBUG_GROUP "Debug" #define DEBUG_GROUP "Debug"
@ -519,11 +509,7 @@ clutter_main (void)
main_loops = g_slist_prepend (main_loops, loop); main_loops = g_slist_prepend (main_loops, loop);
if (g_main_loop_is_running (main_loops->data)) if (g_main_loop_is_running (main_loops->data))
{ g_main_loop_run (loop);
_clutter_threads_release_lock ();
g_main_loop_run (loop);
_clutter_threads_acquire_lock ();
}
main_loops = g_slist_remove (main_loops, loop); main_loops = g_slist_remove (main_loops, loop);
@ -540,13 +526,9 @@ _clutter_threads_dispatch (gpointer data)
ClutterThreadsDispatch *dispatch = data; ClutterThreadsDispatch *dispatch = data;
gboolean ret = FALSE; gboolean ret = FALSE;
_clutter_threads_acquire_lock ();
if (!g_source_is_destroyed (g_main_current_source ())) if (!g_source_is_destroyed (g_main_current_source ()))
ret = dispatch->func (dispatch->data); ret = dispatch->func (dispatch->data);
_clutter_threads_release_lock ();
return ret; return ret;
} }
@ -771,40 +753,6 @@ clutter_threads_add_timeout (guint interval,
NULL); NULL);
} }
void
_clutter_threads_acquire_lock (void)
{
g_mutex_lock (&clutter_threads_mutex);
}
void
_clutter_threads_release_lock (void)
{
/* we need to trylock here, in case the lock hasn't been acquired; on
* various systems trying to release a mutex that hasn't been acquired
* will cause a run-time error. trylock() will either fail, in which
* case we can release the lock we own; or it will succeeds, in which
* case we need to release the lock we just acquired. so we ignore the
* returned value.
*
* see: https://bugs.gnome.org/679439
*/
g_mutex_trylock (&clutter_threads_mutex);
g_mutex_unlock (&clutter_threads_mutex);
}
void
_clutter_context_lock (void)
{
G_LOCK (ClutterCntx);
}
void
_clutter_context_unlock (void)
{
G_UNLOCK (ClutterCntx);
}
gboolean gboolean
_clutter_context_is_initialized (void) _clutter_context_is_initialized (void)
{ {
@ -814,8 +762,8 @@ _clutter_context_is_initialized (void)
return ClutterCntx->is_initialized; return ClutterCntx->is_initialized;
} }
static ClutterMainContext * ClutterMainContext *
clutter_context_get_default_unlocked (void) _clutter_context_get_default (void)
{ {
if (G_UNLIKELY (ClutterCntx == NULL)) if (G_UNLIKELY (ClutterCntx == NULL))
{ {
@ -846,20 +794,6 @@ clutter_context_get_default_unlocked (void)
return ClutterCntx; return ClutterCntx;
} }
ClutterMainContext *
_clutter_context_get_default (void)
{
ClutterMainContext *retval;
_clutter_context_lock ();
retval = clutter_context_get_default_unlocked ();
_clutter_context_unlock ();
return retval;
}
static gboolean static gboolean
clutter_arg_direction_cb (const char *key, clutter_arg_direction_cb (const char *key,
const char *value, const char *value,
@ -2170,9 +2104,6 @@ clutter_base_init (void)
g_type_init (); g_type_init ();
#endif #endif
/* initialise the Big Clutter Lock™ if necessary */
clutter_threads_init_default ();
clutter_graphene_init (); clutter_graphene_init ();
} }
} }
@ -2240,9 +2171,7 @@ clutter_threads_remove_repaint_func (guint handle_id)
g_return_if_fail (handle_id > 0); g_return_if_fail (handle_id > 0);
_clutter_context_lock (); context = _clutter_context_get_default ();
context = clutter_context_get_default_unlocked ();
l = context->repaint_funcs; l = context->repaint_funcs;
while (l != NULL) while (l != NULL)
{ {
@ -2265,8 +2194,6 @@ clutter_threads_remove_repaint_func (guint handle_id)
l = l->next; l = l->next;
} }
_clutter_context_unlock ();
} }
/** /**
@ -2365,9 +2292,7 @@ clutter_threads_add_repaint_func_full (ClutterRepaintFlags flags,
g_return_val_if_fail (func != NULL, 0); g_return_val_if_fail (func != NULL, 0);
_clutter_context_lock (); context = _clutter_context_get_default ();
context = clutter_context_get_default_unlocked ();
repaint_func = g_slice_new (ClutterRepaintFunction); repaint_func = g_slice_new (ClutterRepaintFunction);
@ -2381,8 +2306,6 @@ clutter_threads_add_repaint_func_full (ClutterRepaintFlags flags,
context->repaint_funcs = g_list_prepend (context->repaint_funcs, context->repaint_funcs = g_list_prepend (context->repaint_funcs,
repaint_func); repaint_func);
_clutter_context_unlock ();
return repaint_func->id; return repaint_func->id;
} }

View File

@ -413,8 +413,6 @@ clutter_clock_prepare (GSource *source,
ClutterMasterClockDefault *master_clock = clock_source->master_clock; ClutterMasterClockDefault *master_clock = clock_source->master_clock;
int delay; int delay;
_clutter_threads_acquire_lock ();
if (G_UNLIKELY (clutter_paint_debug_flags & if (G_UNLIKELY (clutter_paint_debug_flags &
CLUTTER_DEBUG_CONTINUOUS_REDRAW)) CLUTTER_DEBUG_CONTINUOUS_REDRAW))
{ {
@ -430,8 +428,6 @@ clutter_clock_prepare (GSource *source,
delay = master_clock_next_frame_delay (master_clock); delay = master_clock_next_frame_delay (master_clock);
_clutter_threads_release_lock ();
*timeout = delay; *timeout = delay;
return delay == 0; return delay == 0;
@ -444,9 +440,7 @@ clutter_clock_check (GSource *source)
ClutterMasterClockDefault *master_clock = clock_source->master_clock; ClutterMasterClockDefault *master_clock = clock_source->master_clock;
int delay; int delay;
_clutter_threads_acquire_lock ();
delay = master_clock_next_frame_delay (master_clock); delay = master_clock_next_frame_delay (master_clock);
_clutter_threads_release_lock ();
return delay == 0; return delay == 0;
} }
@ -462,8 +456,6 @@ clutter_clock_dispatch (GSource *source,
CLUTTER_NOTE (SCHEDULER, "Master clock [tick]"); CLUTTER_NOTE (SCHEDULER, "Master clock [tick]");
_clutter_threads_acquire_lock ();
COGL_TRACE_BEGIN (ClutterMasterClockTick, "Master Clock (tick)"); COGL_TRACE_BEGIN (ClutterMasterClockTick, "Master Clock (tick)");
/* Get the time to use for this frame */ /* Get the time to use for this frame */
@ -499,8 +491,6 @@ clutter_clock_dispatch (GSource *source,
COGL_TRACE_END (ClutterMasterClockTick); COGL_TRACE_END (ClutterMasterClockTick);
_clutter_threads_release_lock ();
return TRUE; return TRUE;
} }

View File

@ -177,11 +177,6 @@ typedef struct
gboolean _clutter_threads_dispatch (gpointer data); gboolean _clutter_threads_dispatch (gpointer data);
void _clutter_threads_dispatch_free (gpointer data); void _clutter_threads_dispatch_free (gpointer data);
CLUTTER_EXPORT
void _clutter_threads_acquire_lock (void);
CLUTTER_EXPORT
void _clutter_threads_release_lock (void);
ClutterMainContext * _clutter_context_get_default (void); ClutterMainContext * _clutter_context_get_default (void);
void _clutter_context_lock (void); void _clutter_context_lock (void);
void _clutter_context_unlock (void); void _clutter_context_unlock (void);

View File

@ -885,13 +885,9 @@ meta_event_prepare (GSource *source,
{ {
gboolean retval; gboolean retval;
_clutter_threads_acquire_lock ();
*timeout = -1; *timeout = -1;
retval = clutter_events_pending (); retval = clutter_events_pending ();
_clutter_threads_release_lock ();
return retval; return retval;
} }
@ -901,13 +897,9 @@ meta_event_check (GSource *source)
MetaEventSource *event_source = (MetaEventSource *) source; MetaEventSource *event_source = (MetaEventSource *) source;
gboolean retval; gboolean retval;
_clutter_threads_acquire_lock ();
retval = ((event_source->event_poll_fd.revents & G_IO_IN) || retval = ((event_source->event_poll_fd.revents & G_IO_IN) ||
clutter_events_pending ()); clutter_events_pending ());
_clutter_threads_release_lock ();
return retval; return retval;
} }
@ -1273,8 +1265,6 @@ meta_event_dispatch (GSource *g_source,
MetaSeatNative *seat; MetaSeatNative *seat;
ClutterEvent *event; ClutterEvent *event;
_clutter_threads_acquire_lock ();
seat = source->seat; seat = source->seat;
/* Don't queue more events if we haven't finished handling the previous batch /* Don't queue more events if we haven't finished handling the previous batch
@ -1299,7 +1289,7 @@ meta_event_dispatch (GSource *g_source,
/* Drop events if we don't have any stage to forward them to */ /* Drop events if we don't have any stage to forward them to */
if (!_clutter_input_device_get_stage (input_device)) if (!_clutter_input_device_get_stage (input_device))
goto out; return TRUE;
/* update the device states *before* the event */ /* update the device states *before* the event */
event_state = seat->button_state | event_state = seat->button_state |
@ -1311,9 +1301,6 @@ meta_event_dispatch (GSource *g_source,
_clutter_stage_queue_event (event->any.stage, event, FALSE); _clutter_stage_queue_event (event->any.stage, event, FALSE);
} }
out:
_clutter_threads_release_lock ();
return TRUE; return TRUE;
} }
static GSourceFuncs event_funcs = { static GSourceFuncs event_funcs = {

View File

@ -92,8 +92,6 @@ meta_x11_handle_event (XEvent *xevent)
result = CLUTTER_X11_FILTER_CONTINUE; result = CLUTTER_X11_FILTER_CONTINUE;
_clutter_threads_acquire_lock ();
backend = clutter_get_default_backend (); backend = clutter_get_default_backend ();
event = clutter_event_new (CLUTTER_NOTHING); event = clutter_event_new (CLUTTER_NOTHING);
@ -135,8 +133,6 @@ out:
if (allocated_event) if (allocated_event)
XFreeEventData (xdisplay, &xevent->xcookie); XFreeEventData (xdisplay, &xevent->xcookie);
_clutter_threads_release_lock ();
return result; return result;
} }