[spice-server,4/5] red-client: Protect disconnecting with a lock

Submitted by Frediano Ziglio on Aug. 24, 2017, 2:37 p.m.

Details

Message ID 20170824143720.7805-4-fziglio@redhat.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Aug. 24, 2017, 2:37 p.m.
Allows to access it safely from different threads.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 server/red-client.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/server/red-client.c b/server/red-client.c
index 666903e3..3ce09e33 100644
--- a/server/red-client.c
+++ b/server/red-client.c
@@ -347,12 +347,18 @@  gboolean red_client_seamless_migration_done_for_channel(RedClient *client)
 
 gboolean red_client_is_disconnecting(RedClient *client)
 {
-    return client->disconnecting;
+    gboolean ret;
+    pthread_mutex_lock(&client->lock);
+    ret =  client->disconnecting;
+    pthread_mutex_unlock(&client->lock);
+    return ret;
 }
 
 void red_client_set_disconnecting(RedClient *client)
 {
+    pthread_mutex_lock(&client->lock);
     client->disconnecting = TRUE;
+    pthread_mutex_unlock(&client->lock);
 }
 
 RedsState *red_client_get_server(RedClient *client)

Comments

On Thu, Aug 24, 2017 at 03:37:19PM +0100, Frediano Ziglio wrote:
> Allows to access it safely from different threads.

I guess it would be worth mentioning the code paths where it's needed in
the commit log.

Christophe

> 
> Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> ---
>  server/red-client.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/server/red-client.c b/server/red-client.c
> index 666903e3..3ce09e33 100644
> --- a/server/red-client.c
> +++ b/server/red-client.c
> @@ -347,12 +347,18 @@ gboolean red_client_seamless_migration_done_for_channel(RedClient *client)
>  
>  gboolean red_client_is_disconnecting(RedClient *client)
>  {
> -    return client->disconnecting;
> +    gboolean ret;
> +    pthread_mutex_lock(&client->lock);
> +    ret =  client->disconnecting;
> +    pthread_mutex_unlock(&client->lock);
> +    return ret;
>  }
>  
>  void red_client_set_disconnecting(RedClient *client)
>  {
> +    pthread_mutex_lock(&client->lock);
>      client->disconnecting = TRUE;
> +    pthread_mutex_unlock(&client->lock);
>  }
>  
>  RedsState *red_client_get_server(RedClient *client)
> -- 
> 2.13.5
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel