logger(mesh, MESHLINK_DEBUG, "Could not start thread: %s\n", strerror(errno));
memset(&mesh->thread, 0, sizeof(mesh)->thread);
meshlink_errno = MESHLINK_EINTERNAL;
+ event_loop_stop(&mesh->loop);
pthread_mutex_unlock(&(mesh->mesh_mutex));
return false;
}
}
}
- // Wait for the main thread to finish
- pthread_mutex_unlock(&(mesh->mesh_mutex));
- pthread_join(mesh->thread, NULL);
- pthread_mutex_lock(&(mesh->mesh_mutex));
+ if(mesh->threadstarted) {
+ // Wait for the main thread to finish
+ pthread_mutex_unlock(&(mesh->mesh_mutex));
+ pthread_join(mesh->thread, NULL);
+ pthread_mutex_lock(&(mesh->mesh_mutex));
- mesh->threadstarted = false;
+ mesh->threadstarted = false;
+ }
// Close all metaconnections
if(mesh->connections) {
if(mesh->outgoings) {
list_delete_list(mesh->outgoings);
+ mesh->outgoings = NULL;
}
- mesh->outgoings = NULL;
-
pthread_mutex_unlock(&(mesh->mesh_mutex));
}