Switch to unique_ptr for thread pointers in TriviaGame
This commit is contained in:
parent
4bcedace38
commit
273f732d8c
@ -108,14 +108,14 @@
|
|||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;WIN32_WINNT=0x0600;URDL_NO_LIB=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;WIN32_WINNT=0x0600;URDL_NO_LIB=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>C:\boost_1_61_0;C:\OpenSSL-Win64\include;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\cpr\include;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\websocketpp;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\sqlite3;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\libcurl\include;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\boost_1_61_0;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\openssl\include;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\websocketpp;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\sqlite3;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<AdditionalOptions>-D_SCL_SECURE_NO_WARNINGS -DUSE_SYSTEM_CURL=OFF -D_WIN32_WINNT=0x0A00 %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>-D_SCL_SECURE_NO_WARNINGS -DUSE_SYSTEM_CURL=OFF -D_WIN32_WINNT=0x0A00 %(AdditionalOptions)</AdditionalOptions>
|
||||||
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
|
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>libcurl.lib;sqlite3.lib;libeay32.lib;ssleay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>libcurl.lib;libeay32.lib;ssleay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
<AdditionalOptions>/SUBSYSTEM:CONSOLE %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/SUBSYSTEM:CONSOLE %(AdditionalOptions)</AdditionalOptions>
|
||||||
<AdditionalLibraryDirectories>C:\buildcurl\third-party\libcurl\lib\dll-release-x64;C:\OpenSSL-Win64\lib;C:\boost_1_61_0\lib64-msvc-14.0;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\sqlite3\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\libcurl\lib\dll-release-x64;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\openssl\lib;C:\Users\Jack\Documents\GitHubVisualStudio\TriviaDiscord\lib\boost_1_61_0\lib64-msvc-14.0;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@ -157,19 +157,10 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\lib\cpr\cpr\auth.cpp" />
|
<ClCompile Include="..\..\..\GitHubVisualStudio\TriviaDiscord\lib\sqlite3\sqlite3.c" />
|
||||||
<ClCompile Include="..\lib\cpr\cpr\cookies.cpp" />
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\cprtypes.cpp" />
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\digest.cpp" />
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\error.cpp" />
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\multipart.cpp" />
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\parameters.cpp" />
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\payload.cpp" />
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\proxies.cpp" />
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\session.cpp" />
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\util.cpp" />
|
|
||||||
<ClCompile Include="bot\APIHelper.cpp" />
|
<ClCompile Include="bot\APIHelper.cpp" />
|
||||||
<ClCompile Include="bot\ClientConnection.cpp" />
|
<ClCompile Include="bot\ClientConnection.cpp" />
|
||||||
|
<ClInclude Include="..\..\..\GitHubVisualStudio\TriviaDiscord\lib\sqlite3\sqlite3.h" />
|
||||||
<ClInclude Include="bot\ClientConnection.hpp" />
|
<ClInclude Include="bot\ClientConnection.hpp" />
|
||||||
<ClCompile Include="bot\GatewayHandler.cpp" />
|
<ClCompile Include="bot\GatewayHandler.cpp" />
|
||||||
<ClCompile Include="bot\http\HTTPHelper.cpp" />
|
<ClCompile Include="bot\http\HTTPHelper.cpp" />
|
||||||
|
@ -42,44 +42,14 @@
|
|||||||
<ClInclude Include="bot\data_structures\Guild.hpp">
|
<ClInclude Include="bot\data_structures\Guild.hpp">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\..\GitHubVisualStudio\TriviaDiscord\lib\sqlite3\sqlite3.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="bot\ClientConnection.cpp">
|
<ClCompile Include="bot\ClientConnection.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\lib\cpr\cpr\auth.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\cookies.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\cprtypes.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\digest.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\error.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\multipart.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\parameters.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\payload.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\proxies.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\session.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\lib\cpr\cpr\util.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="bot\GatewayHandler.cpp">
|
<ClCompile Include="bot\GatewayHandler.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -98,6 +68,9 @@
|
|||||||
<ClCompile Include="bot\TriviaBot.cpp">
|
<ClCompile Include="bot\TriviaBot.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\GitHubVisualStudio\TriviaDiscord\lib\sqlite3\sqlite3.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="bot\data_structures\Text.txt" />
|
<Text Include="bot\data_structures\Text.txt" />
|
||||||
|
@ -212,7 +212,7 @@ void TriviaGame::question() {
|
|||||||
ah->send_message(channel_id, ":question: **(" + std::to_string(questions_asked) + "/" + std::to_string(total_questions) + ")** " + current_question);
|
ah->send_message(channel_id, ":question: **(" + std::to_string(questions_asked) + "/" + std::to_string(total_questions) + ")** " + current_question);
|
||||||
question_start = boost::posix_time::microsec_clock::universal_time();
|
question_start = boost::posix_time::microsec_clock::universal_time();
|
||||||
|
|
||||||
current_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&TriviaGame::give_hint, this, 0, "")));
|
current_thread = std::make_unique<boost::thread>(boost::bind(&TriviaGame::give_hint, this, 0, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriviaGame::give_hint(int hints_given, std::string hint) {
|
void TriviaGame::give_hint(int hints_given, std::string hint) {
|
||||||
@ -277,9 +277,9 @@ void TriviaGame::give_hint(int hints_given, std::string hint) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hints_given < 4) {
|
if (hints_given < 4) {
|
||||||
current_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&TriviaGame::give_hint, this, hints_given, hint)));
|
current_thread = std::make_unique<boost::thread>(boost::bind(&TriviaGame::give_hint, this, hints_given, hint));
|
||||||
} else {
|
} else {
|
||||||
current_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&TriviaGame::question_failed, this)));
|
current_thread = std::make_unique<boost::thread>(boost::bind(&TriviaGame::question_failed, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ private:
|
|||||||
// <user_id, average_time>
|
// <user_id, average_time>
|
||||||
std::map<std::string, int> average_times;
|
std::map<std::string, int> average_times;
|
||||||
|
|
||||||
boost::shared_ptr<boost::thread> current_thread;
|
std::unique_ptr<boost::thread> current_thread;
|
||||||
|
|
||||||
boost::posix_time::ptime question_start;
|
boost::posix_time::ptime question_start;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user