]> prime8.dev >> repos - ttyd.git/commitdiff
protocol: do not block main thread when destroying client
authorShuanglei Tao <tsl0922@gmail.com>
Sat, 20 Apr 2019 23:16:34 +0000 (07:16 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Sat, 20 Apr 2019 23:17:07 +0000 (07:17 +0800)
src/protocol.c

index 027cdff9197f1b50ef3f680f151e3085db06e314..ca6fe3cd2ebadc6ff02d01d10cb52c826fb7f0be 100644 (file)
@@ -135,10 +135,11 @@ tty_client_destroy(struct tty_client *client) {
 
     client->running = false;
 
-    pthread_mutex_lock(&client->mutex);
-    client->state = STATE_DONE;
-    pthread_cond_signal(&client->cond);
-    pthread_mutex_unlock(&client->mutex);
+    if (pthread_mutex_trylock(&client->mutex)) {
+        client->state = STATE_DONE;
+        pthread_cond_signal(&client->cond);
+        pthread_mutex_unlock(&client->mutex);
+    }
 
     // kill process (group) and free resource
     int pgid = getpgid(client->pid);