Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1623 from davidgfnet/cleanup3
Browse files Browse the repository at this point in the history
Stop using std::mutex on Windows builds.
  • Loading branch information
davidgfnet authored May 26, 2019
2 parents 1cf45de + 3057bb6 commit f1b3678
Show file tree
Hide file tree
Showing 33 changed files with 342 additions and 321 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ if (${HOST_OS} EQUAL ${OS_WINDOWS})

list(APPEND osd_SRCS ${d_core}/windows/winmain.cpp)
list(APPEND osd_SRCS ${d_core}/windows/win_vmem.cpp)
list(APPEND osd_SRCS ${d_core}/oslib/windows/threading.cpp)
list(APPEND osd_SRCS ${d_aout}/audiobackend_directsound.cpp)


Expand All @@ -190,6 +191,7 @@ elseif (${HOST_OS} EQUAL ${OS_LINUX} OR ${HOST_OS} EQUAL ${OS_ANDROID})
list(APPEND osd_SRCS
${d_core}/linux/common.cpp
${d_core}/linux/context.cpp
${d_core}/linux/oslib/posix/threading.cpp
${d_core}/linux/nixprof/nixprof.cpp

${d_aout}/audiobackend_oss.cpp # add option
Expand Down
6 changes: 3 additions & 3 deletions core/core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ ifndef NO_NIXPROF
endif

ifdef FOR_ANDROID
RZDCY_MODULES += android/ deps/libandroid/ linux/
RZDCY_MODULES += android/ deps/libandroid/ linux/ oslib/posix/
endif

ifdef USE_SDL
RZDCY_MODULES += sdl/
endif

ifdef FOR_LINUX
RZDCY_MODULES += linux-dist/ linux/
RZDCY_MODULES += linux-dist/ linux/ oslib/posix/
endif

ifdef FOR_WINDOWS
RZDCY_MODULES += windows/
RZDCY_MODULES += windows/ oslib/windows/
endif

ifdef FOR_PANDORA
Expand Down
1 change: 1 addition & 0 deletions core/deps/coreio/coreio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <netdb.h>
#include <unistd.h>
#else
#include <windows.h>
#pragma comment (lib, "wsock32.lib")
#endif
#endif
Expand Down
8 changes: 4 additions & 4 deletions core/hw/gdrom/gdromv3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void FillReadBuffer()

if (count > 32)
{
hint = max(count - 32, (u32)32);
hint = std::max(count - 32, (u32)32);
count = 32;
}

Expand Down Expand Up @@ -981,7 +981,7 @@ static int getGDROMTicks()
if (SB_GDLEN - SB_GDLEND > 10240)
return 1000000; // Large transfers: GD-ROM transfer rate 1.8 MB/s
else
return min((u32)10240, SB_GDLEN - SB_GDLEND) * 2; // Small transfers: Max G1 bus rate: 50 MHz x 16 bits
return std::min((u32)10240, SB_GDLEN - SB_GDLEND) * 2; // Small transfers: Max G1 bus rate: 50 MHz x 16 bits
}
else
return 0;
Expand Down Expand Up @@ -1013,10 +1013,10 @@ int GDRomschd(int i, int c, int j)
if (read_params.remaining_sectors == 0)
{
//make sure we don't underrun the cache :)
len = min(len, read_buff.cache_size);
len = std::min(len, read_buff.cache_size);
}

len = min(len, (u32)10240);
len = std::min(len, (u32)10240);
// do we need to do this for GDROM DMA?
if(0x8201 != (dmaor &DMAOR_MASK))
{
Expand Down
6 changes: 3 additions & 3 deletions core/hw/maple/maple_devs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,18 +1125,18 @@ struct maple_sega_purupuru : maple_base
INC = 0;
bool CNT = VIBSET & 1;

float power = min((POW_POS + POW_NEG) / 7.0, 1.0);
float power = std::min((POW_POS + POW_NEG) / 7.0, 1.0);

u32 duration_ms;
if (FREQ > 0 && (!CNT || INC))
duration_ms = min((int)(1000 * (INC ? abs(INC) * max(POW_POS, POW_NEG) : 1) / FREQ), (int)AST_ms);
duration_ms = std::min((int)(1000 * (INC ? abs(INC) * std::max(POW_POS, POW_NEG) : 1) / FREQ), (int)AST_ms);
else
duration_ms = AST_ms;
float inclination;
if (INC == 0 || power == 0)
inclination = 0.0;
else
inclination = FREQ / (1000.0 * INC * max(POW_POS, POW_NEG));
inclination = FREQ / (1000.0 * INC * std::max(POW_POS, POW_NEG));
config->SetVibration(power, inclination, duration_ms);
}

