]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
wait for heartbeat without loop
authorBastian Dehn <hhaalo@arcor.de>
Tue, 2 Apr 2024 15:05:19 +0000 (17:05 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 2 Apr 2024 15:05:19 +0000 (17:05 +0200)
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h
src/kds_s2000w_heartbeat.c
src/kds_s2000w_heartbeat.h

index 7ec9a4770dac2eff2cbbfd5167d5878e17eb6791..518dfc413c9ac9e187ebfea366fb7ed610a71656 100644 (file)
@@ -146,8 +146,8 @@ void _get_current_scan_status(handler* h)
        if (h->current_scan_status->available_images > 1)
                return;
 
-       while(h->wait);
-       wait_a_second(&h->wait);
+       join_thread();
+       wait_a_second();
        resp = kds_s2000w_client_response_init();
        kds_s2000w_client_status_session(h->sessionid, resp);
        if (resp->error_size > 0)
@@ -182,7 +182,6 @@ handler* init_handler()
 
        h->sessionid = 0;
        h->state = NOTCONNECTED;
-       h->wait = 0;
        h->current_scan_status->current_image_number = 1;
        h->current_scan_status->available_images = 0;
        h->current_scan_status->downloaded_images = 0;
@@ -212,7 +211,7 @@ handler* init_handler()
 void free_handler(handler* h)
 {
        debug_printf(ALL, "free handler");
-       while(h->wait);
+       join_thread();
        json_object_put(h->current_scanner_config);
        h->current_scanner_config = NULL;
        free(h->current_scan_status);
@@ -240,7 +239,6 @@ void reset_handler(handler* h)
        h->jpg_image->data = NULL;
 
        h->state = NOTCONNECTED;
-       h->wait = 0;
        h->current_scan_status->current_image_number = 1;
        h->current_scan_status->available_images = 0;
        h->current_scan_status->downloaded_images = 0;
index d855e253de6169af5a4d8da1f803c936387df10f..aba0ca5a3c37e4e6fef4fe50ca452b0c0aad9ad4 100644 (file)
@@ -48,7 +48,6 @@ typedef struct {
 typedef struct {
        long sessionid;
        int state;
-       int wait;
        json_object* current_scanner_config;
        scanstatus* current_scan_status;
        metadata* current_metadata;
index 62921bf8953f4eb402134026f21d7fcb72f82e5c..af6c87b2639c3d8e15c05e3a6f2188d05673300f 100644 (file)
@@ -2,17 +2,20 @@
 #include <pthread.h>
 #include "kds_s2000w_heartbeat.h"
 
-void* _wait_thread(void* wait)
+pthread_t pwait;
+
+void* _wait_thread(void *args)
 {
-       int* wait_bool = (int*) wait;
        sleep(1);
-       *wait_bool = 0;
        return NULL;
 }
 
-void wait_a_second(int* wait)
+void join_thread()
+{
+       pthread_join(pwait, NULL);
+}
+
+void wait_a_second()
 {
-       *wait = 1;
-       pthread_t pwait;
-       pthread_create(&pwait, NULL, _wait_thread, wait);
+       pthread_create(&pwait, NULL, _wait_thread, NULL);
 }
\ No newline at end of file
index 82c74063cf3b027060d3092b67d547dd2c987766..982b95be36ce10db48c0fbe0292ed4d937bd22f8 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef KDS_S2000W_HEARTBEAT_H
 #define KDS_S2000W_HEARTBEAT_H
 
-void wait_a_second(int* wait);
+void join_thread();
+void wait_a_second();
 
 #endif
\ No newline at end of file