From d5a542d0dcc625607593240fdb64c92d7b39690d Mon Sep 17 00:00:00 2001
From: Shuanglei Tao <tsl0922@gmail.com>
Date: Sun, 21 Apr 2019 07:16:34 +0800
Subject: [PATCH] protocol: do not block main thread when destroying client

---
 src/protocol.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/protocol.c b/src/protocol.c
index 027cdff..ca6fe3c 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -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);
-- 
2.43.4