info->host = host;
info->serv = serv;
info->socktype = socktype;
+ pthread_mutex_init(&info->mutex, NULL);
+ pthread_cond_init(&info->cond, NULL);
struct timespec deadline;
clock_gettime(CLOCK_REALTIME, &deadline);
meshlink_handle_t *mesh = userdata;
assert(mesh);
+ pthread_mutex_lock(&mesh->discovery_mutex);
+
// handle catta logs
catta_set_log_function(discovery_log_cb);
fail:
- pthread_mutex_lock(&mesh->discovery_mutex);
pthread_cond_broadcast(&mesh->discovery_cond);
pthread_mutex_unlock(&mesh->discovery_mutex);
assert(!mesh->discovery_threadstarted);
assert(!mesh->catta_servicetype);
+ pthread_mutex_lock(&mesh->discovery_mutex);
+
// Start the discovery thread
if(pthread_create(&mesh->discovery_thread, NULL, discovery_loop, mesh) != 0) {
+ pthread_mutex_unlock(&mesh->discovery_mutex);
logger(mesh, MESHLINK_ERROR, "Could not start discovery thread: %s\n", strerror(errno));
memset(&mesh->discovery_thread, 0, sizeof(mesh)->discovery_thread);
return false;
}
- pthread_mutex_lock(&mesh->discovery_mutex);
pthread_cond_wait(&mesh->discovery_cond, &mesh->discovery_mutex);
pthread_mutex_unlock(&mesh->discovery_mutex);
}
}
- // initialize mutex
+ // initialize mutexes and conds
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mesh->mutex, &attr);
+ pthread_mutex_init(&mesh->discovery_mutex, NULL);
+ pthread_cond_init(&mesh->discovery_cond, NULL);
+
+ pthread_cond_init(&mesh->adns_cond, NULL);
+
mesh->threadstarted = false;
event_loop_init(&mesh->loop);
mesh->loop.data = mesh;