compatybility with old C++ on macos

This commit is contained in:
Robert Bendun 2023-01-13 10:57:00 +01:00
parent 01e0693031
commit 0bb1f22379
3 changed files with 19 additions and 12 deletions

View File

@ -167,7 +167,8 @@ struct Runner
midi::Serial_Midi midi; midi::Serial_Midi midi;
Interpreter interpreter; Interpreter interpreter;
std::shared_ptr<serialport::State> serial_state; std::shared_ptr<serialport::State> serial_state;
std::optional<std::jthread> serial_event_loop; std::thread serial_event_loop;
std::atomic<bool> serial_event_loop_stop = false;
/// Setup interpreter and midi connection with given port /// Setup interpreter and midi connection with given port
explicit Runner(std::optional<unsigned> output_port) explicit Runner(std::optional<unsigned> output_port)
@ -183,8 +184,8 @@ struct Runner
midi.serialport = serial_state; midi.serialport = serial_state;
serialport::initialize(); serialport::initialize();
serial_event_loop = std::jthread([this](std::stop_token token) mutable{ serial_event_loop = std::thread([this]() mutable {
serialport::event_loop(token, *serial_state); serialport::event_loop(serial_event_loop_stop, *serial_state);
}); });
interpreter.midi_connection = &midi; interpreter.midi_connection = &midi;
@ -209,6 +210,13 @@ struct Runner
Runner& operator=(Runner const&) = delete; Runner& operator=(Runner const&) = delete;
Runner& operator=(Runner &&) = delete; Runner& operator=(Runner &&) = delete;
~Runner() {
serial_event_loop_stop = true;
if (serial_event_loop.joinable()) {
serial_event_loop.join();
}
}
/// Consider given input file as new definition of parametless function /// Consider given input file as new definition of parametless function
/// ///
/// Useful for deffering execution of files to the point when all configuration of midi devices /// Useful for deffering execution of files to the point when all configuration of midi devices

View File

@ -38,9 +38,9 @@ namespace serialport{
return 8; return 8;
} }
void event_loop(std::stop_token token, State &state) void event_loop(std::atomic<bool> &stop, State &state)
{ {
while(!token.stop_requested()){ while(!stop){
try { try {
/// Search for the right device /// Search for the right device
auto const ports = serial::list_ports(); auto const ports = serial::list_ports();
@ -61,18 +61,18 @@ namespace serialport{
} }
} }
} }
/// Start connection /// Start connection
serial::Serial serial_conn(connection_port, 115200, serial::Timeout::simpleTimeout(1000)); serial::Serial serial_conn(connection_port, 115200, serial::Timeout::simpleTimeout(1000));
/*if(serial_conn.isOpen()) /*if(serial_conn.isOpen())
std::cout << "[SERIAL] Serial open\n"; std::cout << "[SERIAL] Serial open\n";
else else
std::cout << "[SERIAL] Serial not open\n"; std::cout << "[SERIAL] Serial not open\n";
std::cout << "[SERIAL] commence serial communication\n"; std::cout << "[SERIAL] commence serial communication\n";
*/ */

View File

@ -3,7 +3,6 @@
#include <string> #include <string>
#include <serial/serial.h> #include <serial/serial.h>
#include <stop_token>
#include <memory> #include <memory>
#include <array> #include <array>
#include <atomic> #include <atomic>
@ -24,10 +23,10 @@ namespace serialport{
void send(uint8_t message_type, uint8_t note_number); void send(uint8_t message_type, uint8_t note_number);
void set(unsigned position, std::uint32_t value); void set(unsigned position, std::uint32_t value);
}; };
void initialize(); void initialize();
void event_loop(std::stop_token token, State &state); void event_loop(std::atomic<bool> &stop, State &state);
std::uint8_t get_byte(); std::uint8_t get_byte();
} }
#endif //MUSIQUE_SERIALPORT_SERIALPORT_HH #endif //MUSIQUE_SERIALPORT_SERIALPORT_HH