From d712ce32cebba6f475c5a89cb0631d4cc828ac60 Mon Sep 17 00:00:00 2001 From: Stefan Gehn Date: Sun, 6 Jul 2014 18:37:43 +0200 Subject: [PATCH] Wait as short as possible after starting win32 sensor app Do not use a fixed 5 second delay after having a started a windows sensor application, instead try to access the shared memory area repeatedly and only give up after 10 seconds. Please note that for this feature to be usable the sensor app must be found in PATH. --- src/sysdeps/win32-sensors.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/sysdeps/win32-sensors.c b/src/sysdeps/win32-sensors.c index f404aaf..67f1b0a 100644 --- a/src/sysdeps/win32-sensors.c +++ b/src/sysdeps/win32-sensors.c @@ -73,6 +73,8 @@ static gboolean shm_open_or_start_app(ShmData *shm, const wchar_t *shm_name, const gchar *app_name) { + guint retries; + /* Try to open shared memory area and return if successful*/ if (shm_open(shm, shm_name)) return TRUE; @@ -91,11 +93,15 @@ shm_open_or_start_app(ShmData *shm, const wchar_t *shm_name, "Started sensor-app %s, waiting for it to initialize\n", app_name); - // 5 second wait to allow sensor-app init - g_usleep(5 * G_USEC_PER_SEC); + /* Wait up to retries seconds for the shared memory area to be accessible */ + for (retries = 10; retries > 0; --retries) + { + if (shm_open(shm, shm_name)) + return TRUE; + g_usleep(1 * G_USEC_PER_SEC); /* delay to allow sensor-app to startup */ + } - /* Retry open of shm-file */ - return shm_open(shm, shm_name); + return FALSE; }