Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Include/httpClient/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <mutex>

#include <httpClient/config.h>

Expand Down Expand Up @@ -494,3 +495,22 @@ enum class HCWebSocketCloseStatus : uint32_t
};

}

// On some platforms, std::mutex default construction creates named mutexes which have a low
// system-wide limit. DefaultUnnamedMutex forces unnamed mutex construction on affected platforms.
#if HC_PLATFORM == HC_PLATFORM_SONY_PLAYSTATION_5
class DefaultUnnamedMutex : public std::mutex
{
public:
DefaultUnnamedMutex() noexcept : std::mutex(nullptr) {}
~DefaultUnnamedMutex() noexcept = default;
DefaultUnnamedMutex(DefaultUnnamedMutex const&) = delete;
DefaultUnnamedMutex& operator=(DefaultUnnamedMutex const&) = delete;
void lock() { std::mutex::lock(); }
bool try_lock() { return std::mutex::try_lock(); }
void unlock() { std::mutex::unlock(); }
native_handle_type native_handle() { return std::mutex::native_handle(); }
};
#else
using DefaultUnnamedMutex = std::mutex;
#endif
2 changes: 1 addition & 1 deletion Source/Global/NetworkState.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class NetworkState
static void CALLBACK HttpProviderCleanupComplete(XAsyncBlock* async);
bool ScheduleCleanup();

std::mutex m_mutex;
DefaultUnnamedMutex m_mutex;

UniquePtr<IHttpProvider> m_httpProvider;

Expand Down
4 changes: 2 additions & 2 deletions Source/Global/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ HRESULT http_singleton::singleton_access(
_Out_ std::shared_ptr<http_singleton>& singleton
) noexcept
{
static std::mutex s_mutex;
static DefaultUnnamedMutex s_mutex;
static std::shared_ptr<http_singleton> s_singleton{ nullptr };
static uint8_t s_useCount{ 0 };

std::lock_guard<std::mutex> lock{ s_mutex };
std::lock_guard<DefaultUnnamedMutex> lock{ s_mutex };
switch (mode)
{
case singleton_access_mode::create:
Expand Down
2 changes: 1 addition & 1 deletion Source/Task/AsyncLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct AsyncState
XAsyncBlock providerAsyncBlock { };
XAsyncBlock* userAsyncBlock = nullptr;
XTaskQueueHandle queue = nullptr;
std::mutex waitMutex;
DefaultUnnamedMutex waitMutex;
std::condition_variable waitCondition;
bool waitSatisfied = false;

Expand Down
2 changes: 1 addition & 1 deletion Source/Task/AtomicVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class AtomicVector

private:

std::mutex m_lock;
DefaultUnnamedMutex m_lock;
std::vector<TElement> m_buffers[2];
std::atomic<uint32_t> m_indexAndRef { 0 };
};
10 changes: 5 additions & 5 deletions Source/Task/TaskQueueImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SubmitCallback
};

std::atomic<uint64_t> m_nextToken{ 0 };
std::mutex m_lock;
DefaultUnnamedMutex m_lock;
CallbackRegistration m_buffer1[SUBMIT_CALLBACK_MAX];
CallbackRegistration m_buffer2[SUBMIT_CALLBACK_MAX];
CallbackRegistration* m_buffers[2]= { m_buffer1, m_buffer2 };
Expand Down Expand Up @@ -149,7 +149,7 @@ class QueueWaitRegistry

std::atomic<uint64_t> m_nextToken{ 0 };
StaticArray<WaitRegistration, QUEUE_WAIT_MAX> m_callbacks;
std::mutex m_lock;
DefaultUnnamedMutex m_lock;
};

class TaskQueuePortImpl: public Api<ApiId::TaskQueuePort, ITaskQueuePort>
Expand Down Expand Up @@ -257,12 +257,12 @@ class TaskQueuePortImpl: public Api<ApiId::TaskQueuePort, ITaskQueuePort>
std::atomic<uint32_t> m_processingSerializedTbCallback{ 0 };
std::atomic<uint32_t> m_processingCallback{ 0 };
std::condition_variable m_processingCallbackCv;
std::mutex m_lock;
DefaultUnnamedMutex m_lock;
std::unique_ptr<LocklessQueue<QueueEntry>> m_queueList;
std::unique_ptr<LocklessQueue<QueueEntry>> m_pendingList;
std::unique_ptr<LocklessQueue<TerminationEntry*>> m_terminationList;
std::unique_ptr<LocklessQueue<TerminationEntry*>> m_pendingTerminationList;
std::mutex m_terminationLock;
DefaultUnnamedMutex m_terminationLock;
OS::WaitTimer m_timer;
OS::ThreadPool m_threadPool;
std::atomic<uint64_t> m_timerDue = { UINT64_MAX };
Expand Down Expand Up @@ -465,7 +465,7 @@ class TaskQueueImpl : public Api<ApiId::TaskQueue, ITaskQueue>
struct TerminationData
{
bool terminated;
std::mutex lock;
DefaultUnnamedMutex lock;
std::condition_variable cv;
};

Expand Down
4 changes: 2 additions & 2 deletions Source/Task/ThreadPool_stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ namespace OS

std::atomic<uint32_t> m_refs{ 1 };

std::mutex m_wakeLock;
DefaultUnnamedMutex m_wakeLock;
std::condition_variable m_wake;
uint32_t m_calls{ 0 };
bool m_terminate{ false };

std::mutex m_activeLock;
DefaultUnnamedMutex m_activeLock;
std::condition_variable m_active;
uint32_t m_activeCalls{ 0 };

Expand Down
4 changes: 2 additions & 2 deletions Source/Task/WaitTimer_stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace OS
TimerEntry const& Peek() const noexcept;
TimerEntry Pop() noexcept;

std::mutex m_mutex;
DefaultUnnamedMutex m_mutex;
std::condition_variable m_cv;
std::vector<TimerEntry> m_queue; // used as a heap
std::thread m_t;
Expand All @@ -64,7 +64,7 @@ namespace OS
namespace
{
std::shared_ptr<TimerQueue> g_timerQueue;
std::mutex g_timerQueueMutex;
DefaultUnnamedMutex g_timerQueueMutex;
}

TimerQueue::~TimerQueue()
Expand Down
2 changes: 1 addition & 1 deletion Source/WebSocket/hcwebsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class WebSocket : public std::enable_shared_from_this<WebSocket>
void* context{ nullptr };
};

std::mutex m_stateMutex;
DefaultUnnamedMutex m_stateMutex;
enum class State
{
Initial,
Expand Down
Loading