]> git.meshlink.io Git - meshlink/blobdiff - test/utils.c
Add condition check in auto connect for blacklisted nodes
[meshlink] / test / utils.c
index 4cafa4b452a9300b19d86c6fcace767ecefe2288..9a9bd211fcef7b85a5ee7904062e30f305009134 100644 (file)
@@ -15,6 +15,14 @@ void set_sync_flag(struct sync_flag *s, bool value) {
        pthread_mutex_unlock(&s->mutex);
 }
 
+bool check_sync_flag(struct sync_flag *s) {
+       bool flag;
+       pthread_mutex_lock(&s->mutex);
+       flag = s->flag;
+       pthread_mutex_unlock(&s->mutex);
+       return flag;
+}
+
 bool wait_sync_flag(struct sync_flag *s, int seconds) {
        struct timespec timeout;
        clock_gettime(CLOCK_REALTIME, &timeout);
@@ -22,10 +30,11 @@ bool wait_sync_flag(struct sync_flag *s, int seconds) {
 
        pthread_mutex_lock(&s->mutex);
 
-       while(!s->flag)
+       while(!s->flag) {
                if(!pthread_cond_timedwait(&s->cond, &s->mutex, &timeout) || errno != EINTR) {
                        break;
                }
+       }
 
        pthread_mutex_unlock(&s->mutex);
 
@@ -87,15 +96,11 @@ void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b) {
        a->priv = &pair_status;
        meshlink_set_node_status_cb(a, pair_status_cb);
 
-       pthread_mutex_lock(&pair_status.mutex);
-
        meshlink_start(a);
        meshlink_start(b);
 
        assert(wait_sync_flag(&pair_status, 5));
 
-       pthread_mutex_unlock(&pair_status.mutex);
-
        meshlink_set_node_status_cb(a, NULL);
        a->priv = NULL;
 }