From 1cf689a6ad9d6c5cd29e11a6a96cb075eb2bbbb8 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 27 Mar 2022 22:11:07 +0200 Subject: Replaced ThreadSync with stl's mutex --- Stars45/CmpSelectDlg.cpp | 21 +++++++++++---------- Stars45/CmpSelectDlg.h | 5 +++-- Stars45/MusicDirector.cpp | 6 +++--- Stars45/MusicDirector.h | 5 +++-- Stars45/RadioView.cpp | 7 ++++--- Stars45/RadioView.h | 5 +++-- Stars45/RadioVox.cpp | 9 +++++---- Stars45/SoundCard.cpp | 6 ++++-- Stars45/SoundCard.h | 5 +++-- Stars45/SoundD3D.cpp | 9 +++++---- Stars45/SoundD3D.h | 5 +++-- 11 files changed, 47 insertions(+), 36 deletions(-) (limited to 'Stars45') diff --git a/Stars45/CmpSelectDlg.cpp b/Stars45/CmpSelectDlg.cpp index 18ba3d0..95f9efa 100644 --- a/Stars45/CmpSelectDlg.cpp +++ b/Stars45/CmpSelectDlg.cpp @@ -11,6 +11,8 @@ Mission Select Dialog Active Window class */ +#include + #include "CmpSelectDlg.h" #include "ConfirmDlg.h" #include "MenuScreen.h" @@ -32,7 +34,6 @@ #include "Mouse.h" #include "ParseUtil.h" #include "FormatUtil.h" -#include "ThreadSync.h" // +--------------------------------------------------------------------+ // DECLARE MAPPING FUNCTIONS: @@ -118,7 +119,7 @@ CmpSelectDlg::ExecFrame() OnAccept(0); } - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (loaded) { loaded = false; @@ -197,7 +198,7 @@ CmpSelectDlg::ExecFrame() bool CmpSelectDlg::CanClose() { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); return !loading; } @@ -206,7 +207,7 @@ CmpSelectDlg::CanClose() void CmpSelectDlg::ShowNewCampaigns() { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (loading && description) { description->SetText(ContentBundle::GetInstance()->GetText("CmpSelectDlg.already-loading")); @@ -283,7 +284,7 @@ CmpSelectDlg::ShowNewCampaigns() void CmpSelectDlg::ShowSavedCampaigns() { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (loading && description) { description->SetText(ContentBundle::GetInstance()->GetText("CmpSelectDlg.already-loading")); @@ -332,7 +333,7 @@ void CmpSelectDlg::OnCampaignSelect(AWEvent* event) { if (description && lst_campaigns) { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (loading) { description->SetText(ContentBundle::GetInstance()->GetText("CmpSelectDlg.already-loading")); @@ -363,7 +364,7 @@ CmpSelectDlg::OnCampaignSelect(AWEvent* event) images[i]->CopyBitmap(*c->GetImage(1)); lst_campaigns->SetItemImage(i, images[i]); - AutoThreadSync a(sync); + const std::lock_guard lock(sync); load_index = i; } else { @@ -486,7 +487,7 @@ CmpSelectDlg::OnConfirmDelete(AWEvent* event) void CmpSelectDlg::OnAccept(AWEvent* event) { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (loading) return; @@ -594,13 +595,13 @@ CmpSelectDlg::LoadProc() c = savegame.GetCampaign(); } - sync.acquire(); + sync.lock(); loading = false; loaded = true; campaign = c; - sync.release(); + sync.unlock(); return 0; } diff --git a/Stars45/CmpSelectDlg.h b/Stars45/CmpSelectDlg.h index 7463aec..093e21d 100644 --- a/Stars45/CmpSelectDlg.h +++ b/Stars45/CmpSelectDlg.h @@ -14,6 +14,8 @@ #ifndef CmpSelectDlg_h #define CmpSelectDlg_h +#include + #include "Types.h" #include "FormWindow.h" #include "Bitmap.h" @@ -22,7 +24,6 @@ #include "ListBox.h" #include "Font.h" #include "Text.h" -#include "ThreadSync.h" // +--------------------------------------------------------------------+ @@ -76,7 +77,7 @@ protected: Campaign* campaign; int selected_mission; HANDLE hproc; - ThreadSync sync; + std::mutex sync; bool loading; bool loaded; Text load_file; diff --git a/Stars45/MusicDirector.cpp b/Stars45/MusicDirector.cpp index 34e48a6..b2ff7ef 100644 --- a/Stars45/MusicDirector.cpp +++ b/Stars45/MusicDirector.cpp @@ -12,6 +12,7 @@ of background music tracks for both menu and game modes */ +#include #include "MusicDirector.h" #include "MusicTrack.h" @@ -20,7 +21,6 @@ #include "DataLoader.h" #include "FormatUtil.h" #include "Sound.h" -#include "ThreadSync.h" static MusicDirector* music_director = 0; @@ -91,7 +91,7 @@ MusicDirector::ExecFrame() { if (no_music) return; - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (next_track && !track) { track = next_track; @@ -273,7 +273,7 @@ MusicDirector::SetMode(int mode) { if (!music_director || music_director->no_music) return; - AutoThreadSync a(music_director->sync); + const std::lock_guard lock(music_director->sync); // stay in intro mode until it is complete: if (mode == MENU && (music_director->GetMode() == NONE || diff --git a/Stars45/MusicDirector.h b/Stars45/MusicDirector.h index 293b6d7..8fc6812 100644 --- a/Stars45/MusicDirector.h +++ b/Stars45/MusicDirector.h @@ -16,10 +16,11 @@ #ifndef MusicDirector_h #define MusicDirector_h +#include + #include "Types.h" #include "List.h" #include "Text.h" -#include "ThreadSync.h" // +-------------------------------------------------------------------+ @@ -108,7 +109,7 @@ protected: bool no_music; HANDLE hproc; - ThreadSync sync; + std::mutex sync; }; #endif // MusicDirector_h \ No newline at end of file diff --git a/Stars45/RadioView.cpp b/Stars45/RadioView.cpp index fe29a5d..8a63091 100644 --- a/Stars45/RadioView.cpp +++ b/Stars45/RadioView.cpp @@ -11,6 +11,8 @@ View class for Radio Communications HUD Overlay */ +#include + #include "RadioView.h" #include "RadioMessage.h" #include "RadioTraffic.h" @@ -35,7 +37,6 @@ #include "Clock.h" #include "ContentBundle.h" #include "Menu.h" -#include "ThreadSync.h" static Color hud_color = Color::Black; static Color txt_color = Color::White; @@ -163,7 +164,7 @@ static bool TargetRequired(const MenuItem* item) // +====================================================================+ RadioView* RadioView::radio_view = 0; -ThreadSync RadioView::sync; +std::mutex RadioView::sync; RadioView::RadioView(Window* c) : View(c), sim(0), ship(0), font(0), dst_elem(0) @@ -601,7 +602,7 @@ RadioView::GetRadioMenu(Ship* s) void RadioView::Message(const char* msg) { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (radio_view) { int index = -1; diff --git a/Stars45/RadioView.h b/Stars45/RadioView.h index 31b0887..1d25459 100644 --- a/Stars45/RadioView.h +++ b/Stars45/RadioView.h @@ -14,12 +14,13 @@ #ifndef RadioView_h #define RadioView_h +#include + #include "Types.h" #include "View.h" #include "Color.h" #include "SimObject.h" #include "Text.h" -#include "ThreadSync.h" // +--------------------------------------------------------------------+ @@ -80,7 +81,7 @@ protected: double msg_time[MAX_MSG]; static RadioView* radio_view; - static ThreadSync sync; + static std::mutex sync; }; #endif // RadioView_h diff --git a/Stars45/RadioVox.cpp b/Stars45/RadioVox.cpp index 2131aae..8942caf 100644 --- a/Stars45/RadioVox.cpp +++ b/Stars45/RadioVox.cpp @@ -11,6 +11,8 @@ View class for Radio Communications HUD Overlay */ +#include + #include "RadioVox.h" #include "RadioView.h" #include "AudioConfig.h" @@ -18,7 +20,6 @@ #include "DataLoader.h" #include "Game.h" #include "Sound.h" -#include "ThreadSync.h" // +====================================================================+ // @@ -42,7 +43,7 @@ public: bool shutdown; HANDLE hthread; List queue; - ThreadSync sync; + std::mutex sync; }; static RadioVoxController* controller = 0; @@ -100,7 +101,7 @@ RadioVoxController::UpdateThread() void RadioVoxController::Update() { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (queue.size()) { RadioVox* vox = queue.first(); @@ -116,7 +117,7 @@ RadioVoxController::Add(RadioVox* vox) if (!vox || vox->sounds.isEmpty()) return false; - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (queue.size() < MAX_QUEUE) { queue.append(vox); diff --git a/Stars45/SoundCard.cpp b/Stars45/SoundCard.cpp index c0b1368..1e54cce 100644 --- a/Stars45/SoundCard.cpp +++ b/Stars45/SoundCard.cpp @@ -11,6 +11,8 @@ Abstract sound card class */ +#include + #include "SoundCard.h" #include "Sound.h" @@ -72,7 +74,7 @@ SoundCard::UpdateThread() void SoundCard::Update() { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); ListIter iter = sounds; while (++iter) { @@ -93,7 +95,7 @@ SoundCard::Update() void SoundCard::AddSound(Sound* s) { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (!sounds.contains(s)) sounds.append(s); diff --git a/Stars45/SoundCard.h b/Stars45/SoundCard.h index 4c4e2cb..a791c81 100644 --- a/Stars45/SoundCard.h +++ b/Stars45/SoundCard.h @@ -14,9 +14,10 @@ #ifndef SoundCard_h #define SoundCard_h +#include + #include "Types.h" #include "List.h" -#include "ThreadSync.h" // +--------------------------------------------------------------------+ @@ -68,7 +69,7 @@ protected: HANDLE hthread; SoundStatus status; List sounds; - ThreadSync sync; + std::mutex sync; }; #endif // SoundCard_h diff --git a/Stars45/SoundD3D.cpp b/Stars45/SoundD3D.cpp index 617c8d3..803b85a 100644 --- a/Stars45/SoundD3D.cpp +++ b/Stars45/SoundD3D.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "SoundD3D.h" #include "Game.h" @@ -303,7 +304,7 @@ SoundCardD3D::SetListener(const Camera& cam, const Vec3& vel) bool SoundCardD3D::Pause() { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); ListIter iter = sounds; while (++iter) { @@ -321,7 +322,7 @@ SoundCardD3D::Pause() bool SoundCardD3D::Resume() { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); ListIter iter = sounds; while (++iter) { @@ -339,7 +340,7 @@ SoundCardD3D::Resume() bool SoundCardD3D::StopSoundEffects() { - AutoThreadSync a(sync); + const std::lock_guard lock(sync); DWORD ok_sounds = (Sound::INTERFACE | Sound::OGGVORBIS | Sound::RESOURCE); @@ -486,7 +487,7 @@ SoundD3D::Update() return; } - AutoThreadSync a(sync); + const std::lock_guard lock(sync); if (sound_check) sound_check->Update(this); diff --git a/Stars45/SoundD3D.h b/Stars45/SoundD3D.h index b103302..a667182 100644 --- a/Stars45/SoundD3D.h +++ b/Stars45/SoundD3D.h @@ -14,11 +14,12 @@ #ifndef SoundD3D_h #define SoundD3D_h +#include + //#define DIRECT_SOUND_3D #include "SoundCard.h" #include "Sound.h" #include "Camera.h" -#include "ThreadSync.h" #include #include #include "vorbis/vorbisfile.h" @@ -107,7 +108,7 @@ protected: BYTE eos_latch; bool moved; - ThreadSync sync; + std::mutex sync; OggVorbis_File* ov_file; }; -- cgit v1.1