implement destructor

This commit is contained in:
Siegfried Kienzle
2017-06-15 19:09:29 +02:00
parent 68433fc531
commit c9bbfff992
2 changed files with 6 additions and 5 deletions

View File

@@ -10,10 +10,10 @@ rfid_reader::rfid_reader()
thread = std::thread(&rfid_reader::loop, this); thread = std::thread(&rfid_reader::loop, this);
} }
~rfid_reader::rfid_reader() rfid_reader::~rfid_reader()
{ {
stop_thread = true;
thread.join(); if(thread.joinable()) thread.join();
} }
uint32_t rfid_reader::last_id() const uint32_t rfid_reader::last_id() const
@@ -23,7 +23,7 @@ uint32_t rfid_reader::last_id() const
void rfid_reader::loop() void rfid_reader::loop()
{ {
while(true) while(!stop_thread)
{ {
if(!mfrc.PICC_IsNewCardPresent()) if(!mfrc.PICC_IsNewCardPresent())
{ {

View File

@@ -13,12 +13,13 @@ public:
rfid_reader(); rfid_reader();
rfid_reader(const rfid_reader &) = delete; rfid_reader(const rfid_reader &) = delete;
rfid_reader(const rfid_reader &&) = delete; rfid_reader(const rfid_reader &&) = delete;
~rfid_reader() = default; ~rfid_reader();
void loop(); void loop();
private: private:
MFRC522 mfrc; MFRC522 mfrc;
uint32_t uid; uint32_t uid;
std::thread thread; std::thread thread;
bool stop_thread;
}; };