Hi,

On Wed, Jan 09, 2019 at 10:09:26AM +0000, Frediano Ziglio wrote:
> From: Marc-André Lureau <[email protected]>
> 
> spice-gtk requires glib 2.46.
> 
> Modernize a bit coroutine-gthread.

Sure,

> 
> Signed-off-by: Marc-André Lureau <[email protected]>
> ---
>  src/coroutine_gthread.c | 56 ++++++++++++++++-------------------------
>  1 file changed, 22 insertions(+), 34 deletions(-)
> 
> diff --git a/src/coroutine_gthread.c b/src/coroutine_gthread.c
> index b0098fa1..c7e903d1 100644
> --- a/src/coroutine_gthread.c
> +++ b/src/coroutine_gthread.c
> @@ -24,8 +24,8 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  
> -static GCond *run_cond;
> -static GMutex *run_lock;
> +static GCond run_cond;
> +static GMutex run_lock;;
>  static struct coroutine *current;
>  static struct coroutine leader;
>  
> @@ -37,19 +37,18 @@ static struct coroutine leader;
>  
>  static void coroutine_system_init(void)
>  {
> -     if (!g_thread_supported()) {
> -             CO_DEBUG("INIT");
> -             g_thread_init(NULL);
> -     }
> +     if (current != NULL)
> +             return;

with braces for the if,
Acked-by: Victor Toso <[email protected]>

> +
> +     CO_DEBUG("INIT");
>  
> +     g_cond_init(&run_cond);
>  
> -     run_cond = g_cond_new();
> -     run_lock = g_mutex_new();
>       CO_DEBUG("LOCK");
> -     g_mutex_lock(run_lock);
> +     g_mutex_lock(&run_lock);
>  
> -     /* The thread that creates the first coroutine is the system coroutine
> -      * so let's fill out a structure for it */
> +     /* The thread that creates the first coroutine is the system
> +      * coroutine so let's fill out a structure for it */
>       leader.entry = NULL;
>       leader.release = NULL;
>       leader.stack_size = 0;
> @@ -66,10 +65,10 @@ static gpointer coroutine_thread(gpointer opaque)
>  {
>       struct coroutine *co = opaque;
>       CO_DEBUG("LOCK");
> -     g_mutex_lock(run_lock);
> +     g_mutex_lock(&run_lock);
>       while (!co->runnable) {
>               CO_DEBUG("WAIT");
> -             g_cond_wait(run_cond, run_lock);
> +             g_cond_wait(&run_cond, &run_lock);
>       }
>  
>       CO_DEBUG("RUNNABLE");
> @@ -79,28 +78,19 @@ static gpointer coroutine_thread(gpointer opaque)
>  
>       co->caller->runnable = TRUE;
>       CO_DEBUG("BROADCAST");
> -     g_cond_broadcast(run_cond);
> +     g_cond_broadcast(&run_cond);
>       CO_DEBUG("UNLOCK");
> -     g_mutex_unlock(run_lock);
> +     g_mutex_unlock(&run_lock);
>  
>       return NULL;
>  }
>  
>  void coroutine_init(struct coroutine *co)
>  {
> -     GError *err = NULL;
> -
> -     if (run_cond == NULL)
> -             coroutine_system_init();
> -
> +     coroutine_system_init();
>       CO_DEBUG("NEW");
> -     co->thread = g_thread_create_full(coroutine_thread, co, co->stack_size,
> -                                       FALSE, TRUE,
> -                                       G_THREAD_PRIORITY_NORMAL,
> -                                       &err);
> -     if (err != NULL)
> -             g_error("g_thread_create_full() failed: %s", err->message);
> -
> +     co->thread = g_thread_new("coroutine-thread",
> +                               coroutine_thread, co);
>       co->exited = 0;
>       co->runnable = FALSE;
>       co->caller = NULL;
> @@ -118,14 +108,14 @@ void *coroutine_swap(struct coroutine *from, struct 
> coroutine *to, void *arg)
>       to->data = arg;
>       to->caller = from;
>       CO_DEBUG("BROADCAST");
> -     g_cond_broadcast(run_cond);
> +     g_cond_broadcast(&run_cond);
>       CO_DEBUG("UNLOCK");
> -     g_mutex_unlock(run_lock);
> +     g_mutex_unlock(&run_lock);
>       CO_DEBUG("LOCK");
> -     g_mutex_lock(run_lock);
> +     g_mutex_lock(&run_lock);
>       while (!from->runnable) {
>               CO_DEBUG("WAIT");
> -             g_cond_wait(run_cond, run_lock);
> +             g_cond_wait(&run_cond, &run_lock);
>       }
>       current = from;
>       to->caller = NULL;
> @@ -136,9 +126,7 @@ void *coroutine_swap(struct coroutine *from, struct 
> coroutine *to, void *arg)
>  
>  struct coroutine *coroutine_self(void)
>  {
> -     if (run_cond == NULL)
> -             coroutine_system_init();
> -
> +     coroutine_system_init();
>       return current;
>  }
>  
> -- 
> 2.20.1
> 
> _______________________________________________
> Spice-devel mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/spice-devel

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/spice-devel

Reply via email to