[Spice-devel] [PATCH spice-server 04/16] test-display-base: Protect the wake up timer start with a mutex
Christophe Fergeau
cfergeau at redhat.com
Wed Sep 6 15:38:18 UTC 2017
On Mon, Sep 04, 2017 at 11:57:12AM +0100, Frediano Ziglio wrote:
> Timers in spice server are supposed to be used in a single thread
> context. To avoid problems protect the usage from multiple
> thread with a mutex.
"problems, protect"
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
> This sometimes caused a crash.
>
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> server/tests/test-display-base.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
> index da33ad08..f77f9659 100644
> --- a/server/tests/test-display-base.c
> +++ b/server/tests/test-display-base.c
> @@ -84,6 +84,10 @@ static int control = 3; //used to know when we can take a screenshot
> static int rects = 16; //number of rects that will be draw
> static int has_automated_tests = 0; //automated test flag
>
> +// SPICE implementation is not designed to have a timer shared
> +// between multiple threads so use a mutex
> +static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
> +
> __attribute__((noreturn))
> static void sigchld_handler(SPICE_GNUC_UNUSED int signal_num) // wait for the child process and exit
> {
> @@ -637,7 +641,9 @@ static int req_cmd_notification(QXLInstance *qin)
> {
> Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
>
> + pthread_mutex_lock(&timer_mutex);
> test->core->timer_start(test->wakeup_timer, test->wakeup_ms);
> + pthread_mutex_unlock(&timer_mutex);
> return TRUE;
> }
>
> @@ -651,7 +657,9 @@ static void do_wakeup(void *opaque)
> produce_command(test);
> }
>
> + pthread_mutex_lock(&timer_mutex);
> test->core->timer_start(test->wakeup_timer, test->wakeup_ms);
> + pthread_mutex_unlock(&timer_mutex);
> spice_qxl_wakeup(&test->qxl_instance);
> }
>
> --
> 2.13.5
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
More information about the Spice-devel
mailing list