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)
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;
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);
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;
#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
#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