Files
parallel-gx1/Source/Core/Common/SocketContext.cpp
T
LibretroAdmin f7d5095739 Core, InputCommon, VideoCommon: remove the remaining locks
Every std::mutex, lock_guard, unique_lock, scoped_lock,
condition_variable, call_once and semaphore left in Source/Core is
replaced by a lock-free design:

- Input: the device list, control bindings, stick calibration and
  default device are published snapshots read under a quiesce; a
  rebind requested while another thread is rebinding is handed to
  that thread instead of waited for.
- WiimoteReal: the pool thread owns the slots and runs commands from
  an MPSC queue; the active Wiimotes are atomic slots.
- EXI/SI/IOS devices: socket and packet traffic goes through SPSC
  rings or MPSC handoffs owned by one thread; USB scanning publishes
  its device list, and libusb transfers drain through a CallGate.
- Memory cards: the flush thread applies change records queued by
  the CPU thread.
- Custom assets: loads are scheduled as a published batch with an
  atomic cursor, results come back over an MPSC stack, and busy
  assets are skipped and retried.
- D3D state and GL program caches use insert-only atomic maps
  (Common/AtomicHashMap.h).
- Logging appends with O_APPEND / FILE_APPEND_DATA; FatFs reports
  busy instead of waiting; per-socket WSAStartup/WSACleanup.

Deleted as unused by the libretro core: the profiler, the FIFO
recorder, the volume verifier, the touch InputOverrider and the
GameCube adapter's libusb path.
2026-11-05 20:11:31 +01:00

48 lines
1.4 KiB
C++

// Copyright 2021 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Common/SocketContext.h"
#ifdef _WIN32
#include "Common/Logging/Log.h"
#include "Common/Network.h"
#endif
namespace Common
{
#ifdef _WIN32
// Winsock counts WSAStartup calls itself and tears down at the matching last WSACleanup, so each
// context makes its own pair and nothing is shared between threads.
SocketContext::SocketContext()
{
WSADATA data;
const int ret = WSAStartup(MAKEWORD(2, 2), &data);
if (ret == 0)
{
INFO_LOG_FMT(COMMON, "WSAStartup succeeded, wVersion={}.{}, wHighVersion={}.{}",
int(LOBYTE(data.wVersion)), int(HIBYTE(data.wVersion)),
int(LOBYTE(data.wHighVersion)), int(HIBYTE(data.wHighVersion)));
m_started = true;
}
else
{
// The WSAStartup function directly returns the extended error code in the return value.
// A call to the WSAGetLastError function is not needed and should not be used.
//
// Source:
// https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastartup
ERROR_LOG_FMT(COMMON, "WSAStartup failed with error {}: {}", ret,
Common::DecodeNetworkError(ret));
}
}
SocketContext::~SocketContext()
{
if (m_started)
WSACleanup();
}
#else
SocketContext::SocketContext() = default;
SocketContext::~SocketContext() = default;
#endif
} // namespace Common