ilmControl: get rid of context::valid
authorMarcus Fritzsch <marcus.fritzsch@xse.de>
Tue, 29 Jul 2014 13:37:08 +0000 (15:37 +0200)
committerNobuhiko Tanibata <NOBUHIKO_TANIBATA@denso.co.jp>
Tue, 12 Aug 2014 13:15:14 +0000 (22:15 +0900)
Replace valid with a needed "initialized" flag, also don't use
this flag to determine thread termination, pthread_cancel() is
used.

Signed-off-by: Marcus Fritzsch <marcus.fritzsch@xse.de>
ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c

index 22b6563..796878c 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <memory.h>
-#include <unistd.h>
 #include <pthread.h>
 #include <signal.h>
+#include <stdbool.h>
+
+#include <unistd.h>
 #include <poll.h>
+
 #include "ilm_common.h"
 #include "ilm_control_platform.h"
 #include "wayland-util.h"
@@ -346,7 +349,7 @@ struct wayland_context {
 
 struct ilm_control_context {
     struct wayland_context wl;
-    int32_t valid;
+    bool initialized;
 
     uint32_t num_screen;
 
@@ -403,6 +406,8 @@ static int init_control(void);
 
 static struct ilm_control_context* sync_and_acquire_instance(void);
 
+static void release_instance(void);
+
 static int create_controller_layer(struct wayland_context *ctx, t_ilm_uint width, t_ilm_uint height, t_ilm_layer layerid);
 
 static int32_t
@@ -1207,15 +1212,12 @@ static void
 wayland_destroy(void)
 {
     struct ilm_control_context *ctx = &ilm_context;
-    lock_context(ctx);
-    ctx->valid = 0;
-    unlock_context(ctx);
-    void* threadRetVal = NULL;
     pthread_cancel(ctx->thread);
-    if (0 != pthread_join(ctx->thread, &threadRetVal)) {
+    if (0 != pthread_join(ctx->thread, NULL)) {
         fprintf(stderr, "failed to join control thread\n");
     }
     destroy_control_resources();
+    memset(ctx, 0, sizeof *ctx);
 }
 
 static ilmErrorTypes
@@ -1223,7 +1225,7 @@ wayland_init(t_ilm_nativedisplay nativedisplay)
 {
     struct ilm_control_context *ctx = &ilm_context;
 
-    if (ctx->valid != 0)
+    if (ctx->initialized)
     {
         fprintf(stderr, "Already initialized!\n");
         return ILM_FAILED;
@@ -1288,15 +1290,6 @@ control_thread(void *p_ret)
 
     while (1)
     {
-        lock_context(ctx);
-        int valid = ctx->valid;
-        unlock_context(ctx);
-
-        if (valid != 1)
-        {
-            break;
-        }
-
         if (wl_display_prepare_read_queue(display, queue) != 0)
         {
             lock_context(ctx);
@@ -1374,8 +1367,6 @@ init_control(void)
     display_roundtrip_queue(wl->display, wl->queue);
     display_roundtrip_queue(wl->display, wl->queue);
 
-    ctx->valid = 1;
-
     ret = pthread_create(&ctx->thread, NULL, control_thread, NULL);
 
     if (ret != 0) {
@@ -1383,6 +1374,8 @@ init_control(void)
         return -1;
     }
 
+    ctx->initialized = true;
+
     return 0;
 }