#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"
struct ilm_control_context {
struct wayland_context wl;
- int32_t valid;
+ bool initialized;
uint32_t num_screen;
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
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
{
struct ilm_control_context *ctx = &ilm_context;
- if (ctx->valid != 0)
+ if (ctx->initialized)
{
fprintf(stderr, "Already initialized!\n");
return ILM_FAILED;
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);
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) {
return -1;
}
+ ctx->initialized = true;
+
return 0;
}