game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
image_service.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// core/services/image_service.cpp
4// ==============================================================================
5// Image service singleton implementation.
6//
7// Same thread-safety contract as NotificationService โ€” the static
8// shared_ptr is mutated by main.cpp at startup/shutdown while async
9// workers (image cache, thumbnail loaders) read it. Without the mutex,
10// the shared_ptr's two-word control-block update races with concurrent
11// reads; per [shared_ptr] ยง20.10.2.6 that's UB.
12// ==============================================================================
13
15
16#include <mutex>
17
18namespace core
19{
20
21namespace
22{
24}
25
26// Static member initialization โ€” only mutated under g_imageInstanceMutex.
27std::shared_ptr<IImageService> ImageService::instance_ = nullptr;
28
29void ImageService::setInstance(std::shared_ptr<IImageService> service)
30{
31 std::lock_guard<std::mutex> lock(g_imageInstanceMutex);
32 instance_ = std::move(service);
33}
34
35std::shared_ptr<IImageService> ImageService::instance()
36{
37 // shared_ptr return โ€” see notification_service.cpp for the same
38 // contract. Holds the service alive past any racing
39 // setInstance(nullptr) at shutdown.
40 std::lock_guard<std::mutex> lock(g_imageInstanceMutex);
41 return instance_;
42}
43
45{
46 std::lock_guard<std::mutex> lock(g_imageInstanceMutex);
47 return instance_ != nullptr;
48}
49
50} // namespace core
static bool hasInstance()
Check if an image service has been set.
static std::shared_ptr< IImageService > instance()
Get the image service instance.
static void setInstance(std::shared_ptr< IImageService > service)
Set the image service implementation.