[Spice-devel] [PATCH v2] Constify event_loop_core
Jonathon Jongsma
jjongsma at redhat.com
Tue Jun 28 20:19:26 UTC 2016
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
On Fri, 2016-06-24 at 08:54 +0100, Frediano Ziglio wrote:
> Was used as write variable only for testing.
> Avoid usage of not constant globals.
> Making globals constants avoid future race condition
> usages.
>
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> server/event-loop.c | 6 +++---
> server/red-common.h | 2 +-
> server/tests/basic_event_loop.c | 20 +++++++++++---------
> 3 files changed, 15 insertions(+), 13 deletions(-)
>
> Changes from v1:
> - fixed typo in comment;
> - extented commit comment.
>
> diff --git a/server/event-loop.c b/server/event-loop.c
> index 4738ed9..1b57460 100644
> --- a/server/event-loop.c
> +++ b/server/event-loop.c
> @@ -17,9 +17,9 @@
> */
>
> /*
> - *This file export a global variable:
> + * This file exports a global variable:
> *
> - * SpiceCoreInterfaceInternal event_loop_core;
> + * const SpiceCoreInterfaceInternal event_loop_core;
> */
>
> #include "red-common.h"
> @@ -168,7 +168,7 @@ static void watch_remove(SpiceWatch *watch)
> free(watch);
> }
>
> -SpiceCoreInterfaceInternal event_loop_core = {
> +const SpiceCoreInterfaceInternal event_loop_core = {
> .timer_add = timer_add,
> .timer_start = timer_start,
> .timer_cancel = timer_cancel,
> diff --git a/server/red-common.h b/server/red-common.h
> index 7add3d0..7ab7e15 100644
> --- a/server/red-common.h
> +++ b/server/red-common.h
> @@ -58,7 +58,7 @@ struct SpiceCoreInterfaceInternal {
> GMainContext *main_context;
> };
>
> -extern SpiceCoreInterfaceInternal event_loop_core;
> +extern const SpiceCoreInterfaceInternal event_loop_core;
>
> typedef struct RedsState RedsState;
>
> diff --git a/server/tests/basic_event_loop.c b/server/tests/basic_event_loop.c
> index b9e1b9c..4820387 100644
> --- a/server/tests/basic_event_loop.c
> +++ b/server/tests/basic_event_loop.c
> @@ -36,6 +36,7 @@ int debug = 0;
> } \
> }
>
> +static SpiceCoreInterfaceInternal base_core_interface;
> static GMainContext *main_context = NULL;
>
> GMainContext *basic_event_loop_get_context(void)
> @@ -69,12 +70,12 @@ static void ignore_sigpipe(void)
>
> static SpiceTimer* base_timer_add(SpiceTimerFunc func, void *opaque)
> {
> - return event_loop_core.timer_add(&event_loop_core, func, opaque);
> + return base_core_interface.timer_add(&base_core_interface, func, opaque);
> }
>
> static SpiceWatch *base_watch_add(int fd, int event_mask, SpiceWatchFunc
> func, void *opaque)
> {
> - return event_loop_core.watch_add(&event_loop_core, fd, event_mask, func,
> opaque);
> + return base_core_interface.watch_add(&base_core_interface, fd,
> event_mask, func, opaque);
> }
>
> static SpiceCoreInterface core = {
> @@ -91,13 +92,14 @@ SpiceCoreInterface *basic_event_loop_init(void)
> ignore_sigpipe();
> spice_assert(main_context == NULL);
> main_context = g_main_context_new();
> - core.timer_start = event_loop_core.timer_start;
> - core.timer_cancel = event_loop_core.timer_cancel;
> - core.timer_remove = event_loop_core.timer_remove;
> - core.watch_update_mask = event_loop_core.watch_update_mask;
> - core.watch_remove = event_loop_core.watch_remove;
> - event_loop_core.channel_event = core.channel_event =
> event_loop_channel_event;
> - event_loop_core.main_context = main_context;
> + base_core_interface = event_loop_core;
> + core.timer_start = base_core_interface.timer_start;
> + core.timer_cancel = base_core_interface.timer_cancel;
> + core.timer_remove = base_core_interface.timer_remove;
> + core.watch_update_mask = base_core_interface.watch_update_mask;
> + core.watch_remove = base_core_interface.watch_remove;
> + base_core_interface.channel_event = core.channel_event =
> event_loop_channel_event;
> + base_core_interface.main_context = main_context;
>
> return &core;
> }
More information about the Spice-devel
mailing list