Corrected multithreading issue
This commit is contained in:
+1
-1
@@ -122,7 +122,7 @@ int main(int argc, char* argv[])
|
|||||||
// Initializing a connection pool to the database that will be shared along services
|
// Initializing a connection pool to the database that will be shared along services
|
||||||
auto connectionPool = Database::Handler::createConnectionPool(Config::instance().getPath("working-dir") / "lms.db");
|
auto connectionPool = Database::Handler::createConnectionPool(Config::instance().getPath("working-dir") / "lms.db");
|
||||||
|
|
||||||
UserInterface::LmsApplicationGroups appGroups;
|
UserInterface::LmsApplicationGroupContainer appGroups;
|
||||||
Scanner::MediaScanner scanner(*connectionPool);
|
Scanner::MediaScanner scanner(*connectionPool);
|
||||||
|
|
||||||
// bind entry point
|
// bind entry point
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
namespace UserInterface {
|
namespace UserInterface {
|
||||||
|
|
||||||
std::unique_ptr<Wt::WApplication>
|
std::unique_ptr<Wt::WApplication>
|
||||||
LmsApplication::create(const Wt::WEnvironment& env, Wt::Dbo::SqlConnectionPool& connectionPool, LmsApplicationGroups& appGroups, Scanner::MediaScanner& scanner)
|
LmsApplication::create(const Wt::WEnvironment& env, Wt::Dbo::SqlConnectionPool& connectionPool, LmsApplicationGroupContainer& appGroups, Scanner::MediaScanner& scanner)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* You could read information from the environment to decide whether
|
* You could read information from the environment to decide whether
|
||||||
@@ -71,7 +71,7 @@ LmsApplication::instance()
|
|||||||
* constructor so it is typically also an argument for your custom
|
* constructor so it is typically also an argument for your custom
|
||||||
* application constructor.
|
* application constructor.
|
||||||
*/
|
*/
|
||||||
LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnectionPool& connectionPool, LmsApplicationGroups& appGroups, Scanner::MediaScanner& scanner)
|
LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnectionPool& connectionPool, LmsApplicationGroupContainer& appGroups, Scanner::MediaScanner& scanner)
|
||||||
: Wt::WApplication(env),
|
: Wt::WApplication(env),
|
||||||
_db(connectionPool),
|
_db(connectionPool),
|
||||||
_appGroups(appGroups),
|
_appGroups(appGroups),
|
||||||
@@ -254,7 +254,7 @@ handlePathChange(Wt::WStackedWidget* stack, bool isAdmin)
|
|||||||
LmsApplicationGroup&
|
LmsApplicationGroup&
|
||||||
LmsApplication::getApplicationGroup()
|
LmsApplication::getApplicationGroup()
|
||||||
{
|
{
|
||||||
return _appGroups[_userIdentity];
|
return _appGroups.get(_userIdentity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -47,11 +47,11 @@ struct GroupEvents
|
|||||||
class LmsApplication : public Wt::WApplication
|
class LmsApplication : public Wt::WApplication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnectionPool& connectionPool, LmsApplicationGroups& appGroups, Scanner::MediaScanner& scanner);
|
LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnectionPool& connectionPool, LmsApplicationGroupContainer& appGroups, Scanner::MediaScanner& scanner);
|
||||||
~LmsApplication();
|
~LmsApplication();
|
||||||
|
|
||||||
static std::unique_ptr<Wt::WApplication> create(const Wt::WEnvironment& env,
|
static std::unique_ptr<Wt::WApplication> create(const Wt::WEnvironment& env,
|
||||||
Wt::Dbo::SqlConnectionPool& connectionPool, LmsApplicationGroups& appGroups, Scanner::MediaScanner& scanner);
|
Wt::Dbo::SqlConnectionPool& connectionPool, LmsApplicationGroupContainer& appGroups, Scanner::MediaScanner& scanner);
|
||||||
static LmsApplication* instance();
|
static LmsApplication* instance();
|
||||||
|
|
||||||
// Session application data
|
// Session application data
|
||||||
@@ -88,7 +88,7 @@ class LmsApplication : public Wt::WApplication
|
|||||||
void createHome();
|
void createHome();
|
||||||
|
|
||||||
Database::Handler _db;
|
Database::Handler _db;
|
||||||
LmsApplicationGroups& _appGroups;
|
LmsApplicationGroupContainer& _appGroups;
|
||||||
GroupEvents _groupEvents;
|
GroupEvents _groupEvents;
|
||||||
Wt::WString _userIdentity;
|
Wt::WString _userIdentity;
|
||||||
Auth* _auth;
|
Auth* _auth;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ LmsApplicationInfo::fromEnvironment(const Wt::WEnvironment& env)
|
|||||||
void
|
void
|
||||||
LmsApplicationGroup::join(LmsApplicationInfo info)
|
LmsApplicationGroup::join(LmsApplicationInfo info)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
|
|
||||||
_apps.emplace(wApp->sessionId(), std::move(info));
|
_apps.emplace(wApp->sessionId(), std::move(info));
|
||||||
}
|
}
|
||||||
@@ -52,6 +53,7 @@ LmsApplicationGroup::getOtherSessionIds() const
|
|||||||
{
|
{
|
||||||
std::vector<std::string> res;
|
std::vector<std::string> res;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
for (auto const& app : _apps)
|
for (auto const& app : _apps)
|
||||||
{
|
{
|
||||||
if (app.first != wApp->sessionId())
|
if (app.first != wApp->sessionId())
|
||||||
@@ -74,5 +76,12 @@ LmsApplicationGroup::postOthers(std::function<void()> func) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LmsApplicationGroup&
|
||||||
|
LmsApplicationGroupContainer::get(Wt::WString identity)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
|
|
||||||
|
return _apps[identity];
|
||||||
|
}
|
||||||
|
|
||||||
} // UserInterface
|
} // UserInterface
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <Wt/WSignal.h>
|
#include <Wt/WSignal.h>
|
||||||
#include <Wt/WEnvironment.h>
|
#include <Wt/WEnvironment.h>
|
||||||
@@ -41,17 +42,25 @@ class LmsApplicationGroup
|
|||||||
void join(LmsApplicationInfo info);
|
void join(LmsApplicationInfo info);
|
||||||
void leave();
|
void leave();
|
||||||
|
|
||||||
std::vector<LmsApplicationInfo> list() const;
|
|
||||||
|
|
||||||
void postOthers(std::function<void()> func) const;
|
void postOthers(std::function<void()> func) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
mutable std::mutex _mutex;
|
||||||
|
|
||||||
std::vector<std::string> getOtherSessionIds() const;
|
std::vector<std::string> getOtherSessionIds() const;
|
||||||
|
|
||||||
std::map<std::string, LmsApplicationInfo> _apps;
|
std::map<std::string, LmsApplicationInfo> _apps;
|
||||||
};
|
};
|
||||||
|
|
||||||
using LmsApplicationGroups = std::map<Wt::WString, LmsApplicationGroup>;
|
class LmsApplicationGroupContainer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LmsApplicationGroup& get(Wt::WString identity);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<Wt::WString, LmsApplicationGroup> _apps;
|
||||||
|
std::mutex _mutex;
|
||||||
|
};
|
||||||
|
|
||||||
} // UserInterface
|
} // UserInterface
|
||||||
|
|||||||
Reference in New Issue
Block a user