Re: [PATCH spice-server 02/16] test-display-base: Protect command ring with a mutex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Acked-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>

On Mon, Sep 04, 2017 at 11:57:10AM +0100, Frediano Ziglio wrote:
> The ring is accessed by multiple thread.
> 
> Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
> ---
>  server/tests/test-display-base.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
> index 69e0b8d2..ac1cffca 100644
> --- a/server/tests/test-display-base.c
> +++ b/server/tests/test-display-base.c
> @@ -26,6 +26,7 @@
>  #include <sys/select.h>
>  #include <sys/types.h>
>  #include <getopt.h>
> +#include <pthread.h>
>  
>  #include "spice.h"
>  #include <spice/qxl_dev.h>
> @@ -467,27 +468,35 @@ static void get_init_info(SPICE_GNUC_UNUSED QXLInstance *qin,
>  static unsigned int commands_end = 0;
>  static unsigned int commands_start = 0;
>  static struct QXLCommandExt* commands[1024];
> +static pthread_mutex_t command_mutex = PTHREAD_MUTEX_INITIALIZER;
>  
>  #define COMMANDS_SIZE G_N_ELEMENTS(commands)
>  
>  static void push_command(QXLCommandExt *ext)
>  {
> -    spice_assert(commands_end - commands_start < (int) COMMANDS_SIZE);
> +    pthread_mutex_lock(&command_mutex);
> +    spice_assert(commands_end - commands_start < COMMANDS_SIZE);
>      commands[commands_end % COMMANDS_SIZE] = ext;
>      commands_end++;
> +    pthread_mutex_unlock(&command_mutex);
>  }
>  
>  static struct QXLCommandExt *get_simple_command(void)
>  {
> +    pthread_mutex_lock(&command_mutex);
>      struct QXLCommandExt *ret = commands[commands_start % COMMANDS_SIZE];
>      spice_assert(commands_start < commands_end);
>      commands_start++;
> +    pthread_mutex_unlock(&command_mutex);
>      return ret;
>  }
>  
>  static int get_num_commands(void)
>  {
> -    return commands_end - commands_start;
> +    pthread_mutex_lock(&command_mutex);
> +    int ret = commands_end - commands_start;
> +    pthread_mutex_unlock(&command_mutex);
> +    return ret;
>  }
>  
>  // called from spice_server thread (i.e. red_worker thread)
> -- 
> 2.13.5
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]