Added mutex

This commit is contained in:
tastytea 2018-05-17 18:27:06 +02:00
parent 08a7cb1988
commit 44f1692e80
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
2 changed files with 7 additions and 1 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (expandurl-mastodon
VERSION 0.2.6
VERSION 0.3.0
LANGUAGES CXX
)

View File

@ -17,6 +17,7 @@
#include <fstream>
#include <cstdlib> // getenv()
#include <iostream>
#include <mutex>
#include "version.hpp"
#include "expandurl-mastodon.hpp"
@ -65,6 +66,10 @@ const void Listener::start()
cout << "DEBUG: Connection lost.\n";
_running = false;
});
while (_ptr == nullptr)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
const void Listener::stop()
@ -85,6 +90,7 @@ std::vector<Easy::Notification> Listener::get_new_messages()
std::vector<Easy::Notification> v;
static std::uint_fast8_t count_empty = 0;
std::lock_guard<std::mutex> lock(_ptr->get_mutex());
if (!_stream.empty())
{
const string buffer = _stream;