add locks and refactor for clarity
This commit is contained in:
parent
bfed2114e4
commit
a7979a3e56
|
@ -14,6 +14,7 @@ JACK::JACK(const std::string &id, const Json::Value &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string JACK::JACKState() {
|
std::string JACK::JACKState() {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
if (running_) {
|
if (running_) {
|
||||||
load_ = jack_cpu_load(client_);
|
load_ = jack_cpu_load(client_);
|
||||||
return state_;
|
return state_;
|
||||||
|
@ -30,24 +31,23 @@ std::string JACK::JACKState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
client_ = jack_client_open("waybar", JackNoStartServer, NULL);
|
client_ = jack_client_open("waybar", JackNoStartServer, NULL);
|
||||||
if (client_) {
|
if (!client_) return "disconnected";
|
||||||
|
|
||||||
|
if (config_["realtime"].isBool() && !config_["realtime"].asBool()) {
|
||||||
pthread_t jack_thread = jack_client_thread_id(client_);
|
pthread_t jack_thread = jack_client_thread_id(client_);
|
||||||
if (config_["realtime"].isBool() && !config_["realtime"].asBool())
|
|
||||||
jack_drop_real_time_scheduling(jack_thread);
|
jack_drop_real_time_scheduling(jack_thread);
|
||||||
|
}
|
||||||
|
|
||||||
bufsize_ = jack_get_buffer_size(client_);
|
bufsize_ = jack_get_buffer_size(client_);
|
||||||
samplerate_ = jack_get_sample_rate(client_);
|
samplerate_ = jack_get_sample_rate(client_);
|
||||||
jack_set_buffer_size_callback(client_, bufSizeCallback, this);
|
jack_set_buffer_size_callback(client_, bufSizeCallback, this);
|
||||||
jack_set_xrun_callback(client_, xrunCallback, this);
|
jack_set_xrun_callback(client_, xrunCallback, this);
|
||||||
jack_on_shutdown(client_, shutdownCallback, this);
|
jack_on_shutdown(client_, shutdownCallback, this);
|
||||||
|
if (jack_activate(client_)) return "disconnected";
|
||||||
|
|
||||||
if (!jack_activate(client_)) {
|
|
||||||
running_ = true;
|
running_ = true;
|
||||||
return "connected";
|
return "connected";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return "disconnected";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto JACK::update() -> void {
|
auto JACK::update() -> void {
|
||||||
std::string format;
|
std::string format;
|
||||||
|
@ -101,6 +101,7 @@ int JACK::xrun() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void JACK::shutdown() {
|
void JACK::shutdown() {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
running_ = false;
|
running_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue