while (client->running) {
pthread_mutex_lock(&client->mutex);
if (client->state == STATE_READY) {
- pthread_mutex_unlock(&client->mutex);
- usleep(5);
- continue;
+ pthread_cond_wait(&client->cond, &client->mutex);
}
memset(client->pty_buffer, 0, sizeof(client->pty_buffer));
client->pty_len = read(pty, client->pty_buffer + LWS_PRE + 1, BUF_SIZE);
client->state = STATE_INIT;
client->pty_len = 0;
pthread_mutex_init(&client->mutex, NULL);
+ pthread_cond_init(&client->cond, NULL);
lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi),
client->hostname, sizeof(client->hostname),
client->address, sizeof(client->address));
pthread_mutex_lock(&client->mutex);
if (client->state != STATE_DONE)
lws_callback_on_writable(client->wsi);
+ else
+ pthread_cond_signal(&client->cond);
pthread_mutex_unlock(&client->mutex);
}
}