2021-03-04 19:43:35 +00:00
|
|
|
// Copyright 2021 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-03-04 19:43:35 +00:00
|
|
|
|
|
|
|
#include "Common/SocketContext.h"
|
|
|
|
|
|
|
|
namespace Common
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
SocketContext::SocketContext()
|
|
|
|
{
|
2023-10-15 00:52:26 +00:00
|
|
|
std::lock_guard<std::mutex> g(s_lock);
|
|
|
|
if (s_num_objects == 0)
|
|
|
|
{
|
|
|
|
static_cast<void>(WSAStartup(MAKEWORD(2, 2), &s_data));
|
|
|
|
}
|
|
|
|
s_num_objects++;
|
2021-03-04 19:43:35 +00:00
|
|
|
}
|
|
|
|
SocketContext::~SocketContext()
|
|
|
|
{
|
2023-10-15 00:52:26 +00:00
|
|
|
std::lock_guard<std::mutex> g(s_lock);
|
|
|
|
s_num_objects--;
|
|
|
|
if (s_num_objects == 0)
|
|
|
|
{
|
|
|
|
WSACleanup();
|
|
|
|
}
|
2021-03-04 19:43:35 +00:00
|
|
|
}
|
2023-10-15 00:52:26 +00:00
|
|
|
|
|
|
|
std::mutex SocketContext::s_lock;
|
|
|
|
size_t SocketContext::s_num_objects = 0;
|
|
|
|
WSADATA SocketContext::s_data;
|
|
|
|
|
2021-03-04 19:43:35 +00:00
|
|
|
#else
|
|
|
|
SocketContext::SocketContext() = default;
|
|
|
|
SocketContext::~SocketContext() = default;
|
|
|
|
#endif
|
|
|
|
} // namespace Common
|