Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit bf8c5fe

Browse files
committed
Fix compilation and apply suggestions (part 3)
1 parent 7b284f3 commit bf8c5fe

File tree

4 files changed

+45
-49
lines changed

4 files changed

+45
-49
lines changed

src/core/file_sys/archive_artic.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Result ArticArchive::RespResult(const std::optional<Network::ArticBase::Client::
4242

4343
ArticArchive::~ArticArchive() {
4444
if (clear_cache_on_close) {
45-
cache_provider.ClearAllCache();
45+
cache_provider->ClearAllCache();
4646
}
4747
if (archive_handle != -1) {
4848
auto req = client->NewRequest("FSUSER_CloseArchive");
@@ -84,7 +84,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArticArchive::Open(
8484

8585
void ArticArchive::Close() {
8686
if (clear_cache_on_close) {
87-
cache_provider.ClearAllCache();
87+
cache_provider->ClearAllCache();
8888
}
8989

9090
auto req = client->NewRequest("FSUSER_CloseArchive");
@@ -104,8 +104,8 @@ std::string ArticArchive::GetName() const {
104104
ResultVal<std::unique_ptr<FileBackend>> ArticArchive::OpenFile(const Path& path, const Mode& mode,
105105
u32 attributes) {
106106
if (mode.create_flag) {
107-
auto cache = cache_provider.ProvideCache(
108-
client, cache_provider.PathsToVector(archive_path, path), false);
107+
auto cache = cache_provider->ProvideCache(
108+
client, cache_provider->PathsToVector(archive_path, path), false);
109109
if (cache != nullptr) {
110110
cache->Clear();
111111
}
@@ -129,8 +129,8 @@ ResultVal<std::unique_ptr<FileBackend>> ArticArchive::OpenFile(const Path& path,
129129

130130
auto size_opt = resp->GetResponseU64(1);
131131
if (size_opt.has_value()) {
132-
auto cache = cache_provider.ProvideCache(
133-
client, cache_provider.PathsToVector(archive_path, path), true);
132+
auto cache = cache_provider->ProvideCache(
133+
client, cache_provider->PathsToVector(archive_path, path), true);
134134
if (cache != nullptr) {
135135
cache->ForceSetSize(static_cast<size_t>(*size_opt));
136136
}
@@ -144,8 +144,8 @@ ResultVal<std::unique_ptr<FileBackend>> ArticArchive::OpenFile(const Path& path,
144144
}
145145

146146
Result ArticArchive::DeleteFile(const Path& path) const {
147-
auto cache = cache_provider.ProvideCache(
148-
client, cache_provider.PathsToVector(archive_path, path), false);
147+
auto cache = cache_provider->ProvideCache(
148+
client, cache_provider->PathsToVector(archive_path, path), false);
149149
if (cache != nullptr) {
150150
cache->Clear();
151151
}
@@ -160,13 +160,13 @@ Result ArticArchive::DeleteFile(const Path& path) const {
160160
}
161161

162162
Result ArticArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
163-
auto cache = cache_provider.ProvideCache(
164-
client, cache_provider.PathsToVector(archive_path, src_path), false);
163+
auto cache = cache_provider->ProvideCache(
164+
client, cache_provider->PathsToVector(archive_path, src_path), false);
165165
if (cache != nullptr) {
166166
cache->Clear();
167167
}
168-
cache = cache_provider.ProvideCache(
169-
client, cache_provider.PathsToVector(archive_path, dest_path), false);
168+
cache = cache_provider->ProvideCache(
169+
client, cache_provider->PathsToVector(archive_path, dest_path), false);
170170
if (cache != nullptr) {
171171
cache->Clear();
172172
}
@@ -184,7 +184,7 @@ Result ArticArchive::RenameFile(const Path& src_path, const Path& dest_path) con
184184
}
185185

186186
Result ArticArchive::DeleteDirectory(const Path& path) const {
187-
cache_provider.ClearAllCache();
187+
cache_provider->ClearAllCache();
188188

189189
auto req = client->NewRequest("FSUSER_DeleteDirectory");
190190

@@ -196,7 +196,7 @@ Result ArticArchive::DeleteDirectory(const Path& path) const {
196196
}
197197

198198
Result ArticArchive::DeleteDirectoryRecursively(const Path& path) const {
199-
cache_provider.ClearAllCache();
199+
cache_provider->ClearAllCache();
200200

201201
auto req = client->NewRequest("FSUSER_DeleteDirectoryRec");
202202

@@ -208,8 +208,8 @@ Result ArticArchive::DeleteDirectoryRecursively(const Path& path) const {
208208
}
209209

210210
Result ArticArchive::CreateFile(const Path& path, u64 size, u32 attributes) const {
211-
auto cache = cache_provider.ProvideCache(
212-
client, cache_provider.PathsToVector(archive_path, path), false);
211+
auto cache = cache_provider->ProvideCache(
212+
client, cache_provider->PathsToVector(archive_path, path), false);
213213
if (cache != nullptr) {
214214
cache->Clear();
215215
}
@@ -237,7 +237,7 @@ Result ArticArchive::CreateDirectory(const Path& path, u32 attributes) const {
237237
}
238238

239239
Result ArticArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
240-
cache_provider.ClearAllCache();
240+
cache_provider->ClearAllCache();
241241

242242
auto req = client->NewRequest("FSUSER_RenameDirectory");
243243

@@ -376,8 +376,8 @@ ArticFileBackend::~ArticFileBackend() {
376376
}
377377

378378
ResultVal<std::size_t> ArticFileBackend::Read(u64 offset, std::size_t length, u8* buffer) const {
379-
auto cache = cache_provider.ProvideCache(
380-
client, cache_provider.PathsToVector(archive.GetArchivePath(), file_path), true);
379+
auto cache = cache_provider->ProvideCache(
380+
client, cache_provider->PathsToVector(archive.GetArchivePath(), file_path), true);
381381

382382
if (cache != nullptr) {
383383
return cache->Read(file_handle, offset, length, buffer);
@@ -406,8 +406,8 @@ ResultVal<std::size_t> ArticFileBackend::Read(u64 offset, std::size_t length, u8
406406
ResultVal<std::size_t> ArticFileBackend::Write(u64 offset, std::size_t length, bool flush,
407407
bool update_timestamp, const u8* buffer) {
408408
u32 flags = (flush ? 1 : 0) | (update_timestamp ? (1 << 8) : 0);
409-
auto cache = cache_provider.ProvideCache(
410-
client, cache_provider.PathsToVector(archive.GetArchivePath(), file_path), true);
409+
auto cache = cache_provider->ProvideCache(
410+
client, cache_provider->PathsToVector(archive.GetArchivePath(), file_path), true);
411411
if (cache != nullptr) {
412412
return cache->Write(file_handle, offset, length, buffer, flags);
413413
} else {
@@ -434,8 +434,8 @@ ResultVal<std::size_t> ArticFileBackend::Write(u64 offset, std::size_t length, b
434434
}
435435

436436
u64 ArticFileBackend::GetSize() const {
437-
auto cache = cache_provider.ProvideCache(
438-
client, cache_provider.PathsToVector(archive.GetArchivePath(), file_path), true);
437+
auto cache = cache_provider->ProvideCache(
438+
client, cache_provider->PathsToVector(archive.GetArchivePath(), file_path), true);
439439
if (cache != nullptr) {
440440
auto res = cache->GetSize(file_handle);
441441
if (res.Failed())

src/core/file_sys/archive_artic.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ArticArchive : public ArchiveBackend {
2525
ArticCacheProvider& _cache_provider, const Path& _archive_path,
2626
bool _clear_cache_on_close)
2727
: client(_client), archive_handle(_archive_handle), report_artic_event(_report_artic_event),
28-
cache_provider(_cache_provider), archive_path(_archive_path),
28+
cache_provider(&_cache_provider), archive_path(_archive_path),
2929
clear_cache_on_close(_clear_cache_on_close) {}
3030
~ArticArchive() override;
3131

@@ -143,7 +143,7 @@ class ArticArchive : public ArchiveBackend {
143143
Core::PerfStats::PerfArticEventBits report_artic_event =
144144
Core::PerfStats::PerfArticEventBits::NONE;
145145
std::atomic<u32> open_files;
146-
ArticCacheProvider& cache_provider;
146+
ArticCacheProvider* cache_provider = nullptr;
147147
Path archive_path;
148148
bool clear_cache_on_close;
149149

@@ -161,7 +161,7 @@ class ArticFileBackend : public FileBackend {
161161
s32 _file_handle, ArticArchive& _archive,
162162
ArticCacheProvider& _cache_provider, const Path& _file_path)
163163
: client(_client), file_handle(_file_handle), archive(_archive),
164-
cache_provider(_cache_provider), file_path(_file_path) {}
164+
cache_provider(&_cache_provider), file_path(_file_path) {}
165165
~ArticFileBackend() override;
166166

167167
ResultVal<std::size_t> Read(u64 offset, std::size_t length, u8* buffer) const override;
@@ -182,8 +182,8 @@ class ArticFileBackend : public FileBackend {
182182
}
183183

184184
bool CacheReady(std::size_t file_offset, std::size_t length) override {
185-
auto cache = cache_provider.ProvideCache(
186-
client, cache_provider.PathsToVector(archive.GetArchivePath(), file_path), true);
185+
auto cache = cache_provider->ProvideCache(
186+
client, cache_provider->PathsToVector(archive.GetArchivePath(), file_path), true);
187187
if (cache == nullptr) {
188188
return false;
189189
}
@@ -197,7 +197,7 @@ class ArticFileBackend : public FileBackend {
197197
std::shared_ptr<Network::ArticBase::Client> client;
198198
s32 file_handle;
199199
ArticArchive& archive;
200-
ArticCacheProvider& cache_provider;
200+
ArticCacheProvider* cache_provider = nullptr;
201201
Path file_path;
202202

203203
template <class Archive>

src/network/artic_base/artic_base_client.cpp

+14-18
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ Client::~Client() {
141141
delete h;
142142
}
143143

144-
if (ping_thread) {
145-
ping_thread->join();
146-
delete ping_thread;
144+
if (ping_thread.joinable()) {
145+
ping_thread.join();
147146
}
148147

149148
SocketManager::DisableSockets();
@@ -292,7 +291,7 @@ bool Client::Connect() {
292291
std::this_thread::sleep_for(100ms);
293292
}
294293

295-
ping_thread = new std::thread(PingFunction, this);
294+
ping_thread = std::thread(&Client::PingFunction, this);
296295

297296
int i = 0;
298297
running_handlers = ports.size();
@@ -315,13 +314,10 @@ void Client::StopImpl(bool from_error) {
315314
SendSimpleRequest("STOP");
316315
}
317316

318-
if (ping_thread) {
319-
// Stop ping thread
320-
{
321-
std::scoped_lock l2(ping_cv_mutex);
322-
ping_run = false;
323-
ping_cv.notify_one();
324-
}
317+
if (ping_thread.joinable()) {
318+
std::scoped_lock l2(ping_cv_mutex);
319+
ping_run = false;
320+
ping_cv.notify_one();
325321
}
326322

327323
// Stop handlers
@@ -392,24 +388,24 @@ void Client::SignalCommunicationError() {
392388
communication_error_callback.first(communication_error_callback.second);
393389
}
394390

395-
void Client::PingFunction(Client* client) {
391+
void Client::PingFunction() {
396392
// Max silence time => 7 secs interval + 3 secs wait + 10 seconds timeout = 25 seconds
397-
while (client->ping_run) {
398-
std::chrono::time_point<std::chrono::steady_clock> last = client->last_sent_request;
393+
while (ping_run) {
394+
std::chrono::time_point<std::chrono::steady_clock> last = last_sent_request;
399395
if (std::chrono::steady_clock::now() - last > std::chrono::seconds(7)) {
400396
#ifdef DISABLE_PING_TIMEOUT
401397
client->last_sent_request = std::chrono::steady_clock::now();
402398
#else
403-
auto ping_reply = client->SendSimpleRequest("PING");
399+
auto ping_reply = SendSimpleRequest("PING");
404400
if (!ping_reply.has_value()) {
405-
client->SignalCommunicationError();
401+
SignalCommunicationError();
406402
break;
407403
}
408404
#endif // DISABLE_PING_TIMEOUT
409405
}
410406
{
411-
std::unique_lock<std::mutex> lk(client->ping_cv_mutex);
412-
client->ping_cv.wait_for(lk, std::chrono::seconds(3));
407+
std::unique_lock<std::mutex> lk(ping_cv_mutex);
408+
ping_cv.wait_for(lk, std::chrono::seconds(3));
413409
}
414410
}
415411
}

src/network/artic_base/artic_base_client.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ class Client {
118118
std::atomic<bool> stopped = false;
119119

120120
std::atomic<std::chrono::time_point<std::chrono::steady_clock>> last_sent_request;
121-
std::thread* ping_thread = nullptr;
121+
std::thread ping_thread;
122122
std::condition_variable ping_cv;
123123
std::mutex ping_cv_mutex;
124124
bool ping_run = true;
125125

126126
void StopImpl(bool from_error);
127127

128-
static void PingFunction(Client* client);
128+
void PingFunction();
129129

130130
static bool ConnectWithTimeout(SocketHolder sockFD, void* server_addr, size_t server_addr_len,
131131
int timeout_seconds);

0 commit comments

Comments
 (0)