Expand Down
11 changes: 6 additions & 5 deletions core/hw/modem/picoppp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern "C" {
#include "net_platform.h"

#include "types.h"
#include "oslib/threading.h"
#include "cfg/cfg.h"
#include "picoppp.h"

Expand Down Expand Up @@ -695,11 +696,11 @@ static void *pico_thread_func(void *)
{
pico_stack_init();
pico_stack_inited = true;
#if _WIN32
static WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)
printf("WSAStartup failed\n");
#endif
#if _WIN32
static WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)
printf("WSAStartup failed\n");
#endif
}

// PPP
Expand Down
4 changes: 2 additions & 2 deletions core/hw/naomi/gdcartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void GDCartridge::device_reset()
void *GDCartridge::GetDmaPtr(u32 &size)
{
dimm_cur_address = DmaOffset & (dimm_data_size-1);
size = min(size, dimm_data_size - dimm_cur_address);
size = std::min(size, dimm_data_size - dimm_cur_address);
return dimm_data + dimm_cur_address;
}

Expand All @@ -608,7 +608,7 @@ void GDCartridge::AdvancePtr(u32 size)
bool GDCartridge::Read(u32 offset, u32 size, void *dst)
{
u32 addr = offset & (dimm_data_size-1);
memcpy(dst, &dimm_data[addr], min(size, dimm_data_size - addr));
memcpy(dst, &dimm_data[addr], std::min(size, dimm_data_size - addr));
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion core/hw/naomi/m1cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class M1Cartridge : public NaomiCartridge
{
if (encryption)
{
size = min(size, (u32)sizeof(buffer));
size = std::min(size, (u32)sizeof(buffer));
return buffer;
}
else
Expand Down
6 changes: 3 additions & 3 deletions core/hw/naomi/m4cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void *M4Cartridge::GetDmaPtr(u32 &limit)
int fpr_num = m4id & 0x7f;

if (((rom_cur_address >> 26) & 0x07) < fpr_num) {
limit = min(limit, (u32)2);
limit = std::min(limit, (u32)2);
return &cfidata[rom_cur_address & 0xffff];
}
}
Expand All @@ -176,15 +176,15 @@ void *M4Cartridge::GetDmaPtr(u32 &limit)
}
if (encryption)
{
limit = min(limit, (u32)sizeof(buffer));
limit = std::min(limit, (u32)sizeof(buffer));
return buffer;

}
else
{
if ((DmaOffset & 0x1ffffffe) < RomSize)
{
limit = min(limit, RomSize - (DmaOffset & 0x1ffffffe));
limit = std::min(limit, RomSize - (DmaOffset & 0x1ffffffe));
return RomPtr + (DmaOffset & 0x1ffffffe);
}
else
Expand Down
2 changes: 2 additions & 0 deletions core/hw/naomi/naomi_cart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Cartridge *CurrentCartridge;
bool bios_loaded = false;

#if HOST_OS == OS_WINDOWS
#define NOMINMAX
#include <windows.h>
typedef HANDLE fd_t;
#define INVALID_FD INVALID_HANDLE_VALUE
#else
Expand Down
1 change: 1 addition & 0 deletions core/hw/pvr/ta_ctx.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "ta.h"
#include "pvr_regs.h"
#include "oslib/threading.h"

// helper for 32 byte aligned memory allocation
void* OS_aligned_malloc(size_t align, size_t size);
Expand Down
4 changes: 2 additions & 2 deletions core/hw/sh4/dyna/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,9 +1185,9 @@ void dec_DecodeBlock(RuntimeBlockInfo* rbi,u32 max_cycles)
}

//make sure we don't use wayy-too-many cycles
blk->guest_cycles=min(blk->guest_cycles,max_cycles);
blk->guest_cycles=std::min(blk->guest_cycles,max_cycles);
//make sure we don't use wayy-too-few cycles
blk->guest_cycles=max(1U,blk->guest_cycles);
blk->guest_cycles=std::max(1U,blk->guest_cycles);
blk=0;
}

Expand Down
2 changes: 1 addition & 1 deletion core/hw/sh4/interpr/sh4_fpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ sh4op(i1111_nnnn_0011_1101)
if (fpscr.PR == 0)
{
u32 n = GetN(op);
fpul = (u32)(s32)min(fr[n], 2147483520.0f); // IEEE 754: 0x4effffff
fpul = (u32)(s32)std::min(fr[n], 2147483520.0f); // IEEE 754: 0x4effffff

// Intel CPUs convert out of range float numbers to 0x80000000. Manually set the correct sign
if (fpul == 0x80000000)
Expand Down
2 changes: 1 addition & 1 deletion core/hw/sh4/sh4_sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void handle_cb(int id)
int re_sch=sch_list[id].cb(sch_list[id].tag,remain,jitter);

if (re_sch > 0)
sh4_sched_request(id, max(0, re_sch - jitter));
sh4_sched_request(id, std::max(0, re_sch - jitter));
}

