made ircmanager::connection a shared_pointer

This commit is contained in:
fourtf 2017-01-30 19:43:17 +01:00
parent 1d1c98ecdb
commit 3c8d2740de
3 changed files with 6 additions and 10 deletions

View file

@ -15,9 +15,7 @@ Channels::getItems()
{
QMutexLocker locker(&Channels::channelsMutex);
int size = Channels::channels.size();
std::vector<std::shared_ptr<Channel>> items(size);
std::vector<std::shared_ptr<Channel>> items;
for (auto &item : Channels::channels.values()) {
items.push_back(std::get<0>(item));

View file

@ -15,7 +15,7 @@
namespace chatterino {
Account *IrcManager::account = nullptr;
IrcConnection *IrcManager::connection = NULL;
std::shared_ptr<IrcConnection> IrcManager::connection;
QMutex IrcManager::connectionMutex;
long IrcManager::connectionGeneration = 0;
const QString IrcManager::defaultClientId = "7ue61iz46fz11y3cugd0l3tawb4taal";
@ -136,9 +136,8 @@ IrcManager::beginConnecting()
IrcManager::connectionMutex.lock();
if (generation == IrcManager::connectionGeneration) {
delete IrcManager::connection;
c->moveToThread(QCoreApplication::instance()->thread());
IrcManager::connection = c;
IrcManager::connection = std::shared_ptr<IrcConnection>(c);
auto channels = Channels::getItems();
@ -156,9 +155,8 @@ IrcManager::disconnect()
{
IrcManager::connectionMutex.lock();
if (IrcManager::connection != NULL) {
delete IrcManager::connection;
IrcManager::connection = NULL;
if (IrcManager::connection.get() != NULL) {
IrcManager::connection = std::shared_ptr<IrcConnection>();
}
IrcManager::connectionMutex.unlock();

View file

@ -52,7 +52,7 @@ private:
static void beginConnecting();
static IrcConnection *connection;
static std::shared_ptr<IrcConnection> connection;
static QMutex connectionMutex;
static long connectionGeneration;