From: Bastian Dehn Date: Tue, 2 Apr 2024 15:05:19 +0000 (+0200) Subject: wait for heartbeat without loop X-Git-Tag: v1.0.0^2~30 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=bb8800c46e9d86466e5a94567876cdd9c541e3f0;p=sane-kds-s2000w-net.git wait for heartbeat without loop --- diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index 7ec9a47..518dfc4 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -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; diff --git a/src/kds_s2000w_handler.h b/src/kds_s2000w_handler.h index d855e25..aba0ca5 100644 --- a/src/kds_s2000w_handler.h +++ b/src/kds_s2000w_handler.h @@ -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; diff --git a/src/kds_s2000w_heartbeat.c b/src/kds_s2000w_heartbeat.c index 62921bf..af6c87b 100644 --- a/src/kds_s2000w_heartbeat.c +++ b/src/kds_s2000w_heartbeat.c @@ -2,17 +2,20 @@ #include #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 diff --git a/src/kds_s2000w_heartbeat.h b/src/kds_s2000w_heartbeat.h index 82c7406..982b95b 100644 --- a/src/kds_s2000w_heartbeat.h +++ b/src/kds_s2000w_heartbeat.h @@ -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