void sh4_sched_tick(int cycles)
Expand Down
18 changes: 9 additions & 9 deletions core/input/gamepad_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern u8 rt[4], lt[4];
extern s8 joyx[4], joyy[4];

std::vector<std::shared_ptr<GamepadDevice>> GamepadDevice::_gamepads;
std::mutex GamepadDevice::_gamepads_mutex;
cMutex GamepadDevice::_gamepads_mutex;

bool GamepadDevice::gamepad_btn_input(u32 code, bool pressed)
{
Expand Down Expand Up @@ -238,21 +238,21 @@ bool GamepadDevice::find_mapping(const char *custom_mapping /* = NULL */)

int GamepadDevice::GetGamepadCount()
{
_gamepads_mutex.lock();
_gamepads_mutex.Lock();
int count = _gamepads.size();
_gamepads_mutex.unlock();
_gamepads_mutex.Unlock();
return count;
}

std::shared_ptr<GamepadDevice> GamepadDevice::GetGamepad(int index)
{
_gamepads_mutex.lock();
_gamepads_mutex.Lock();
std::shared_ptr<GamepadDevice> dev;
if (index >= 0 && index < _gamepads.size())
dev = _gamepads[index];
else
dev = NULL;
_gamepads_mutex.unlock();
_gamepads_mutex.Unlock();
return dev;
}

Expand Down Expand Up @@ -295,21 +295,21 @@ void GamepadDevice::Register(std::shared_ptr<GamepadDevice> gamepad)
if (maple_port != 12345)
gamepad->set_maple_port(maple_port);

_gamepads_mutex.lock();
_gamepads_mutex.Lock();
_gamepads.push_back(gamepad);
_gamepads_mutex.unlock();
_gamepads_mutex.Unlock();
}

void GamepadDevice::Unregister(std::shared_ptr<GamepadDevice> gamepad)
{
gamepad->save_mapping();
_gamepads_mutex.lock();
_gamepads_mutex.Lock();
for (auto it = _gamepads.begin(); it != _gamepads.end(); it++)
if (*it == gamepad) {
_gamepads.erase(it);
break;
}
_gamepads_mutex.unlock();
_gamepads_mutex.Unlock();
}

void GamepadDevice::SaveMaplePorts()
Expand Down
3 changes: 2 additions & 1 deletion core/input/gamepad_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <mutex>
#include "types.h"
#include "mapping.h"
#include "oslib/threading.h"

class GamepadDevice
{
Expand Down Expand Up @@ -89,5 +90,5 @@ class GamepadDevice
float _dead_zone = 0.1f;

static std::vector<std::shared_ptr<GamepadDevice>> _gamepads;
static std::mutex _gamepads_mutex;
static cMutex _gamepads_mutex;
};
16 changes: 2 additions & 14 deletions core/oslib/audiostream.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include <limits.h>
#include "cfg/cfg.h"
#include "oslib/threading.h"
#include "oslib/oslib.h"
#include "audiostream.h"
#ifndef _WIN32
#include <unistd.h>
#endif

struct SoundFrame { s16 l; s16 r; };

Expand All @@ -18,16 +16,6 @@ static unsigned int audiobackends_num_registered = 0;
static audiobackend_t **audiobackends = NULL;
static audiobackend_t *audiobackend_current = NULL;

u32 SmallCpuWait()
{
#if defined(_WIN32)
Sleep(1);
#else // if linux?
usleep(1000);
#endif
return 0;
}

static float InterpolateCatmull4pt3oX(float x0, float x1, float x2, float x3, float t) {
return 0.45f* ((2 * x1) + t * ((-x0 + x2) + t * ((2 * x0 - 5 * x1 + 4 * x2 - x3) + t * (-x0 + 3 * x1 - 3 * x2 + x3))));
}
Expand Down Expand Up @@ -133,7 +121,7 @@ class PullBuffer_t {
{
// infinite?
while (asRingFreeCount() < 512)
SmallCpuWait();
SleepMs(1);
}
else
{
Expand Down
Binary file removed core/oslib/logtest
Binary file not shown.
Loading

0 comments on commit f1b3678

Please sign in to comment.