From b1d6f6d63f8294a3f62d7db6f9eea07da1d93664 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 27 Jan 2016 08:12:00 +0100 Subject: Cleanups and version bump --- src/emu/luaengine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/emu/luaengine.cpp') diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp index ba7cecc1c95..733c99537c7 100644 --- a/src/emu/luaengine.cpp +++ b/src/emu/luaengine.cpp @@ -863,9 +863,9 @@ void lua_engine::serve_lua() static void *serve_lua(void *param) { - lua_engine *engine = (lua_engine *)param; - engine->serve_lua(); - return NULL; + lua_engine *engine = (lua_engine *)param; + engine->serve_lua(); + return NULL; } //------------------------------------------------- -- cgit v1.2.3-70-g09d2 From 361d32d37ffbe133760fcbfa314f60ccd4a8e8a8 Mon Sep 17 00:00:00 2001 From: dankan1890 Date: Fri, 29 Jan 2016 00:43:18 +0100 Subject: Small code cleanup: - corealloc.h: added macro definition for global_alloc (nothrow) memory allocation. - textbuf.cpp / wavwrite.cpp: removed pointless cast. - debugcmd.cpp / luaengine.cpp / render.cpp: avoid strlen calls in a loop. - diimage.cpp: simplified "device_image_interface::set_image_filename" function. - miscmenu.cpp / selgame.h / video.cpp(h): replaced int with bool where applicable. - ui.cpp: removed unused code. --- src/emu/debug/debugcmd.cpp | 5 +++-- src/emu/debug/textbuf.cpp | 6 +++--- src/emu/diimage.cpp | 26 ++++++++++++-------------- src/emu/luaengine.cpp | 2 +- src/emu/render.cpp | 3 ++- src/emu/sound/wavwrite.cpp | 2 +- src/emu/ui/miscmenu.cpp | 6 +++--- src/emu/ui/selgame.h | 2 +- src/emu/ui/ui.cpp | 3 +-- src/emu/video.cpp | 2 +- src/emu/video.h | 2 +- src/lib/util/corealloc.h | 2 ++ 12 files changed, 31 insertions(+), 30 deletions(-) (limited to 'src/emu/luaengine.cpp') diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp index 4558413b2c3..7ad039806ea 100644 --- a/src/emu/debug/debugcmd.cpp +++ b/src/emu/debug/debugcmd.cpp @@ -2381,11 +2381,12 @@ static void execute_find(running_machine &machine, int ref, int params, const ch for (int i = 2; i < params; i++) { const char *pdata = param[i]; + size_t pdatalen = strlen(pdata) - 1; /* check for a string */ - if (pdata[0] == '"' && pdata[strlen(pdata) - 1] == '"') + if (pdata[0] == '"' && pdata[pdatalen] == '"') { - for (j = 1; j < strlen(pdata) - 1; j++) + for (j = 1; j < pdatalen; j++) { data_to_find[data_count] = pdata[j]; data_size[data_count++] = 1; diff --git a/src/emu/debug/textbuf.cpp b/src/emu/debug/textbuf.cpp index e7daf96571a..476fe6e1efc 100644 --- a/src/emu/debug/textbuf.cpp +++ b/src/emu/debug/textbuf.cpp @@ -86,12 +86,12 @@ text_buffer *text_buffer_alloc(UINT32 bytes, UINT32 lines) text_buffer *text; /* allocate memory for the text buffer object */ - text = (text_buffer *)global_alloc(text_buffer); + text = global_alloc_nothrow(text_buffer); if (!text) return nullptr; /* allocate memory for the buffer itself */ - text->buffer = (char *)global_alloc_array(char, bytes); + text->buffer = global_alloc_array_nothrow(char, bytes); if (!text->buffer) { global_free(text); @@ -99,7 +99,7 @@ text_buffer *text_buffer_alloc(UINT32 bytes, UINT32 lines) } /* allocate memory for the lines array */ - text->lineoffs = (INT32 *)global_alloc_array(INT32, lines); + text->lineoffs = global_alloc_array_nothrow(INT32, lines); if (!text->lineoffs) { global_free_array(text->buffer); diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp index 392da316dbb..d33bdb1d78b 100644 --- a/src/emu/diimage.cpp +++ b/src/emu/diimage.cpp @@ -161,29 +161,27 @@ image_error_t device_image_interface::set_image_filename(const char *filename) zippath_parent(m_working_directory, filename); m_basename.assign(m_image_name); - int loc1 = m_image_name.find_last_of('\\'); - int loc2 = m_image_name.find_last_of('/'); - int loc3 = m_image_name.find_last_of(':'); - int loc = MAX(loc1,MAX(loc2,loc3)); - if (loc!=-1) { + size_t loc1 = m_image_name.find_last_of('\\'); + size_t loc2 = m_image_name.find_last_of('/'); + size_t loc3 = m_image_name.find_last_of(':'); + size_t loc = MAX(loc1,MAX(loc2, loc3)); + if (loc != -1) { if (loc == loc3) { // temp workaround for softlists now that m_image_name contains the part name too (e.g. list:gamename:cart) m_basename = m_basename.substr(0, loc); - std::string tmpstr = std::string(m_basename); - int tmploc = tmpstr.find_last_of(':'); - m_basename = m_basename.substr(tmploc + 1,loc-tmploc); + size_t tmploc = m_basename.find_last_of(':'); + m_basename = m_basename.substr(tmploc + 1, loc - tmploc); } else - m_basename = m_basename.substr(loc + 1, m_basename.length() - loc); + m_basename = m_basename.substr(loc + 1); } - m_basename_noext = m_basename.assign(m_basename); + m_basename_noext = m_basename; m_filetype = ""; loc = m_basename_noext.find_last_of('.'); - if (loc!=-1) { - m_basename_noext = m_basename_noext.substr(0,loc); - m_filetype = m_basename.assign(m_basename); - m_filetype = m_filetype.substr(loc + 1, m_filetype.length() - loc); + if (loc != -1) { + m_basename_noext = m_basename_noext.substr(0, loc); + m_filetype = m_basename.substr(loc + 1); } return IMAGE_ERROR_SUCCESS; diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp index 733c99537c7..f1d12757ed7 100644 --- a/src/emu/luaengine.cpp +++ b/src/emu/luaengine.cpp @@ -1049,7 +1049,7 @@ void lua_engine::periodic_check() osd_lock_acquire(lock); if (msg.ready == 1) { lua_settop(m_lua_state, 0); - int status = luaL_loadbuffer(m_lua_state, msg.text.c_str(), strlen(msg.text.c_str()), "=stdin"); + int status = luaL_loadbuffer(m_lua_state, msg.text.c_str(), msg.text.length(), "=stdin"); if (incomplete(status)==0) /* cannot try to add lines? */ { if (status == LUA_OK) status = docall(0, LUA_MULTRET); diff --git a/src/emu/render.cpp b/src/emu/render.cpp index baa5aa8db1b..1f8e5d0be1f 100644 --- a/src/emu/render.cpp +++ b/src/emu/render.cpp @@ -1055,8 +1055,9 @@ int render_target::configured_view(const char *viewname, int targetindex, int nu if (strcmp(viewname, "auto") != 0) { // scan for a matching view name + size_t viewlen = strlen(viewname); for (view = view_by_index(viewindex = 0); view != nullptr; view = view_by_index(++viewindex)) - if (core_strnicmp(view->name(), viewname, strlen(viewname)) == 0) + if (core_strnicmp(view->name(), viewname, viewlen) == 0) break; } diff --git a/src/emu/sound/wavwrite.cpp b/src/emu/sound/wavwrite.cpp index 210b1bcc9d5..b535e91a675 100644 --- a/src/emu/sound/wavwrite.cpp +++ b/src/emu/sound/wavwrite.cpp @@ -18,7 +18,7 @@ wav_file *wav_open(const char *filename, int sample_rate, int channels) UINT16 align, temp16; /* allocate memory for the wav struct */ - wav = (wav_file *) global_alloc(wav_file); + wav = global_alloc(wav_file); if (!wav) return nullptr; diff --git a/src/emu/ui/miscmenu.cpp b/src/emu/ui/miscmenu.cpp index 1eaa9fe1366..9d96692a15a 100644 --- a/src/emu/ui/miscmenu.cpp +++ b/src/emu/ui/miscmenu.cpp @@ -434,9 +434,9 @@ void ui_menu_crosshair::populate() file_enumerator path(machine().options().crosshair_path()); const osd_directory_entry *dir; /* reset search flags */ - int using_default = false; - int finished = false; - int found = false; + bool using_default = false; + bool finished = false; + bool found = false; /* if we are using the default, then we just need to find the first in the list */ if (*(settings.name) == 0) diff --git a/src/emu/ui/selgame.h b/src/emu/ui/selgame.h index b5e6687c4f3..006f972b22b 100644 --- a/src/emu/ui/selgame.h +++ b/src/emu/ui/selgame.h @@ -31,7 +31,7 @@ private: // internal state enum { VISIBLE_GAMES_IN_LIST = 15 }; UINT8 m_error; - UINT8 m_rerandomize; + bool m_rerandomize; char m_search[40]; int m_matchlist[VISIBLE_GAMES_IN_LIST]; std::vector m_driverlist; diff --git a/src/emu/ui/ui.cpp b/src/emu/ui/ui.cpp index 3f2d252c107..e9a03243eae 100644 --- a/src/emu/ui/ui.cpp +++ b/src/emu/ui/ui.cpp @@ -236,7 +236,7 @@ ui_manager::ui_manager(running_machine &machine) m_handler_param = 0; m_single_step = false; m_showfps = false; - m_showfps_end = false; + m_showfps_end = 0; m_show_profiler = false; m_popup_text_end = 0; m_use_natural_keyboard = false; @@ -1503,7 +1503,6 @@ UINT32 ui_manager::handler_ingame(running_machine &machine, render_container *co // first draw the FPS counter if (machine.ui().show_fps_counter()) { - std::string tempstring; machine.ui().draw_text_full(container, machine.video().speed_text().c_str(), 0.0f, 0.0f, 1.0f, JUSTIFY_RIGHT, WRAP_WORD, DRAW_OPAQUE, ARGB_WHITE, ARGB_BLACK, nullptr, nullptr); } diff --git a/src/emu/video.cpp b/src/emu/video.cpp index 41fb5e1726e..d05a1b8327c 100644 --- a/src/emu/video.cpp +++ b/src/emu/video.cpp @@ -584,7 +584,7 @@ void video_manager::postload() // forward //------------------------------------------------- -inline int video_manager::effective_autoframeskip() const +inline bool video_manager::effective_autoframeskip() const { // if we're fast forwarding or paused, autoframeskip is disabled if (m_fastforward || machine().paused()) diff --git a/src/emu/video.h b/src/emu/video.h index 4938cf67f34..aef70a57f15 100644 --- a/src/emu/video.h +++ b/src/emu/video.h @@ -100,7 +100,7 @@ private: void postload(); // effective value helpers - int effective_autoframeskip() const; + bool effective_autoframeskip() const; int effective_frameskip() const; bool effective_throttle() const; diff --git a/src/lib/util/corealloc.h b/src/lib/util/corealloc.h index 4f0b961eb59..2c1df6dd46c 100644 --- a/src/lib/util/corealloc.h +++ b/src/lib/util/corealloc.h @@ -27,7 +27,9 @@ // global allocation helpers -- use these instead of new and delete #define global_alloc(_type) new _type +#define global_alloc_nothrow(_type) new (std::nothrow) _type #define global_alloc_array(_type, _num) new _type[_num] +#define global_alloc_array_nothrow(_type, _num) new (std::nothrow) _type[_num] #define global_free(_ptr) do { delete _ptr; } while (0) #define global_free_array(_ptr) do { delete[] _ptr; } while (0) -- cgit v1.2.3-70-g09d2 From 83e6738a0a26282606b21848a027963d63ef8f78 Mon Sep 17 00:00:00 2001 From: AJR Date: Sat, 30 Jan 2016 13:25:32 -0500 Subject: Add macros for alignment checking (nw) --- src/devices/bus/ti99_peb/bwg.cpp | 2 +- src/devices/bus/ti99_peb/hfdc.cpp | 4 +- src/devices/cpu/arm/arm.cpp | 6 +-- src/devices/cpu/asap/asap.cpp | 8 ++-- src/devices/cpu/dsp32/dsp32.cpp | 12 ++++-- src/devices/cpu/hd61700/hd61700.cpp | 4 +- src/devices/cpu/i386/i386priv.h | 20 ++++----- src/devices/cpu/i8089/i8089.cpp | 4 +- src/devices/cpu/i960/i960.cpp | 8 ++-- src/devices/cpu/m37710/m37710il.h | 8 ++-- src/devices/cpu/m68000/m68kcpu.cpp | 36 ++++++++-------- src/devices/cpu/m68000/m68kcpu.h | 4 +- src/devices/cpu/se3208/se3208.cpp | 32 +++++--------- src/devices/video/i82730.cpp | 4 +- src/emu/debug/debugcpu.cpp | 18 ++++---- src/emu/luaengine.cpp | 12 +++--- src/emu/memory.cpp | 86 ++++++++++++++++++------------------- src/emu/memory.h | 6 +++ src/mame/drivers/cobra.cpp | 4 +- src/mame/drivers/magictg.cpp | 4 +- src/mame/machine/n64.cpp | 2 +- src/mame/video/seibuspi.cpp | 6 +-- 22 files changed, 144 insertions(+), 146 deletions(-) (limited to 'src/emu/luaengine.cpp') diff --git a/src/devices/bus/ti99_peb/bwg.cpp b/src/devices/bus/ti99_peb/bwg.cpp index 4085dcfe230..4716ccedf8a 100644 --- a/src/devices/bus/ti99_peb/bwg.cpp +++ b/src/devices/bus/ti99_peb/bwg.cpp @@ -151,7 +151,7 @@ SETADDRESS_DBIN_MEMBER( snug_bwg_device::setaddress_dbin ) && ((state==ASSERT_LINE && ((m_address & 0x1ff8)==0x1ff0)) // read || (state==CLEAR_LINE && ((m_address & 0x1ff8)==0x1ff8))); // write - m_WDsel = m_WDsel0 && ((m_address & 1)==0); + m_WDsel = m_WDsel0 && WORD_ALIGNED(m_address); // Is the RTC selected on the card? (even addr) m_RTCsel = m_inDsrArea && m_rtc_enabled && ((m_address & 0x1fe1)==0x1fe0); diff --git a/src/devices/bus/ti99_peb/hfdc.cpp b/src/devices/bus/ti99_peb/hfdc.cpp index c3e4779c1ef..46ca7a1b819 100644 --- a/src/devices/bus/ti99_peb/hfdc.cpp +++ b/src/devices/bus/ti99_peb/hfdc.cpp @@ -232,7 +232,7 @@ READ8Z_MEMBER(myarc_hfdc_device::readz) if (m_dip == CLEAR_LINE) *value = m_buffer_ram[(m_ram_page[bank]<<10) | (m_address & 0x03ff)]; if (TRACE_RAM) { - if ((m_address & 1)==0) // only show even addresses with words + if (WORD_ALIGNED(m_address)) { int valword = (((*value) << 8) | m_buffer_ram[(m_ram_page[bank]<<10) | ((m_address+1) & 0x03ff)])&0xffff; logerror("%s: %04x[%02x] -> %04x\n", tag(), m_address & 0xffff, m_ram_page[bank], valword); @@ -246,7 +246,7 @@ READ8Z_MEMBER(myarc_hfdc_device::readz) *value = m_dsrrom[(m_rom_page << 12) | (m_address & 0x0fff)]; if (TRACE_ROM) { - if ((m_address & 1)==0) // only show even addresses with words + if (WORD_ALIGNED(m_address)) { int valword = (((*value) << 8) | m_dsrrom[(m_rom_page << 12) | ((m_address + 1) & 0x0fff)])&0xffff; logerror("%s: %04x[%02x] -> %04x\n", tag(), m_address & 0xffff, m_rom_page, valword); diff --git a/src/devices/cpu/arm/arm.cpp b/src/devices/cpu/arm/arm.cpp index 41724668f53..34dc1635639 100644 --- a/src/devices/cpu/arm/arm.cpp +++ b/src/devices/cpu/arm/arm.cpp @@ -259,7 +259,7 @@ void arm_cpu_device::cpu_write32( int addr, UINT32 data ) { /* Unaligned writes are treated as normal writes */ m_program->write_dword(addr&ADDRESS_MASK,data); - if (ARM_DEBUG_CORE && addr&3) logerror("%08x: Unaligned write %08x\n",R15,addr); + if (ARM_DEBUG_CORE && !DWORD_ALIGNED(addr)) logerror("%08x: Unaligned write %08x\n",R15,addr); } void arm_cpu_device::cpu_write8( int addr, UINT8 data ) @@ -272,9 +272,9 @@ UINT32 arm_cpu_device::cpu_read32( int addr ) UINT32 result = m_program->read_dword(addr&ADDRESS_MASK); /* Unaligned reads rotate the word, they never combine words */ - if (addr&3) + if (!DWORD_ALIGNED(addr)) { - if (ARM_DEBUG_CORE && addr&1) + if (ARM_DEBUG_CORE && !WORD_ALIGNED(addr)) logerror("%08x: Unaligned byte read %08x\n",R15,addr); if ((addr&3)==1) diff --git a/src/devices/cpu/asap/asap.cpp b/src/devices/cpu/asap/asap.cpp index c22d0cdcee2..b369ab6d07b 100644 --- a/src/devices/cpu/asap/asap.cpp +++ b/src/devices/cpu/asap/asap.cpp @@ -364,7 +364,7 @@ inline UINT8 asap_device::readbyte(offs_t address) inline UINT16 asap_device::readword(offs_t address) { // aligned reads are easy - if (!(address & 1)) + if (WORD_ALIGNED(address)) return m_program->read_word(address); // misaligned reads are tricky @@ -379,7 +379,7 @@ inline UINT16 asap_device::readword(offs_t address) inline UINT32 asap_device::readlong(offs_t address) { // aligned reads are easy - if (!(address & 3)) + if (DWORD_ALIGNED(address)) return m_program->read_dword(address); // misaligned reads are tricky @@ -405,7 +405,7 @@ inline void asap_device::writebyte(offs_t address, UINT8 data) inline void asap_device::writeword(offs_t address, UINT16 data) { // aligned writes are easy - if (!(address & 1)) + if (WORD_ALIGNED(address)) { m_program->write_word(address, data); return; @@ -429,7 +429,7 @@ inline void asap_device::writeword(offs_t address, UINT16 data) inline void asap_device::writelong(offs_t address, UINT32 data) { // aligned writes are easy - if (!(address & 3)) + if (DWORD_ALIGNED(address)) { m_program->write_dword(address, data); return; diff --git a/src/devices/cpu/dsp32/dsp32.cpp b/src/devices/cpu/dsp32/dsp32.cpp index f060e81d13c..98640f7d1b4 100644 --- a/src/devices/cpu/dsp32/dsp32.cpp +++ b/src/devices/cpu/dsp32/dsp32.cpp @@ -452,7 +452,8 @@ inline void dsp32c_device::WBYTE(offs_t addr, UINT8 data) inline UINT16 dsp32c_device::RWORD(offs_t addr) { #if DETECT_MISALIGNED_MEMORY - if (addr & 1) fprintf(stderr, "Unaligned word read @ %06X, PC=%06X\n", addr, PC); + if (!WORD_ALIGNED(addr)) + osd_printf_error("Unaligned word read @ %06X, PC=%06X\n", addr, PC); #endif return m_program->read_word(addr); } @@ -460,7 +461,8 @@ inline UINT16 dsp32c_device::RWORD(offs_t addr) inline UINT32 dsp32c_device::RLONG(offs_t addr) { #if DETECT_MISALIGNED_MEMORY - if (addr & 3) fprintf(stderr, "Unaligned long read @ %06X, PC=%06X\n", addr, PC); + if (!DWORD_ALIGNED(addr)) + osd_printf_error("Unaligned long read @ %06X, PC=%06X\n", addr, PC); #endif return m_program->read_dword(addr); } @@ -468,7 +470,8 @@ inline UINT32 dsp32c_device::RLONG(offs_t addr) inline void dsp32c_device::WWORD(offs_t addr, UINT16 data) { #if DETECT_MISALIGNED_MEMORY - if (addr & 1) fprintf(stderr, "Unaligned word write @ %06X, PC=%06X\n", addr, PC); + if (!WORD_ALIGNED(addr)) + osd_printf_error("Unaligned word write @ %06X, PC=%06X\n", addr, PC); #endif m_program->write_word(addr, data); } @@ -476,7 +479,8 @@ inline void dsp32c_device::WWORD(offs_t addr, UINT16 data) inline void dsp32c_device::WLONG(offs_t addr, UINT32 data) { #if DETECT_MISALIGNED_MEMORY - if (addr & 3) fprintf(stderr, "Unaligned long write @ %06X, PC=%06X\n", addr, PC); + if (!DWORD_ALIGNED(addr)) + osd_printf_error("Unaligned long write @ %06X, PC=%06X\n", addr, PC); #endif m_program->write_dword(addr, data); } diff --git a/src/devices/cpu/hd61700/hd61700.cpp b/src/devices/cpu/hd61700/hd61700.cpp index c786c7235ba..4e8d2c6590d 100644 --- a/src/devices/cpu/hd61700/hd61700.cpp +++ b/src/devices/cpu/hd61700/hd61700.cpp @@ -2654,7 +2654,7 @@ void hd61700_cpu_device::execute_run() } //if is in the internal ROM align the pc - if ((m_fetch_addr&1) && m_pc < INT_ROM) + if (!WORD_ALIGNED(m_fetch_addr) && m_pc < INT_ROM) set_pc((m_fetch_addr+1)>>1); m_icount -= 3; @@ -2871,7 +2871,7 @@ inline void hd61700_cpu_device::check_optional_jr(UINT8 arg) { if (arg & 0x80) { - if (m_pc < INT_ROM && !(m_fetch_addr&1)) read_op(); + if (m_pc < INT_ROM && WORD_ALIGNED(m_fetch_addr)) read_op(); UINT8 arg1 = read_op(); diff --git a/src/devices/cpu/i386/i386priv.h b/src/devices/cpu/i386/i386priv.h index 9913d851fa2..fa7ae0d4945 100644 --- a/src/devices/cpu/i386/i386priv.h +++ b/src/devices/cpu/i386/i386priv.h @@ -557,7 +557,7 @@ UINT16 i386_device::FETCH16() UINT16 value; UINT32 address = m_pc, error; - if( address & 0x1 ) { /* Unaligned read */ + if( !WORD_ALIGNED(address) ) { /* Unaligned read */ value = (FETCH() << 0); value |= (FETCH() << 8); } else { @@ -575,7 +575,7 @@ UINT32 i386_device::FETCH32() UINT32 value; UINT32 address = m_pc, error; - if( m_pc & 0x3 ) { /* Unaligned read */ + if( !DWORD_ALIGNED(m_pc) ) { /* Unaligned read */ value = (FETCH() << 0); value |= (FETCH() << 8); value |= (FETCH() << 16); @@ -607,7 +607,7 @@ UINT16 i386_device::READ16(UINT32 ea) UINT16 value; UINT32 address = ea, error; - if( ea & 0x1 ) { /* Unaligned read */ + if( !WORD_ALIGNED(ea) ) { /* Unaligned read */ value = (READ8( address+0 ) << 0); value |= (READ8( address+1 ) << 8); } else { @@ -624,7 +624,7 @@ UINT32 i386_device::READ32(UINT32 ea) UINT32 value; UINT32 address = ea, error; - if( ea & 0x3 ) { /* Unaligned read */ + if( !DWORD_ALIGNED(ea) ) { /* Unaligned read */ value = (READ8( address+0 ) << 0); value |= (READ8( address+1 ) << 8); value |= (READ8( address+2 ) << 16), @@ -644,7 +644,7 @@ UINT64 i386_device::READ64(UINT32 ea) UINT64 value; UINT32 address = ea, error; - if( ea & 0x7 ) { /* Unaligned read */ + if( !QWORD_ALIGNED(ea) ) { /* Unaligned read */ value = (((UINT64) READ8( address+0 )) << 0); value |= (((UINT64) READ8( address+1 )) << 8); value |= (((UINT64) READ8( address+2 )) << 16); @@ -678,7 +678,7 @@ UINT16 i386_device::READ16PL0(UINT32 ea) UINT16 value; UINT32 address = ea, error; - if( ea & 0x1 ) { /* Unaligned read */ + if( !WORD_ALIGNED(ea) ) { /* Unaligned read */ value = (READ8PL0( address+0 ) << 0); value |= (READ8PL0( address+1 ) << 8); } else { @@ -696,7 +696,7 @@ UINT32 i386_device::READ32PL0(UINT32 ea) UINT32 value; UINT32 address = ea, error; - if( ea & 0x3 ) { /* Unaligned read */ + if( !DWORD_ALIGNED(ea) ) { /* Unaligned read */ value = (READ8PL0( address+0 ) << 0); value |= (READ8PL0( address+1 ) << 8); value |= (READ8PL0( address+2 ) << 16); @@ -732,7 +732,7 @@ void i386_device::WRITE16(UINT32 ea, UINT16 value) { UINT32 address = ea, error; - if( ea & 0x1 ) { /* Unaligned write */ + if( !WORD_ALIGNED(ea) ) { /* Unaligned write */ WRITE8( address+0, value & 0xff ); WRITE8( address+1, (value >> 8) & 0xff ); } else { @@ -747,7 +747,7 @@ void i386_device::WRITE32(UINT32 ea, UINT32 value) { UINT32 address = ea, error; - if( ea & 0x3 ) { /* Unaligned write */ + if( !DWORD_ALIGNED(ea) ) { /* Unaligned write */ WRITE8( address+0, value & 0xff ); WRITE8( address+1, (value >> 8) & 0xff ); WRITE8( address+2, (value >> 16) & 0xff ); @@ -765,7 +765,7 @@ void i386_device::WRITE64(UINT32 ea, UINT64 value) { UINT32 address = ea, error; - if( ea & 0x7 ) { /* Unaligned write */ + if( !QWORD_ALIGNED(ea) ) { /* Unaligned write */ WRITE8( address+0, value & 0xff ); WRITE8( address+1, (value >> 8) & 0xff ); WRITE8( address+2, (value >> 16) & 0xff ); diff --git a/src/devices/cpu/i8089/i8089.cpp b/src/devices/cpu/i8089/i8089.cpp index 22494cfdd2f..ade9e4f768b 100644 --- a/src/devices/cpu/i8089/i8089.cpp +++ b/src/devices/cpu/i8089/i8089.cpp @@ -289,7 +289,7 @@ UINT16 i8089_device::read_word(bool space, offs_t address) UINT16 data; address_space *aspace = (space ? m_io : m_mem); - if (sysbus_width() && !(address & 1)) + if (sysbus_width() && WORD_ALIGNED(address)) { data = aspace->read_word(address); } @@ -311,7 +311,7 @@ void i8089_device::write_word(bool space, offs_t address, UINT16 data) { address_space *aspace = (space ? m_io : m_mem); - if (sysbus_width() && !(address & 1)) + if (sysbus_width() && WORD_ALIGNED(address)) { aspace->write_word(address, data); } diff --git a/src/devices/cpu/i960/i960.cpp b/src/devices/cpu/i960/i960.cpp index 224b844387c..f754445379b 100644 --- a/src/devices/cpu/i960/i960.cpp +++ b/src/devices/cpu/i960/i960.cpp @@ -26,7 +26,7 @@ i960_cpu_device::i960_cpu_device(const machine_config &mconfig, const char *tag, UINT32 i960_cpu_device::i960_read_dword_unaligned(UINT32 address) { - if (address & 3) + if (!DWORD_ALIGNED(address)) return m_program->read_byte(address) | m_program->read_byte(address+1)<<8 | m_program->read_byte(address+2)<<16 | m_program->read_byte(address+3)<<24; else return m_program->read_dword(address); @@ -34,7 +34,7 @@ UINT32 i960_cpu_device::i960_read_dword_unaligned(UINT32 address) UINT16 i960_cpu_device::i960_read_word_unaligned(UINT32 address) { - if (address & 1) + if (!WORD_ALIGNED(address)) return m_program->read_byte(address) | m_program->read_byte(address+1)<<8; else return m_program->read_word(address); @@ -42,7 +42,7 @@ UINT16 i960_cpu_device::i960_read_word_unaligned(UINT32 address) void i960_cpu_device::i960_write_dword_unaligned(UINT32 address, UINT32 data) { - if (address & 3) + if (!DWORD_ALIGNED(address)) { m_program->write_byte(address, data & 0xff); m_program->write_byte(address+1, (data>>8)&0xff); @@ -57,7 +57,7 @@ void i960_cpu_device::i960_write_dword_unaligned(UINT32 address, UINT32 data) void i960_cpu_device::i960_write_word_unaligned(UINT32 address, UINT16 data) { - if (address & 1) + if (!WORD_ALIGNED(address)) { m_program->write_byte(address, data & 0xff); m_program->write_byte(address+1, (data>>8)&0xff); diff --git a/src/devices/cpu/m37710/m37710il.h b/src/devices/cpu/m37710/m37710il.h index ffc1aed0a7a..eb79f0fddd6 100644 --- a/src/devices/cpu/m37710/m37710il.h +++ b/src/devices/cpu/m37710/m37710il.h @@ -42,7 +42,7 @@ inline UINT32 m37710_cpu_device::m37710i_read_16_normal(UINT32 address) inline UINT32 m37710_cpu_device::m37710i_read_16_immediate(UINT32 address) { - if (address & 1) + if (!WORD_ALIGNED(address)) return m37710_read_8_immediate(address) | (m37710_read_8_immediate(address+1)<<8); else return m37710_read_16_immediate(address); @@ -65,7 +65,7 @@ inline void m37710_cpu_device::m37710i_write_16_direct(UINT32 address, UINT32 va inline UINT32 m37710_cpu_device::m37710i_read_24_normal(UINT32 address) { - if (address & 1) + if (!WORD_ALIGNED(address)) return m37710_read_8(address) | (m37710_read_16(address+1)<<8); else return m37710_read_16(address) | (m37710_read_8(address+2)<<16); @@ -73,7 +73,7 @@ inline UINT32 m37710_cpu_device::m37710i_read_24_normal(UINT32 address) inline UINT32 m37710_cpu_device::m37710i_read_24_immediate(UINT32 address) { - if (address & 1) + if (!WORD_ALIGNED(address)) return m37710_read_8_immediate(address) | (m37710_read_16_immediate(address+1)<<8); else return m37710_read_16_immediate(address) | (m37710_read_8_immediate(address+2)<<16); @@ -81,7 +81,7 @@ inline UINT32 m37710_cpu_device::m37710i_read_24_immediate(UINT32 address) inline UINT32 m37710_cpu_device::m37710i_read_24_direct(UINT32 address) { - if (address & 1) + if (!WORD_ALIGNED(address)) return m37710_read_8(address) | (m37710_read_16(address+1)<<8); else return m37710_read_16(address) | (m37710_read_8(address+2)<<16); diff --git a/src/devices/cpu/m68000/m68kcpu.cpp b/src/devices/cpu/m68000/m68kcpu.cpp index dc7e0b14a6f..aaa1db079cf 100644 --- a/src/devices/cpu/m68000/m68kcpu.cpp +++ b/src/devices/cpu/m68000/m68kcpu.cpp @@ -1383,7 +1383,7 @@ UINT16 m68000_base_device::readword_d32_mmu(offs_t address) UINT32 address0 = pmmu_translate_addr(this, address); if (mmu_tmp_buserror_occurred) { return ~0; - } else if (!(address & 1)) { + } else if (WORD_ALIGNED(address)) { return m_space->read_word(address0); } else { UINT32 address1 = pmmu_translate_addr(this, address + 1); @@ -1396,7 +1396,7 @@ UINT16 m68000_base_device::readword_d32_mmu(offs_t address) } } - if (!(address & 1)) + if (WORD_ALIGNED(address)) return m_space->read_word(address); result = m_space->read_byte(address) << 8; return result | m_space->read_byte(address + 1); @@ -1410,7 +1410,7 @@ void m68000_base_device::writeword_d32_mmu(offs_t address, UINT16 data) UINT32 address0 = pmmu_translate_addr(this, address); if (mmu_tmp_buserror_occurred) { return; - } else if (!(address & 1)) { + } else if (WORD_ALIGNED(address)) { m_space->write_word(address0, data); return; } else { @@ -1425,7 +1425,7 @@ void m68000_base_device::writeword_d32_mmu(offs_t address, UINT16 data) } } - if (!(address & 1)) + if (WORD_ALIGNED(address)) { m_space->write_word(address, data); return; @@ -1447,13 +1447,13 @@ UINT32 m68000_base_device::readlong_d32_mmu(offs_t address) } else if ((address +3) & 0xfc) { // not at page boundary; use default code address = address0; - } else if (!(address & 3)) { // 0 + } else if (DWORD_ALIGNED(address)) { // 0 return m_space->read_dword(address0); } else { UINT32 address2 = pmmu_translate_addr(this, address+2); if (mmu_tmp_buserror_occurred) { return ~0; - } else if (!(address & 1)) { // 2 + } else if (WORD_ALIGNED(address)) { // 2 result = m_space->read_word(address0) << 16; return result | m_space->read_word(address2); } else { @@ -1470,9 +1470,9 @@ UINT32 m68000_base_device::readlong_d32_mmu(offs_t address) } } - if (!(address & 3)) + if (DWORD_ALIGNED(address)) return m_space->read_dword(address); - else if (!(address & 1)) + else if (WORD_ALIGNED(address)) { result = m_space->read_word(address) << 16; return result | m_space->read_word(address + 2); @@ -1493,14 +1493,14 @@ void m68000_base_device::writelong_d32_mmu(offs_t address, UINT32 data) } else if ((address +3) & 0xfc) { // not at page boundary; use default code address = address0; - } else if (!(address & 3)) { // 0 + } else if (DWORD_ALIGNED(address)) { // 0 m_space->write_dword(address0, data); return; } else { UINT32 address2 = pmmu_translate_addr(this, address+2); if (mmu_tmp_buserror_occurred) { return; - } else if (!(address & 1)) { // 2 + } else if (WORD_ALIGNED(address)) { // 2 m_space->write_word(address0, data >> 16); m_space->write_word(address2, data); return; @@ -1519,12 +1519,12 @@ void m68000_base_device::writelong_d32_mmu(offs_t address, UINT32 data) } } - if (!(address & 3)) + if (DWORD_ALIGNED(address)) { m_space->write_dword(address, data); return; } - else if (!(address & 1)) + else if (WORD_ALIGNED(address)) { m_space->write_word(address, data >> 16); m_space->write_word(address + 2, data); @@ -1594,7 +1594,7 @@ UINT16 m68000_base_device::readword_d32_hmmu(offs_t address) address = hmmu_translate_addr(this, address); } - if (!(address & 1)) + if (WORD_ALIGNED(address)) return m_space->read_word(address); result = m_space->read_byte(address) << 8; return result | m_space->read_byte(address + 1); @@ -1608,7 +1608,7 @@ void m68000_base_device::writeword_d32_hmmu(offs_t address, UINT16 data) address = hmmu_translate_addr(this, address); } - if (!(address & 1)) + if (WORD_ALIGNED(address)) { m_space->write_word(address, data); return; @@ -1627,9 +1627,9 @@ UINT32 m68000_base_device::readlong_d32_hmmu(offs_t address) address = hmmu_translate_addr(this, address); } - if (!(address & 3)) + if (DWORD_ALIGNED(address)) return m_space->read_dword(address); - else if (!(address & 1)) + else if (WORD_ALIGNED(address)) { result = m_space->read_word(address) << 16; return result | m_space->read_word(address + 2); @@ -1647,12 +1647,12 @@ void m68000_base_device::writelong_d32_hmmu(offs_t address, UINT32 data) address = hmmu_translate_addr(this, address); } - if (!(address & 3)) + if (DWORD_ALIGNED(address)) { m_space->write_dword(address, data); return; } - else if (!(address & 1)) + else if (WORD_ALIGNED(address)) { m_space->write_word(address, data >> 16); m_space->write_word(address + 2, data); diff --git a/src/devices/cpu/m68000/m68kcpu.h b/src/devices/cpu/m68000/m68kcpu.h index 5cec889e002..7860298988f 100644 --- a/src/devices/cpu/m68000/m68kcpu.h +++ b/src/devices/cpu/m68000/m68kcpu.h @@ -626,7 +626,7 @@ static inline unsigned int m68k_read_pcrelative_8(m68000_base_device *m68k, unsi static inline unsigned int m68k_read_pcrelative_16(m68000_base_device *m68k, unsigned int address) { - if(address & 1) + if (!WORD_ALIGNED(address)) return (m68k->readimm16(address-1) << 8) | (m68k->readimm16(address+1) >> 8); @@ -638,7 +638,7 @@ static inline unsigned int m68k_read_pcrelative_16(m68000_base_device *m68k, uns static inline unsigned int m68k_read_pcrelative_32(m68000_base_device *m68k, unsigned int address) { - if(address & 1) + if (!WORD_ALIGNED(address)) return (m68k->readimm16(address-1) << 24) | (m68k->readimm16(address+1) << 8) | diff --git a/src/devices/cpu/se3208/se3208.cpp b/src/devices/cpu/se3208/se3208.cpp index 011cc103909..45c4c38cc86 100644 --- a/src/devices/cpu/se3208/se3208.cpp +++ b/src/devices/cpu/se3208/se3208.cpp @@ -54,27 +54,22 @@ se3208_device::se3208_device(const machine_config &mconfig, const char *tag, dev UINT32 se3208_device::read_dword_unaligned(address_space &space, UINT32 address) { - switch (address & 3) - { - case 0: + if (DWORD_ALIGNED(address)) return space.read_dword(address); - case 1: - case 2: - case 3: - printf("%08x: dword READ unaligned %08x\n", m_PC, address); + else + { + osd_printf_debug("%08x: dword READ unaligned %08x\n", m_PC, address); #if ALLOW_UNALIGNED_DWORD_ACCESS return space.read_byte(address) | space.read_byte(address + 1) << 8 | space.read_byte(address + 2) << 16 | space.read_byte(address + 3) << 24; #else return 0; #endif } - - return 0; } UINT16 se3208_device::read_word_unaligned(address_space &space, UINT32 address) { - if (address & 1) + if (!WORD_ALIGNED(address)) return space.read_byte(address) | space.read_byte(address+1)<<8; else return space.read_word(address); @@ -82,31 +77,24 @@ UINT16 se3208_device::read_word_unaligned(address_space &space, UINT32 address) void se3208_device::write_dword_unaligned(address_space &space, UINT32 address, UINT32 data) { - switch (address & 3) - { - case 0: + if (DWORD_ALIGNED(address)) space.write_dword(address, data); - break; - - case 1: - case 2: - case 3: + else + { #if ALLOW_UNALIGNED_DWORD_ACCESS space.write_byte(address, data & 0xff); space.write_byte(address + 1, (data >> 8) & 0xff); space.write_byte(address + 2, (data >> 16) & 0xff); space.write_byte(address + 3, (data >> 24) & 0xff); #endif - printf("%08x: dword WRITE unaligned %08x\n", m_PC, address); - - break; + osd_printf_debug("%08x: dword WRITE unaligned %08x\n", m_PC, address); } } void se3208_device::write_word_unaligned(address_space &space, UINT32 address, UINT16 data) { - if (address & 1) + if (!WORD_ALIGNED(address)) { space.write_byte(address, data & 0xff); space.write_byte(address+1, (data>>8)&0xff); diff --git a/src/devices/video/i82730.cpp b/src/devices/video/i82730.cpp index d344c7006ef..8cd78863df3 100644 --- a/src/devices/video/i82730.cpp +++ b/src/devices/video/i82730.cpp @@ -128,7 +128,7 @@ UINT16 i82730_device::read_word(offs_t address) { UINT16 data; - if (sysbus_16bit() && !(address & 1)) + if (sysbus_16bit() && WORD_ALIGNED(address)) { data = m_program->read_word(address); } @@ -148,7 +148,7 @@ void i82730_device::write_byte(offs_t address, UINT8 data) void i82730_device::write_word(offs_t address, UINT16 data) { - if (sysbus_16bit() && !(address & 1)) + if (sysbus_16bit() && WORD_ALIGNED(address)) { m_program->write_word(address, data); } diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index 82c175251fe..293657b1f45 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -486,7 +486,7 @@ UINT16 debug_read_word(address_space &space, offs_t address, int apply_translati address &= space.logbytemask(); /* if this is misaligned read, or if there are no word readers, just read two bytes */ - if ((address & 1) != 0) + if (!WORD_ALIGNED(address)) { UINT8 byte0 = debug_read_byte(space, address + 0, apply_translation); UINT8 byte1 = debug_read_byte(space, address + 1, apply_translation); @@ -540,7 +540,7 @@ UINT32 debug_read_dword(address_space &space, offs_t address, int apply_translat address &= space.logbytemask(); /* if this is misaligned read, or if there are no dword readers, just read two words */ - if ((address & 3) != 0) + if (!DWORD_ALIGNED(address)) { UINT16 word0 = debug_read_word(space, address + 0, apply_translation); UINT16 word1 = debug_read_word(space, address + 2, apply_translation); @@ -594,7 +594,7 @@ UINT64 debug_read_qword(address_space &space, offs_t address, int apply_translat address &= space.logbytemask(); /* if this is misaligned read, or if there are no qword readers, just read two dwords */ - if ((address & 7) != 0) + if (!QWORD_ALIGNED(address)) { UINT32 dword0 = debug_read_dword(space, address + 0, apply_translation); UINT32 dword1 = debug_read_dword(space, address + 4, apply_translation); @@ -699,7 +699,7 @@ void debug_write_word(address_space &space, offs_t address, UINT16 data, int app address &= space.logbytemask(); /* if this is a misaligned write, or if there are no word writers, just read two bytes */ - if ((address & 1) != 0) + if (!WORD_ALIGNED(address)) { if (space.endianness() == ENDIANNESS_LITTLE) { @@ -751,7 +751,7 @@ void debug_write_dword(address_space &space, offs_t address, UINT32 data, int ap address &= space.logbytemask(); /* if this is a misaligned write, or if there are no dword writers, just read two words */ - if ((address & 3) != 0) + if (!DWORD_ALIGNED(address)) { if (space.endianness() == ENDIANNESS_LITTLE) { @@ -803,7 +803,7 @@ void debug_write_qword(address_space &space, offs_t address, UINT64 data, int ap address &= space.logbytemask(); /* if this is a misaligned write, or if there are no qword writers, just read two dwords */ - if ((address & 7) != 0) + if (!QWORD_ALIGNED(address)) { if (space.endianness() == ENDIANNESS_LITTLE) { @@ -966,7 +966,7 @@ UINT64 debug_read_opcode(address_space &space, offs_t address, int size) case 2: result = space.direct().read_word(address & ~1, addrxor); - if ((address & 1) != 0) + if (!WORD_ALIGNED(address)) { result2 = space.direct().read_word((address & ~1) + 2, addrxor); if (space.endianness() == ENDIANNESS_LITTLE) @@ -979,7 +979,7 @@ UINT64 debug_read_opcode(address_space &space, offs_t address, int size) case 4: result = space.direct().read_dword(address & ~3, addrxor); - if ((address & 3) != 0) + if (!DWORD_ALIGNED(address)) { result2 = space.direct().read_dword((address & ~3) + 4, addrxor); if (space.endianness() == ENDIANNESS_LITTLE) @@ -992,7 +992,7 @@ UINT64 debug_read_opcode(address_space &space, offs_t address, int size) case 8: result = space.direct().read_qword(address & ~7, addrxor); - if ((address & 7) != 0) + if (!QWORD_ALIGNED(address)) { result2 = space.direct().read_qword((address & ~7) + 8, addrxor); if (space.endianness() == ENDIANNESS_LITTLE) diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp index f1d12757ed7..f8ec7023bc6 100644 --- a/src/emu/luaengine.cpp +++ b/src/emu/luaengine.cpp @@ -505,21 +505,21 @@ int lua_engine::lua_addr_space::l_mem_read(lua_State *L) mem_content = sp.read_byte(address); break; case 16: - if ((address & 1) == 0) { + if (WORD_ALIGNED(address)) { mem_content = sp.read_word(address); } else { mem_content = sp.read_word_unaligned(address); } break; case 32: - if ((address & 3) == 0) { + if (DWORD_ALIGNED(address)) { mem_content = sp.read_dword(address); } else { mem_content = sp.read_dword_unaligned(address); } break; case 64: - if ((address & 7) == 0) { + if (QWORD_ALIGNED(address)) { mem_content = sp.read_qword(address); } else { mem_content = sp.read_qword_unaligned(address); @@ -558,21 +558,21 @@ int lua_engine::lua_addr_space::l_mem_write(lua_State *L) sp.write_byte(address, val); break; case 16: - if ((address & 1) == 0) { + if (WORD_ALIGNED(address)) { sp.write_word(address, val); } else { sp.read_word_unaligned(address, val); } break; case 32: - if ((address & 3) == 0) { + if (DWORD_ALIGNED(address)) { sp.write_dword(address, val); } else { sp.write_dword_unaligned(address, val); } break; case 64: - if ((address & 7) == 0) { + if (QWORD_ALIGNED(address)) { sp.write_qword(address, val); } else { sp.write_qword_unaligned(address, val); diff --git a/src/emu/memory.cpp b/src/emu/memory.cpp index 598ffab9ac6..656c00fd626 100644 --- a/src/emu/memory.cpp +++ b/src/emu/memory.cpp @@ -896,9 +896,9 @@ public: printf(" read_byte = "); printf("%02X\n", result8 = read_byte(address)); assert(result8 == expected8); // validate word accesses (if aligned) - if (address % 2 == 0) { printf(" read_word = "); printf("%04X\n", result16 = read_word(address)); assert(result16 == expected16); } - if (address % 2 == 0) { printf(" read_word (0xff00) = "); printf("%04X\n", result16 = read_word(address, 0xff00)); assert((result16 & 0xff00) == (expected16 & 0xff00)); } - if (address % 2 == 0) { printf(" (0x00ff) = "); printf("%04X\n", result16 = read_word(address, 0x00ff)); assert((result16 & 0x00ff) == (expected16 & 0x00ff)); } + if (WORD_ALIGNED(address)) { printf(" read_word = "); printf("%04X\n", result16 = read_word(address)); assert(result16 == expected16); } + if (WORD_ALIGNED(address)) { printf(" read_word (0xff00) = "); printf("%04X\n", result16 = read_word(address, 0xff00)); assert((result16 & 0xff00) == (expected16 & 0xff00)); } + if (WORD_ALIGNED(address)) { printf(" (0x00ff) = "); printf("%04X\n", result16 = read_word(address, 0x00ff)); assert((result16 & 0x00ff) == (expected16 & 0x00ff)); } // validate unaligned word accesses printf(" read_word_unaligned = "); printf("%04X\n", result16 = read_word_unaligned(address)); assert(result16 == expected16); @@ -906,15 +906,15 @@ public: printf(" (0x00ff) = "); printf("%04X\n", result16 = read_word_unaligned(address, 0x00ff)); assert((result16 & 0x00ff) == (expected16 & 0x00ff)); // validate dword acceses (if aligned) - if (address % 4 == 0) { printf(" read_dword = "); printf("%08X\n", result32 = read_dword(address)); assert(result32 == expected32); } - if (address % 4 == 0) { printf(" read_dword (0xff000000) = "); printf("%08X\n", result32 = read_dword(address, 0xff000000)); assert((result32 & 0xff000000) == (expected32 & 0xff000000)); } - if (address % 4 == 0) { printf(" (0x00ff0000) = "); printf("%08X\n", result32 = read_dword(address, 0x00ff0000)); assert((result32 & 0x00ff0000) == (expected32 & 0x00ff0000)); } - if (address % 4 == 0) { printf(" (0x0000ff00) = "); printf("%08X\n", result32 = read_dword(address, 0x0000ff00)); assert((result32 & 0x0000ff00) == (expected32 & 0x0000ff00)); } - if (address % 4 == 0) { printf(" (0x000000ff) = "); printf("%08X\n", result32 = read_dword(address, 0x000000ff)); assert((result32 & 0x000000ff) == (expected32 & 0x000000ff)); } - if (address % 4 == 0) { printf(" (0xffff0000) = "); printf("%08X\n", result32 = read_dword(address, 0xffff0000)); assert((result32 & 0xffff0000) == (expected32 & 0xffff0000)); } - if (address % 4 == 0) { printf(" (0x0000ffff) = "); printf("%08X\n", result32 = read_dword(address, 0x0000ffff)); assert((result32 & 0x0000ffff) == (expected32 & 0x0000ffff)); } - if (address % 4 == 0) { printf(" (0xffffff00) = "); printf("%08X\n", result32 = read_dword(address, 0xffffff00)); assert((result32 & 0xffffff00) == (expected32 & 0xffffff00)); } - if (address % 4 == 0) { printf(" (0x00ffffff) = "); printf("%08X\n", result32 = read_dword(address, 0x00ffffff)); assert((result32 & 0x00ffffff) == (expected32 & 0x00ffffff)); } + if (DWORD_ALIGNED(address)) { printf(" read_dword = "); printf("%08X\n", result32 = read_dword(address)); assert(result32 == expected32); } + if (DWORD_ALIGNED(address)) { printf(" read_dword (0xff000000) = "); printf("%08X\n", result32 = read_dword(address, 0xff000000)); assert((result32 & 0xff000000) == (expected32 & 0xff000000)); } + if (DWORD_ALIGNED(address)) { printf(" (0x00ff0000) = "); printf("%08X\n", result32 = read_dword(address, 0x00ff0000)); assert((result32 & 0x00ff0000) == (expected32 & 0x00ff0000)); } + if (DWORD_ALIGNED(address)) { printf(" (0x0000ff00) = "); printf("%08X\n", result32 = read_dword(address, 0x0000ff00)); assert((result32 & 0x0000ff00) == (expected32 & 0x0000ff00)); } + if (DWORD_ALIGNED(address)) { printf(" (0x000000ff) = "); printf("%08X\n", result32 = read_dword(address, 0x000000ff)); assert((result32 & 0x000000ff) == (expected32 & 0x000000ff)); } + if (DWORD_ALIGNED(address)) { printf(" (0xffff0000) = "); printf("%08X\n", result32 = read_dword(address, 0xffff0000)); assert((result32 & 0xffff0000) == (expected32 & 0xffff0000)); } + if (DWORD_ALIGNED(address)) { printf(" (0x0000ffff) = "); printf("%08X\n", result32 = read_dword(address, 0x0000ffff)); assert((result32 & 0x0000ffff) == (expected32 & 0x0000ffff)); } + if (DWORD_ALIGNED(address)) { printf(" (0xffffff00) = "); printf("%08X\n", result32 = read_dword(address, 0xffffff00)); assert((result32 & 0xffffff00) == (expected32 & 0xffffff00)); } + if (DWORD_ALIGNED(address)) { printf(" (0x00ffffff) = "); printf("%08X\n", result32 = read_dword(address, 0x00ffffff)); assert((result32 & 0x00ffffff) == (expected32 & 0x00ffffff)); } // validate unaligned dword accesses printf(" read_dword_unaligned = "); printf("%08X\n", result32 = read_dword_unaligned(address)); assert(result32 == expected32); @@ -928,37 +928,37 @@ public: printf(" (0x00ffffff) = "); printf("%08X\n", result32 = read_dword_unaligned(address, 0x00ffffff)); assert((result32 & 0x00ffffff) == (expected32 & 0x00ffffff)); // validate qword acceses (if aligned) - if (address % 8 == 0) { printf(" read_qword = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address), 16)); assert(result64 == expected64); } - if (address % 8 == 0) { printf(" read_qword (0xff00000000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xff00000000000000)), 16)); assert((result64 & U64(0xff00000000000000)) == (expected64 & U64(0xff00000000000000))); } - if (address % 8 == 0) { printf(" (0x00ff000000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ff000000000000)), 16)); assert((result64 & U64(0x00ff000000000000)) == (expected64 & U64(0x00ff000000000000))); } - if (address % 8 == 0) { printf(" (0x0000ff0000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ff0000000000)), 16)); assert((result64 & U64(0x0000ff0000000000)) == (expected64 & U64(0x0000ff0000000000))); } - if (address % 8 == 0) { printf(" (0x000000ff00000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000ff00000000)), 16)); assert((result64 & U64(0x000000ff00000000)) == (expected64 & U64(0x000000ff00000000))); } - if (address % 8 == 0) { printf(" (0x00000000ff000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00000000ff000000)), 16)); assert((result64 & U64(0x00000000ff000000)) == (expected64 & U64(0x00000000ff000000))); } - if (address % 8 == 0) { printf(" (0x0000000000ff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000000000ff0000)), 16)); assert((result64 & U64(0x0000000000ff0000)) == (expected64 & U64(0x0000000000ff0000))); } - if (address % 8 == 0) { printf(" (0x000000000000ff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000000000ff00)), 16)); assert((result64 & U64(0x000000000000ff00)) == (expected64 & U64(0x000000000000ff00))); } - if (address % 8 == 0) { printf(" (0x00000000000000ff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00000000000000ff)), 16)); assert((result64 & U64(0x00000000000000ff)) == (expected64 & U64(0x00000000000000ff))); } - if (address % 8 == 0) { printf(" (0xffff000000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffff000000000000)), 16)); assert((result64 & U64(0xffff000000000000)) == (expected64 & U64(0xffff000000000000))); } - if (address % 8 == 0) { printf(" (0x0000ffff00000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffff00000000)), 16)); assert((result64 & U64(0x0000ffff00000000)) == (expected64 & U64(0x0000ffff00000000))); } - if (address % 8 == 0) { printf(" (0x00000000ffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00000000ffff0000)), 16)); assert((result64 & U64(0x00000000ffff0000)) == (expected64 & U64(0x00000000ffff0000))); } - if (address % 8 == 0) { printf(" (0x000000000000ffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000000000ffff)), 16)); assert((result64 & U64(0x000000000000ffff)) == (expected64 & U64(0x000000000000ffff))); } - if (address % 8 == 0) { printf(" (0xffffff0000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffff0000000000)), 16)); assert((result64 & U64(0xffffff0000000000)) == (expected64 & U64(0xffffff0000000000))); } - if (address % 8 == 0) { printf(" (0x0000ffffff000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffffff000000)), 16)); assert((result64 & U64(0x0000ffffff000000)) == (expected64 & U64(0x0000ffffff000000))); } - if (address % 8 == 0) { printf(" (0x000000ffffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000ffffff0000)), 16)); assert((result64 & U64(0x000000ffffff0000)) == (expected64 & U64(0x000000ffffff0000))); } - if (address % 8 == 0) { printf(" (0x0000000000ffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000000000ffffff)), 16)); assert((result64 & U64(0x0000000000ffffff)) == (expected64 & U64(0x0000000000ffffff))); } - if (address % 8 == 0) { printf(" (0xffffffff00000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffffff00000000)), 16)); assert((result64 & U64(0xffffffff00000000)) == (expected64 & U64(0xffffffff00000000))); } - if (address % 8 == 0) { printf(" (0x00ffffffff000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ffffffff000000)), 16)); assert((result64 & U64(0x00ffffffff000000)) == (expected64 & U64(0x00ffffffff000000))); } - if (address % 8 == 0) { printf(" (0x0000ffffffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffffffff0000)), 16)); assert((result64 & U64(0x0000ffffffff0000)) == (expected64 & U64(0x0000ffffffff0000))); } - if (address % 8 == 0) { printf(" (0x000000ffffffff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000ffffffff00)), 16)); assert((result64 & U64(0x000000ffffffff00)) == (expected64 & U64(0x000000ffffffff00))); } - if (address % 8 == 0) { printf(" (0x00000000ffffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00000000ffffffff)), 16)); assert((result64 & U64(0x00000000ffffffff)) == (expected64 & U64(0x00000000ffffffff))); } - if (address % 8 == 0) { printf(" (0xffffffffff000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffffffff000000)), 16)); assert((result64 & U64(0xffffffffff000000)) == (expected64 & U64(0xffffffffff000000))); } - if (address % 8 == 0) { printf(" (0x00ffffffffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ffffffffff0000)), 16)); assert((result64 & U64(0x00ffffffffff0000)) == (expected64 & U64(0x00ffffffffff0000))); } - if (address % 8 == 0) { printf(" (0x0000ffffffffff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffffffffff00)), 16)); assert((result64 & U64(0x0000ffffffffff00)) == (expected64 & U64(0x0000ffffffffff00))); } - if (address % 8 == 0) { printf(" (0x000000ffffffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000ffffffffff)), 16)); assert((result64 & U64(0x000000ffffffffff)) == (expected64 & U64(0x000000ffffffffff))); } - if (address % 8 == 0) { printf(" (0xffffffffffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffffffffff0000)), 16)); assert((result64 & U64(0xffffffffffff0000)) == (expected64 & U64(0xffffffffffff0000))); } - if (address % 8 == 0) { printf(" (0x00ffffffffffff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ffffffffffff00)), 16)); assert((result64 & U64(0x00ffffffffffff00)) == (expected64 & U64(0x00ffffffffffff00))); } - if (address % 8 == 0) { printf(" (0x0000ffffffffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffffffffffff)), 16)); assert((result64 & U64(0x0000ffffffffffff)) == (expected64 & U64(0x0000ffffffffffff))); } - if (address % 8 == 0) { printf(" (0xffffffffffffff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffffffffffff00)), 16)); assert((result64 & U64(0xffffffffffffff00)) == (expected64 & U64(0xffffffffffffff00))); } - if (address % 8 == 0) { printf(" (0x00ffffffffffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ffffffffffffff)), 16)); assert((result64 & U64(0x00ffffffffffffff)) == (expected64 & U64(0x00ffffffffffffff))); } + if (QWORD_ALIGNED(address)) { printf(" read_qword = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address), 16)); assert(result64 == expected64); } + if (QWORD_ALIGNED(address)) { printf(" read_qword (0xff00000000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xff00000000000000)), 16)); assert((result64 & U64(0xff00000000000000)) == (expected64 & U64(0xff00000000000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x00ff000000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ff000000000000)), 16)); assert((result64 & U64(0x00ff000000000000)) == (expected64 & U64(0x00ff000000000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x0000ff0000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ff0000000000)), 16)); assert((result64 & U64(0x0000ff0000000000)) == (expected64 & U64(0x0000ff0000000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x000000ff00000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000ff00000000)), 16)); assert((result64 & U64(0x000000ff00000000)) == (expected64 & U64(0x000000ff00000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x00000000ff000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00000000ff000000)), 16)); assert((result64 & U64(0x00000000ff000000)) == (expected64 & U64(0x00000000ff000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x0000000000ff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000000000ff0000)), 16)); assert((result64 & U64(0x0000000000ff0000)) == (expected64 & U64(0x0000000000ff0000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x000000000000ff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000000000ff00)), 16)); assert((result64 & U64(0x000000000000ff00)) == (expected64 & U64(0x000000000000ff00))); } + if (QWORD_ALIGNED(address)) { printf(" (0x00000000000000ff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00000000000000ff)), 16)); assert((result64 & U64(0x00000000000000ff)) == (expected64 & U64(0x00000000000000ff))); } + if (QWORD_ALIGNED(address)) { printf(" (0xffff000000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffff000000000000)), 16)); assert((result64 & U64(0xffff000000000000)) == (expected64 & U64(0xffff000000000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x0000ffff00000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffff00000000)), 16)); assert((result64 & U64(0x0000ffff00000000)) == (expected64 & U64(0x0000ffff00000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x00000000ffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00000000ffff0000)), 16)); assert((result64 & U64(0x00000000ffff0000)) == (expected64 & U64(0x00000000ffff0000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x000000000000ffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000000000ffff)), 16)); assert((result64 & U64(0x000000000000ffff)) == (expected64 & U64(0x000000000000ffff))); } + if (QWORD_ALIGNED(address)) { printf(" (0xffffff0000000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffff0000000000)), 16)); assert((result64 & U64(0xffffff0000000000)) == (expected64 & U64(0xffffff0000000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x0000ffffff000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffffff000000)), 16)); assert((result64 & U64(0x0000ffffff000000)) == (expected64 & U64(0x0000ffffff000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x000000ffffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000ffffff0000)), 16)); assert((result64 & U64(0x000000ffffff0000)) == (expected64 & U64(0x000000ffffff0000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x0000000000ffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000000000ffffff)), 16)); assert((result64 & U64(0x0000000000ffffff)) == (expected64 & U64(0x0000000000ffffff))); } + if (QWORD_ALIGNED(address)) { printf(" (0xffffffff00000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffffff00000000)), 16)); assert((result64 & U64(0xffffffff00000000)) == (expected64 & U64(0xffffffff00000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x00ffffffff000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ffffffff000000)), 16)); assert((result64 & U64(0x00ffffffff000000)) == (expected64 & U64(0x00ffffffff000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x0000ffffffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffffffff0000)), 16)); assert((result64 & U64(0x0000ffffffff0000)) == (expected64 & U64(0x0000ffffffff0000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x000000ffffffff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000ffffffff00)), 16)); assert((result64 & U64(0x000000ffffffff00)) == (expected64 & U64(0x000000ffffffff00))); } + if (QWORD_ALIGNED(address)) { printf(" (0x00000000ffffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00000000ffffffff)), 16)); assert((result64 & U64(0x00000000ffffffff)) == (expected64 & U64(0x00000000ffffffff))); } + if (QWORD_ALIGNED(address)) { printf(" (0xffffffffff000000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffffffff000000)), 16)); assert((result64 & U64(0xffffffffff000000)) == (expected64 & U64(0xffffffffff000000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x00ffffffffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ffffffffff0000)), 16)); assert((result64 & U64(0x00ffffffffff0000)) == (expected64 & U64(0x00ffffffffff0000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x0000ffffffffff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffffffffff00)), 16)); assert((result64 & U64(0x0000ffffffffff00)) == (expected64 & U64(0x0000ffffffffff00))); } + if (QWORD_ALIGNED(address)) { printf(" (0x000000ffffffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x000000ffffffffff)), 16)); assert((result64 & U64(0x000000ffffffffff)) == (expected64 & U64(0x000000ffffffffff))); } + if (QWORD_ALIGNED(address)) { printf(" (0xffffffffffff0000) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffffffffff0000)), 16)); assert((result64 & U64(0xffffffffffff0000)) == (expected64 & U64(0xffffffffffff0000))); } + if (QWORD_ALIGNED(address)) { printf(" (0x00ffffffffffff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ffffffffffff00)), 16)); assert((result64 & U64(0x00ffffffffffff00)) == (expected64 & U64(0x00ffffffffffff00))); } + if (QWORD_ALIGNED(address)) { printf(" (0x0000ffffffffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x0000ffffffffffff)), 16)); assert((result64 & U64(0x0000ffffffffffff)) == (expected64 & U64(0x0000ffffffffffff))); } + if (QWORD_ALIGNED(address)) { printf(" (0xffffffffffffff00) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0xffffffffffffff00)), 16)); assert((result64 & U64(0xffffffffffffff00)) == (expected64 & U64(0xffffffffffffff00))); } + if (QWORD_ALIGNED(address)) { printf(" (0x00ffffffffffffff) = "); printf("%s\n", core_i64_hex_format(result64 = read_qword(address, U64(0x00ffffffffffffff)), 16)); assert((result64 & U64(0x00ffffffffffffff)) == (expected64 & U64(0x00ffffffffffffff))); } // validate unaligned qword accesses printf(" read_qword_unaligned = "); printf("%s\n", core_i64_hex_format(result64 = read_qword_unaligned(address), 16)); assert(result64 == expected64); diff --git a/src/emu/memory.h b/src/emu/memory.h index 3b46ac33449..34a060a51b6 100644 --- a/src/emu/memory.h +++ b/src/emu/memory.h @@ -866,6 +866,12 @@ private: #define DWORD_XOR_LE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,4)) +// helpers for checking address alignment +#define WORD_ALIGNED(a) (((a) & 1) == 0) +#define DWORD_ALIGNED(a) (((a) & 3) == 0) +#define QWORD_ALIGNED(a) (((a) & 7) == 0) + + //************************************************************************** // INLINE FUNCTIONS diff --git a/src/mame/drivers/cobra.cpp b/src/mame/drivers/cobra.cpp index 848862363b2..8062af06612 100644 --- a/src/mame/drivers/cobra.cpp +++ b/src/mame/drivers/cobra.cpp @@ -2128,7 +2128,7 @@ void cobra_renderer::gfx_reset() UINT32 cobra_renderer::gfx_read_gram(UINT32 address) { - if (address & 3) + if (!DWORD_ALIGNED(address)) { printf("gfx_read_gram: %08X, not dword aligned!\n", address); return 0; @@ -2186,7 +2186,7 @@ void cobra_renderer::gfx_write_gram(UINT32 address, UINT32 mask, UINT32 data) } } - if (address & 3) + if (!DWORD_ALIGNED(address)) { printf("gfx_write_gram: %08X, %08X, not dword aligned!\n", address, data); return; diff --git a/src/mame/drivers/magictg.cpp b/src/mame/drivers/magictg.cpp index 63b0df20394..0235da41a9a 100644 --- a/src/mame/drivers/magictg.cpp +++ b/src/mame/drivers/magictg.cpp @@ -601,8 +601,8 @@ WRITE32_MEMBER( magictg_state::f0_w ) UINT32 dst_addr = m_dma_ch[ch].dst_addr; //device_t *voodoo = dst_addr > 0xa000000 voodoo0 : voodoo1; - assert((src_addr & 3) == 0); - assert((dst_addr & 3) == 0); + assert(DWORD_ALIGNED(src_addr)); + assert(DWORD_ALIGNED(dst_addr)); while (m_dma_ch[ch].count > 3) { diff --git a/src/mame/machine/n64.cpp b/src/mame/machine/n64.cpp index a3e256a080c..5f0d8a6b4d2 100644 --- a/src/mame/machine/n64.cpp +++ b/src/mame/machine/n64.cpp @@ -2089,7 +2089,7 @@ void n64_periphs::si_dma_tick() void n64_periphs::pif_dma(int direction) { - if (si_dram_addr & 0x3) + if (!DWORD_ALIGNED(si_dram_addr)) { fatalerror("pif_dma: si_dram_addr unaligned: %08X\n", si_dram_addr); } diff --git a/src/mame/video/seibuspi.cpp b/src/mame/video/seibuspi.cpp index cb267167789..42e683c70b2 100644 --- a/src/mame/video/seibuspi.cpp +++ b/src/mame/video/seibuspi.cpp @@ -111,7 +111,7 @@ WRITE32_MEMBER(seibuspi_state::tilemap_dma_start_w) int dma_length_real = (m_video_dma_length + 1) * 2; // ideally we should be using this, let's check if we have to: if (m_video_dma_length != 0 && dma_length_user != dma_length_real) popmessage("Tile LEN %X %X, contact MAMEdev", dma_length_user, dma_length_real); // shouldn't happen - else if ((m_video_dma_address & 3) != 0 || (m_video_dma_length & 3) != 3 || (m_video_dma_address + dma_length_user) > 0x40000) + else if (!DWORD_ALIGNED(m_video_dma_address) || (m_video_dma_length & 3) != 3 || (m_video_dma_address + dma_length_user) > 0x40000) popmessage("Tile DMA %X %X, contact MAMEdev", m_video_dma_address, m_video_dma_length); // shouldn't happen if (m_video_dma_address < 0x800) logerror("tilemap_dma_start_w in I/O area: %X\n", m_video_dma_address); @@ -198,7 +198,7 @@ WRITE32_MEMBER(seibuspi_state::palette_dma_start_w) int dma_length = (m_video_dma_length + 1) * 2; // safety check - if ((m_video_dma_address & 3) != 0 || (m_video_dma_length & 3) != 3 || dma_length > m_palette_ram_size || (m_video_dma_address + dma_length) > 0x40000) + if (!DWORD_ALIGNED(m_video_dma_address) || (m_video_dma_length & 3) != 3 || dma_length > m_palette_ram_size || (m_video_dma_address + dma_length) > 0x40000) popmessage("Pal DMA %X %X, contact MAMEdev", m_video_dma_address, m_video_dma_length); // shouldn't happen if (m_video_dma_address < 0x800) logerror("palette_dma_start_w in I/O area: %X\n", m_video_dma_address); @@ -219,7 +219,7 @@ WRITE32_MEMBER(seibuspi_state::palette_dma_start_w) WRITE16_MEMBER(seibuspi_state::sprite_dma_start_w) { // safety check - if ((m_video_dma_address & 3) != 0 || (m_video_dma_address + m_sprite_ram_size) > 0x40000) + if (!DWORD_ALIGNED(m_video_dma_address) || (m_video_dma_address + m_sprite_ram_size) > 0x40000) popmessage("Sprite DMA %X, contact MAMEdev", m_video_dma_address); // shouldn't happen if (m_video_dma_address < 0x800) logerror("sprite_dma_start_w in I/O area: %X\n", m_video_dma_address); -- cgit v1.2.3-70-g09d2 From 42622cfe8effd40c0bf63030738e43feaa6999d6 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 30 Jan 2016 20:43:50 +0100 Subject: replace osd_lock with std::mutex [Miodrag Milanovic] --- scripts/src/osd/osdmini.lua | 1 - src/emu/debug/debugvw.cpp | 22 +-- src/emu/debug/dvstate.cpp | 18 +- src/emu/emualloc.cpp | 29 +--- src/emu/emualloc.h | 3 +- src/emu/luaengine.cpp | 49 +++--- src/emu/render.cpp | 4 - src/emu/render.h | 7 +- src/emu/ui/filemngr.cpp | 4 +- src/emu/ui/imgcntrl.cpp | 14 +- src/emu/ui/inputmap.cpp | 2 +- src/emu/ui/mainmenu.cpp | 44 ++--- src/emu/ui/menu.cpp | 14 +- src/emu/ui/selgame.cpp | 8 +- src/emu/ui/sliders.cpp | 2 +- src/emu/ui/slotopt.cpp | 2 +- src/emu/ui/swlist.cpp | 2 +- src/emu/ui/videoopt.cpp | 2 +- src/mame/includes/chihiro.h | 5 +- src/mame/video/chihiro.cpp | 3 +- src/osd/modules/sound/xaudio2_sound.cpp | 40 +---- src/osd/modules/sync/osdsync.h | 16 +- src/osd/modules/sync/sync_mini.cpp | 57 ------- src/osd/modules/sync/sync_ntc.cpp | 279 ------------------------------- src/osd/modules/sync/sync_os2.cpp | 280 -------------------------------- src/osd/modules/sync/sync_sdl.cpp | 132 --------------- src/osd/modules/sync/sync_tc.cpp | 117 ------------- src/osd/modules/sync/sync_windows.cpp | 177 -------------------- src/osd/modules/sync/work_osd.cpp | 43 +++-- src/osd/osdcore.h | 87 ---------- src/osd/osdmini/minisync.cpp | 66 -------- src/osd/sdl/input.cpp | 16 +- src/osd/windows/input.cpp | 32 +--- src/osd/windows/window.cpp | 18 +- src/osd/windows/window.h | 3 +- 35 files changed, 152 insertions(+), 1446 deletions(-) delete mode 100644 src/osd/osdmini/minisync.cpp (limited to 'src/emu/luaengine.cpp') diff --git a/scripts/src/osd/osdmini.lua b/scripts/src/osd/osdmini.lua index 0795ccdb4bd..b05839e7873 100644 --- a/scripts/src/osd/osdmini.lua +++ b/scripts/src/osd/osdmini.lua @@ -125,7 +125,6 @@ project ("ocore_" .. _OPTIONS["osd"]) MAME_DIR .. "src/osd/osdmini/minidir.cpp", MAME_DIR .. "src/osd/osdmini/minifile.cpp", MAME_DIR .. "src/osd/osdmini/minimisc.cpp", - MAME_DIR .. "src/osd/osdmini/minisync.cpp", MAME_DIR .. "src/osd/osdmini/minitime.cpp", MAME_DIR .. "src/osd/modules/sync/work_mini.cpp", } diff --git a/src/emu/debug/debugvw.cpp b/src/emu/debug/debugvw.cpp index eea867f3a63..0fcf1f4b2fd 100644 --- a/src/emu/debug/debugvw.cpp +++ b/src/emu/debug/debugvw.cpp @@ -331,7 +331,7 @@ debug_view_manager::~debug_view_manager() { debug_view *oldhead = m_viewlist; m_viewlist = oldhead->m_next; - auto_free(machine(), oldhead); + global_free(oldhead); } } @@ -345,31 +345,31 @@ debug_view *debug_view_manager::alloc_view(debug_view_type type, debug_view_osd_ switch (type) { case DVT_CONSOLE: - return append(auto_alloc(machine(), debug_view_console(machine(), osdupdate, osdprivate))); + return append(global_alloc(debug_view_console(machine(), osdupdate, osdprivate))); case DVT_STATE: - return append(auto_alloc(machine(), debug_view_state(machine(), osdupdate, osdprivate))); + return append(global_alloc(debug_view_state(machine(), osdupdate, osdprivate))); case DVT_DISASSEMBLY: - return append(auto_alloc(machine(), debug_view_disasm(machine(), osdupdate, osdprivate))); + return append(global_alloc(debug_view_disasm(machine(), osdupdate, osdprivate))); case DVT_MEMORY: - return append(auto_alloc(machine(), debug_view_memory(machine(), osdupdate, osdprivate))); + return append(global_alloc(debug_view_memory(machine(), osdupdate, osdprivate))); case DVT_LOG: - return append(auto_alloc(machine(), debug_view_log(machine(), osdupdate, osdprivate))); + return append(global_alloc(debug_view_log(machine(), osdupdate, osdprivate))); case DVT_TIMERS: -// return append(auto_alloc(machine(), debug_view_timers(machine(), osdupdate, osdprivate))); +// return append(global_alloc(debug_view_timers(machine(), osdupdate, osdprivate))); case DVT_ALLOCS: -// return append(auto_alloc(machine(), debug_view_allocs(machine(), osdupdate, osdprivate))); +// return append(global_alloc(debug_view_allocs(machine(), osdupdate, osdprivate))); case DVT_BREAK_POINTS: - return append(auto_alloc(machine(), debug_view_breakpoints(machine(), osdupdate, osdprivate))); + return append(global_alloc(debug_view_breakpoints(machine(), osdupdate, osdprivate))); case DVT_WATCH_POINTS: - return append(auto_alloc(machine(), debug_view_watchpoints(machine(), osdupdate, osdprivate))); + return append(global_alloc(debug_view_watchpoints(machine(), osdupdate, osdprivate))); default: fatalerror("Attempt to create invalid debug view type %d\n", type); @@ -389,7 +389,7 @@ void debug_view_manager::free_view(debug_view &view) if (*viewptr == &view) { *viewptr = view.m_next; - auto_free(machine(), &view); + global_free(&view); break; } } diff --git a/src/emu/debug/dvstate.cpp b/src/emu/debug/dvstate.cpp index 578b423725d..d0d741ed21e 100644 --- a/src/emu/debug/dvstate.cpp +++ b/src/emu/debug/dvstate.cpp @@ -98,7 +98,7 @@ void debug_view_state::reset() { state_item *oldhead = m_state_list; m_state_list = oldhead->m_next; - auto_free(machine(), oldhead); + global_free(oldhead); } } @@ -117,39 +117,39 @@ void debug_view_state::recompute() // add a cycles entry: cycles:99999999 state_item **tailptr = &m_state_list; - *tailptr = auto_alloc(machine(), state_item(REG_CYCLES, "cycles", 8)); + *tailptr = global_alloc(state_item(REG_CYCLES, "cycles", 8)); tailptr = &(*tailptr)->m_next; // add a beam entry: beamx:1234 - *tailptr = auto_alloc(machine(), state_item(REG_BEAMX, "beamx", 4)); + *tailptr = global_alloc(state_item(REG_BEAMX, "beamx", 4)); tailptr = &(*tailptr)->m_next; // add a beam entry: beamy:5678 - *tailptr = auto_alloc(machine(), state_item(REG_BEAMY, "beamy", 4)); + *tailptr = global_alloc(state_item(REG_BEAMY, "beamy", 4)); tailptr = &(*tailptr)->m_next; // add a beam entry: frame:123456 - *tailptr = auto_alloc(machine(), state_item(REG_FRAME, "frame", 6)); + *tailptr = global_alloc(state_item(REG_FRAME, "frame", 6)); tailptr = &(*tailptr)->m_next; // add a flags entry: flags:xxxxxxxx - *tailptr = auto_alloc(machine(), state_item(STATE_GENFLAGS, "flags", source.m_stateintf->state_string_max_length(STATE_GENFLAGS))); + *tailptr = global_alloc(state_item(STATE_GENFLAGS, "flags", source.m_stateintf->state_string_max_length(STATE_GENFLAGS))); tailptr = &(*tailptr)->m_next; // add a divider entry - *tailptr = auto_alloc(machine(), state_item(REG_DIVIDER, "", 0)); + *tailptr = global_alloc(state_item(REG_DIVIDER, "", 0)); tailptr = &(*tailptr)->m_next; // add all registers into it for (const device_state_entry *entry = source.m_stateintf->state_first(); entry != nullptr; entry = entry->next()) if (entry->divider()) { - *tailptr = auto_alloc(machine(), state_item(REG_DIVIDER, "", 0)); + *tailptr = global_alloc(state_item(REG_DIVIDER, "", 0)); tailptr = &(*tailptr)->m_next; } else if (entry->visible()) { - *tailptr = auto_alloc(machine(), state_item(entry->index(), entry->symbol(), source.m_stateintf->state_string_max_length(entry->index()))); + *tailptr = global_alloc(state_item(entry->index(), entry->symbol(), source.m_stateintf->state_string_max_length(entry->index()))); tailptr = &(*tailptr)->m_next; } diff --git a/src/emu/emualloc.cpp b/src/emu/emualloc.cpp index a43faae522c..f424bca39cb 100644 --- a/src/emu/emualloc.cpp +++ b/src/emu/emualloc.cpp @@ -38,7 +38,6 @@ UINT64 resource_pool::s_id = 0; resource_pool::resource_pool(int hash_size) : m_hash_size(hash_size), - m_listlock(osd_lock_alloc()), m_hash(hash_size), m_ordered_head(nullptr), m_ordered_tail(nullptr) @@ -56,8 +55,6 @@ resource_pool::resource_pool(int hash_size) resource_pool::~resource_pool() { clear(); - if (m_listlock != nullptr) - osd_lock_free(m_listlock); } @@ -67,7 +64,7 @@ resource_pool::~resource_pool() void resource_pool::add(resource_pool_item &item, size_t size, const char *type) { - osd_lock_acquire(m_listlock); + std::lock_guard lock(m_listlock); // insert into hash table int hashval = reinterpret_cast(item.m_ptr) % m_hash_size; @@ -107,8 +104,6 @@ void resource_pool::add(resource_pool_item &item, size_t size, const char *type) item.m_ordered_prev = nullptr; m_ordered_head = &item; } - - osd_lock_release(m_listlock); } @@ -124,7 +119,7 @@ void resource_pool::remove(void *ptr) return; // search for the item - osd_lock_acquire(m_listlock); + std::lock_guard lock(m_listlock); int hashval = reinterpret_cast(ptr) % m_hash_size; for (resource_pool_item **scanptr = &m_hash[hashval]; *scanptr != nullptr; scanptr = &(*scanptr)->m_next) @@ -152,8 +147,6 @@ void resource_pool::remove(void *ptr) global_free(deleteme); break; } - - osd_lock_release(m_listlock); } @@ -165,7 +158,7 @@ void resource_pool::remove(void *ptr) resource_pool_item *resource_pool::find(void *ptr) { // search for the item - osd_lock_acquire(m_listlock); + std::lock_guard lock(m_listlock); int hashval = reinterpret_cast(ptr) % m_hash_size; resource_pool_item *item; @@ -173,8 +166,6 @@ resource_pool_item *resource_pool::find(void *ptr) if (item->m_ptr == ptr) break; - osd_lock_release(m_listlock); - return item; } @@ -190,7 +181,7 @@ bool resource_pool::contains(void *_ptrstart, void *_ptrend) UINT8 *ptrend = reinterpret_cast(_ptrend); // search for the item - osd_lock_acquire(m_listlock); + std::lock_guard lock(m_listlock); resource_pool_item *item = nullptr; for (item = m_ordered_head; item != nullptr; item = item->m_ordered_next) @@ -198,13 +189,9 @@ bool resource_pool::contains(void *_ptrstart, void *_ptrend) UINT8 *objstart = reinterpret_cast(item->m_ptr); UINT8 *objend = objstart + item->m_size; if (ptrstart >= objstart && ptrend <= objend) - goto found; + return true; } - -found: - osd_lock_release(m_listlock); - - return (item != nullptr); + return false; } @@ -214,12 +201,8 @@ found: void resource_pool::clear() { - osd_lock_acquire(m_listlock); - // important: delete from earliest to latest; this allows objects to clean up after // themselves if they wish while (m_ordered_head != nullptr) remove(m_ordered_head->m_ptr); - - osd_lock_release(m_listlock); } diff --git a/src/emu/emualloc.h b/src/emu/emualloc.h index 4571762054f..37b5c63d860 100644 --- a/src/emu/emualloc.h +++ b/src/emu/emualloc.h @@ -14,6 +14,7 @@ #define __EMUALLOC_H__ #include +#include #include "osdcore.h" #include "coretmpl.h" @@ -124,7 +125,7 @@ public: private: int m_hash_size; - osd_lock * m_listlock; + std::mutex m_listlock; std::vector m_hash; resource_pool_item * m_ordered_head; resource_pool_item * m_ordered_tail; diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp index f8ec7023bc6..f487c02bed6 100644 --- a/src/emu/luaengine.cpp +++ b/src/emu/luaengine.cpp @@ -17,6 +17,7 @@ #include "drivenum.h" #include "ui/ui.h" #include "luaengine.h" +#include //************************************************************************** // LUA ENGINE @@ -808,7 +809,7 @@ struct msg { int done; } msg; -osd_lock *lock; +static std::mutex g_mutex; void lua_engine::serve_lua() { @@ -826,37 +827,39 @@ void lua_engine::serve_lua() fgets(buff, LUA_MAXINPUT, stdin); // Create message - osd_lock_acquire(lock); - if (msg.ready == 0) { - msg.text = oldbuff; - if (oldbuff.length()!=0) msg.text.append("\n"); - msg.text.append(buff); - msg.ready = 1; - msg.done = 0; + { + std::lock_guard lock(g_mutex); + if (msg.ready == 0) { + msg.text = oldbuff; + if (oldbuff.length() != 0) msg.text.append("\n"); + msg.text.append(buff); + msg.ready = 1; + msg.done = 0; + } } - osd_lock_release(lock); // Wait for response int done; do { osd_sleep(osd_ticks_per_second() / 1000); - osd_lock_acquire(lock); + std::lock_guard lock(g_mutex); done = msg.done; - osd_lock_release(lock); } while (done==0); // Do action on client side - osd_lock_acquire(lock); - if (msg.status == -1){ - b = LUA_PROMPT2; - oldbuff = msg.response; - } - else { - b = LUA_PROMPT; - oldbuff = ""; + { + osd_sleep(osd_ticks_per_second() / 1000); + + if (msg.status == -1) { + b = LUA_PROMPT2; + oldbuff = msg.response; + } + else { + b = LUA_PROMPT; + oldbuff = ""; + } + msg.done = 0; } - msg.done = 0; - osd_lock_release(lock); } while (1); } @@ -891,7 +894,6 @@ lua_engine::lua_engine() msg.ready = 0; msg.status = 0; msg.done = 0; - lock = osd_lock_alloc(); } //------------------------------------------------- @@ -1046,7 +1048,7 @@ bool lua_engine::frame_hook() void lua_engine::periodic_check() { - osd_lock_acquire(lock); + std::lock_guard lock(g_mutex); if (msg.ready == 1) { lua_settop(m_lua_state, 0); int status = luaL_loadbuffer(m_lua_state, msg.text.c_str(), msg.text.length(), "=stdin"); @@ -1075,7 +1077,6 @@ void lua_engine::periodic_check() msg.ready = 0; msg.done = 1; } - osd_lock_release(lock); } //------------------------------------------------- diff --git a/src/emu/render.cpp b/src/emu/render.cpp index 1f8e5d0be1f..e25f62a8e13 100644 --- a/src/emu/render.cpp +++ b/src/emu/render.cpp @@ -227,7 +227,6 @@ void render_primitive::reset() //------------------------------------------------- render_primitive_list::render_primitive_list() - : m_lock(osd_lock_alloc()) { } @@ -239,7 +238,6 @@ render_primitive_list::render_primitive_list() render_primitive_list::~render_primitive_list() { release_all(); - osd_lock_free(m_lock); } @@ -296,10 +294,8 @@ inline render_primitive *render_primitive_list::alloc(render_primitive::primitiv void render_primitive_list::release_all() { // release all the live items while under the lock - acquire_lock(); m_primitive_allocator.reclaim_all(m_primlist); m_reference_allocator.reclaim_all(m_reflist); - release_lock(); } diff --git a/src/emu/render.h b/src/emu/render.h index df8896b712b..5be63b085b5 100644 --- a/src/emu/render.h +++ b/src/emu/render.h @@ -49,6 +49,7 @@ //#include "osdepend.h" #include +#include //************************************************************************** @@ -358,8 +359,8 @@ public: render_primitive *first() const { return m_primlist.first(); } // lock management - void acquire_lock() { osd_lock_acquire(m_lock); } - void release_lock() { osd_lock_release(m_lock); } + void acquire_lock() { m_lock.lock(); } + void release_lock() { m_lock.unlock(); } // reference management void add_reference(void *refptr); @@ -388,7 +389,7 @@ private: fixed_allocator m_primitive_allocator;// allocator for primitives fixed_allocator m_reference_allocator; // allocator for references - osd_lock * m_lock; // lock to protect list accesses + std::mutex m_lock; // lock to protect list accesses }; diff --git a/src/emu/ui/filemngr.cpp b/src/emu/ui/filemngr.cpp index d277d0bd847..cccc92888c4 100644 --- a/src/emu/ui/filemngr.cpp +++ b/src/emu/ui/filemngr.cpp @@ -195,10 +195,10 @@ void ui_menu_file_manager::force_file_manager(running_machine &machine, render_c ui_menu::stack_reset(machine); // add the quit entry followed by the game select entry - ui_menu *quit = auto_alloc_clear(machine, (machine, container)); + ui_menu *quit = global_alloc_clear(machine, container); quit->set_special_main_menu(true); ui_menu::stack_push(quit); - ui_menu::stack_push(auto_alloc_clear(machine, (machine, container, warnings))); + ui_menu::stack_push(global_alloc_clear(machine, container, warnings)); // force the menus on machine.ui().show_menu(); diff --git a/src/emu/ui/imgcntrl.cpp b/src/emu/ui/imgcntrl.cpp index 3bb77723726..8f3dbeca75b 100644 --- a/src/emu/ui/imgcntrl.cpp +++ b/src/emu/ui/imgcntrl.cpp @@ -190,20 +190,20 @@ void ui_menu_control_device_image::handle() zippath_closedir(directory); } submenu_result = -1; - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, image, current_directory, current_file, true, image->image_interface()!=nullptr, can_create, &submenu_result))); + ui_menu::stack_push(global_alloc_clear(machine(), container, image, current_directory, current_file, true, image->image_interface()!=nullptr, can_create, &submenu_result)); state = SELECT_FILE; break; } case START_SOFTLIST: sld = nullptr; - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, image->image_interface(), &sld))); + ui_menu::stack_push(global_alloc_clear(machine(), container, image->image_interface(), &sld)); state = SELECT_SOFTLIST; break; case START_OTHER_PART: { submenu_result = -1; - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, swi, swp->interface(), &swp, true, &submenu_result))); + ui_menu::stack_push(global_alloc_clear(machine(), container, swi, swp->interface(), &swp, true, &submenu_result)); state = SELECT_OTHER_PART; break; } @@ -214,7 +214,7 @@ void ui_menu_control_device_image::handle() break; } software_info_name = ""; - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, sld, image->image_interface(), software_info_name))); + ui_menu::stack_push(global_alloc_clear(machine(), container, sld, image->image_interface(), software_info_name)); state = SELECT_PARTLIST; break; @@ -226,7 +226,7 @@ void ui_menu_control_device_image::handle() { submenu_result = -1; swp = nullptr; - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, swi, image->image_interface(), &swp, false, &submenu_result))); + ui_menu::stack_push(global_alloc_clear(machine(), container, swi, image->image_interface(), &swp, false, &submenu_result)); state = SELECT_ONE_PART; } else @@ -290,7 +290,7 @@ void ui_menu_control_device_image::handle() break; case ui_menu_file_selector::R_CREATE: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, image, current_directory, current_file, &create_ok))); + ui_menu::stack_push(global_alloc_clear(machine(), container, image, current_directory, current_file, &create_ok)); state = CHECK_CREATE; break; @@ -310,7 +310,7 @@ void ui_menu_control_device_image::handle() test_create(can_create, need_confirm); if(can_create) { if(need_confirm) { - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, &create_confirmed))); + ui_menu::stack_push(global_alloc_clear(machine(), container, &create_confirmed)); state = CREATE_CONFIRM; } else { state = DO_CREATE; diff --git a/src/emu/ui/inputmap.cpp b/src/emu/ui/inputmap.cpp index 1fc0d046e1f..f3ffe9b0e59 100644 --- a/src/emu/ui/inputmap.cpp +++ b/src/emu/ui/inputmap.cpp @@ -73,7 +73,7 @@ void ui_menu_input_groups::handle() /* process the menu */ const ui_menu_event *menu_event = process(0); if (menu_event != nullptr && menu_event->iptkey == IPT_UI_SELECT) - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, int((long long)(menu_event->itemref)-1)))); + ui_menu::stack_push(global_alloc_clear(machine(), container, int((long long)(menu_event->itemref)-1))); } diff --git a/src/emu/ui/mainmenu.cpp b/src/emu/ui/mainmenu.cpp index 415ad118811..75f16b3d9ba 100644 --- a/src/emu/ui/mainmenu.cpp +++ b/src/emu/ui/mainmenu.cpp @@ -152,91 +152,91 @@ void ui_menu_main::handle() if (menu_event != nullptr && menu_event->iptkey == IPT_UI_SELECT) { switch((long long)(menu_event->itemref)) { case INPUT_GROUPS: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case INPUT_SPECIFIC: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case SETTINGS_DIP_SWITCHES: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case SETTINGS_DRIVER_CONFIG: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case ANALOG: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case BOOKKEEPING: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case GAME_INFO: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case IMAGE_MENU_IMAGE_INFO: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case IMAGE_MENU_FILE_MANAGER: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); + ui_menu::stack_push(global_alloc_clear(machine(), container, nullptr)); break; case TAPE_CONTROL: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); + ui_menu::stack_push(global_alloc_clear(machine(), container, nullptr)); break; case PTY_INFO: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case SLOT_DEVICES: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case NETWORK_DEVICES: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case KEYBOARD_MODE: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case SLIDERS: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, false))); + ui_menu::stack_push(global_alloc_clear(machine(), container, false)); break; case VIDEO_TARGETS: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case VIDEO_OPTIONS: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, machine().render().first_target()))); + ui_menu::stack_push(global_alloc_clear(machine(), container, machine().render().first_target())); break; case CROSSHAIR: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case CHEAT: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case SELECT_GAME: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); + ui_menu::stack_push(global_alloc_clear(machine(), container, nullptr)); break; case BIOS_SELECTION: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); break; case BARCODE_READ: - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); + ui_menu::stack_push(global_alloc_clear(machine(), container, nullptr)); break; default: diff --git a/src/emu/ui/menu.cpp b/src/emu/ui/menu.cpp index 069b05aa913..33604fbbe62 100644 --- a/src/emu/ui/menu.cpp +++ b/src/emu/ui/menu.cpp @@ -148,12 +148,12 @@ ui_menu::~ui_menu() { ui_menu_pool *ppool = pool; pool = pool->next; - auto_free(machine(), ppool); + global_free(ppool); } // free the item array if (item) - auto_free(machine(), item); + global_free(item); } @@ -247,10 +247,10 @@ void ui_menu::item_append(const char *text, const char *subtext, UINT32 flags, v { int olditems = allocitems; allocitems += UI_MENU_ALLOC_ITEMS; - ui_menu_item *newitems = auto_alloc_array(machine(), ui_menu_item, allocitems); + ui_menu_item *newitems = global_alloc_array(ui_menu_item, allocitems); for (int itemnum = 0; itemnum < olditems; itemnum++) newitems[itemnum] = item[itemnum]; - auto_free(machine(), item); + global_free(item); item = newitems; } index = numitems++; @@ -338,7 +338,7 @@ void *ui_menu::m_pool_alloc(size_t size) } // allocate a new pool - ppool = (ui_menu_pool *)auto_alloc_array_clear(machine(), UINT8, sizeof(*ppool) + UI_MENU_POOL_SIZE); + ppool = (ui_menu_pool *)global_alloc_array_clear(sizeof(*ppool) + UI_MENU_POOL_SIZE); // wire it up ppool->next = pool; @@ -948,7 +948,7 @@ void ui_menu::clear_free_list(running_machine &machine) { ui_menu *menu = menu_free; menu_free = menu->parent; - auto_free(machine, menu); + global_free(menu); } } @@ -1037,7 +1037,7 @@ UINT32 ui_menu::ui_handler(running_machine &machine, render_container *container { // if we have no menus stacked up, start with the main menu if (menu_stack == nullptr) - stack_push(auto_alloc_clear(machine, (machine, container))); + stack_push(global_alloc_clear(machine, container)); // update the menu state if (menu_stack != nullptr) diff --git a/src/emu/ui/selgame.cpp b/src/emu/ui/selgame.cpp index 9a080df6655..19af6e607d8 100644 --- a/src/emu/ui/selgame.cpp +++ b/src/emu/ui/selgame.cpp @@ -141,7 +141,7 @@ void ui_menu_select_game::inkey_select(const ui_menu_event *menu_event) // special case for configure inputs if ((FPTR)driver == 1) - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container))); + ui_menu::stack_push(global_alloc_clear(machine(), container)); // anything else is a driver else @@ -180,7 +180,7 @@ void ui_menu_select_game::inkey_cancel(const ui_menu_event *menu_event) if (m_search[0] != 0) { // since we have already been popped, we must recreate ourself from scratch - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, nullptr))); + ui_menu::stack_push(global_alloc_clear(machine(), container, nullptr)); } } @@ -429,10 +429,10 @@ void ui_menu_select_game::force_game_select(running_machine &machine, render_con ui_menu::stack_reset(machine); // add the quit entry followed by the game select entry - ui_menu *quit = auto_alloc_clear(machine, (machine, container)); + ui_menu *quit = global_alloc_clear(machine, container); quit->set_special_main_menu(true); ui_menu::stack_push(quit); - ui_menu::stack_push(auto_alloc_clear(machine, (machine, container, gamename))); + ui_menu::stack_push(global_alloc_clear(machine, container, gamename)); // force the menus on machine.ui().show_menu(); diff --git a/src/emu/ui/sliders.cpp b/src/emu/ui/sliders.cpp index 26da6327202..23bd9013dba 100644 --- a/src/emu/ui/sliders.cpp +++ b/src/emu/ui/sliders.cpp @@ -242,7 +242,7 @@ UINT32 ui_menu_sliders::ui_handler(running_machine &machine, render_container *c /* if this is the first call, push the sliders menu */ if (state) - ui_menu::stack_push(auto_alloc_clear(machine, (machine, container, true))); + ui_menu::stack_push(global_alloc_clear(machine, container, true)); /* handle standard menus */ result = ui_menu::ui_handler(machine, container, state); diff --git a/src/emu/ui/slotopt.cpp b/src/emu/ui/slotopt.cpp index cce17353532..a3b6352ac2b 100644 --- a/src/emu/ui/slotopt.cpp +++ b/src/emu/ui/slotopt.cpp @@ -204,7 +204,7 @@ void ui_menu_slot_devices::handle() device_slot_interface *slot = (device_slot_interface *)menu_event->itemref; device_slot_option *option = slot_get_current_option(slot); if (option) - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, slot, option))); + ui_menu::stack_push(global_alloc_clear(machine(), container, slot, option)); } } } diff --git a/src/emu/ui/swlist.cpp b/src/emu/ui/swlist.cpp index 64eb5109fae..d57c91fae40 100644 --- a/src/emu/ui/swlist.cpp +++ b/src/emu/ui/swlist.cpp @@ -448,7 +448,7 @@ void ui_menu_software::handle() const ui_menu_event *event = process(0); if (event != nullptr && event->iptkey == IPT_UI_SELECT) { - // ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, (software_list_config *)event->itemref, image))); + // ui_menu::stack_push(global_alloc_clear(machine(), container, (software_list_config *)event->itemref, image)); *m_result = (software_list_device *)event->itemref; ui_menu::stack_pop(machine()); } diff --git a/src/emu/ui/videoopt.cpp b/src/emu/ui/videoopt.cpp index e76c27305c8..aa3bc21dd5f 100644 --- a/src/emu/ui/videoopt.cpp +++ b/src/emu/ui/videoopt.cpp @@ -24,7 +24,7 @@ void ui_menu_video_targets::handle() /* process the menu */ const ui_menu_event *menu_event = process(0); if (menu_event != nullptr && menu_event->iptkey == IPT_UI_SELECT) - ui_menu::stack_push(auto_alloc_clear(machine(), (machine(), container, static_cast(menu_event->itemref)))); + ui_menu::stack_push(global_alloc_clear(machine(), container, static_cast(menu_event->itemref))); } diff --git a/src/mame/includes/chihiro.h b/src/mame/includes/chihiro.h index a9efcc711e3..0f68747059a 100644 --- a/src/mame/includes/chihiro.h +++ b/src/mame/includes/chihiro.h @@ -3,6 +3,8 @@ /* * geforce 3d (NV2A) vertex program disassembler */ +#include + class vertex_program_disassembler { static const char *srctypes[]; static const char *scaops[]; @@ -357,7 +359,6 @@ public: objectdata = &(object_data_alloc()); objectdata->data = this; combiner.used = 0; - combiner.lock = osd_lock_alloc(); enabled_vertex_attributes = 0; indexesleft_count = 0; vertex_pipeline = 4; @@ -626,7 +627,7 @@ public: } final; int stages; int used; - osd_lock *lock; + std::mutex lock; } combiner; UINT32 color_mask; bool alpha_test_enabled; diff --git a/src/mame/video/chihiro.cpp b/src/mame/video/chihiro.cpp index 9f803c45651..e6c8e578bb6 100644 --- a/src/mame/video/chihiro.cpp +++ b/src/mame/video/chihiro.cpp @@ -1953,7 +1953,7 @@ void nv2a_renderer::render_register_combiners(INT32 scanline, const extent_t &ex if ((extent.startx < 0) || (extent.stopx > 640)) return; - osd_lock_acquire(combiner.lock); // needed since multithreading is not supported yet + std::lock_guard lock(combiner.lock); // needed since multithreading is not supported yet x = extent.stopx - extent.startx - 1; // number of pixels to draw while (x >= 0) { xp = extent.startx + x; @@ -1998,7 +1998,6 @@ void nv2a_renderer::render_register_combiners(INT32 scanline, const extent_t &ex write_pixel(xp, scanline, a8r8g8b8, z); x--; } - osd_lock_release(combiner.lock); } #if 0 diff --git a/src/osd/modules/sound/xaudio2_sound.cpp b/src/osd/modules/sound/xaudio2_sound.cpp index 7df854c0364..9dc3d0461be 100644 --- a/src/osd/modules/sound/xaudio2_sound.cpp +++ b/src/osd/modules/sound/xaudio2_sound.cpp @@ -14,6 +14,7 @@ // standard windows headers #define WIN32_LEAN_AND_MEAN #include +#include #pragma warning( push ) #pragma warning( disable: 4068 ) @@ -124,21 +125,12 @@ public: obj->DestroyVoice(); } } - - void operator()(osd_lock* obj) const - { - if (obj != nullptr) - { - osd_lock_free(obj); - } - } }; // Typedefs for smart pointers used with customer deleters typedef std::unique_ptr xaudio2_ptr; typedef std::unique_ptr mastering_voice_ptr; typedef std::unique_ptr src_voice_ptr; -typedef std::unique_ptr osd_lock_ptr; // Typedef for pointer to XAudio2Create typedef HRESULT(__stdcall* PFN_XAUDIO2CREATE)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR); @@ -147,27 +139,6 @@ typedef HRESULT(__stdcall* PFN_XAUDIO2CREATE)(IXAudio2**, UINT32, XAUDIO2_PROCES // Helper classes //============================================================ -// Helper for locking within a particular scope without having to manually release -class osd_scoped_lock -{ -private: - osd_lock * m_lock; -public: - osd_scoped_lock(osd_lock* lock) - { - m_lock = lock; - osd_lock_acquire(m_lock); - } - - ~osd_scoped_lock() - { - if (m_lock != nullptr) - { - osd_lock_release(m_lock); - } - } -}; - // Provides a pool of buffers class bufferpool { @@ -233,7 +204,7 @@ private: DWORD m_buffer_size; DWORD m_buffer_count; DWORD m_writepos; - osd_lock_ptr m_buffer_lock; + std::mutex m_buffer_lock; HANDLE m_hEventBufferCompleted; HANDLE m_hEventDataAvailable; HANDLE m_hEventExiting; @@ -258,7 +229,6 @@ public: m_buffer_size(0), m_buffer_count(0), m_writepos(0), - m_buffer_lock(osd_lock_alloc()), m_hEventBufferCompleted(NULL), m_hEventDataAvailable(NULL), m_hEventExiting(NULL), @@ -389,7 +359,7 @@ void sound_xaudio2::update_audio_stream( UINT32 const bytes_this_frame = samples_this_frame * m_sample_bytes; - osd_scoped_lock scope_lock(m_buffer_lock.get()); + std::lock_guard lock(m_buffer_lock); UINT32 bytes_left = bytes_this_frame; @@ -446,7 +416,7 @@ void sound_xaudio2::OnBufferEnd(void *pBufferContext) BYTE* completed_buffer = (BYTE*)pBufferContext; if (completed_buffer != nullptr) { - auto scoped_lock = osd_scoped_lock(m_buffer_lock.get()); + std::lock_guard lock(m_buffer_lock); m_buffer_pool->return_to_pool(completed_buffer); } @@ -625,7 +595,7 @@ void sound_xaudio2::submit_needed() if (state.BuffersQueued >= 1) return; - osd_scoped_lock lock_scope(m_buffer_lock.get()); + std::lock_guard lock(m_buffer_lock); // Roll the buffer roll_buffer(); diff --git a/src/osd/modules/sync/osdsync.h b/src/osd/modules/sync/osdsync.h index 46d32b09135..e6e5e2f99c9 100644 --- a/src/osd/modules/sync/osdsync.h +++ b/src/osd/modules/sync/osdsync.h @@ -24,7 +24,7 @@ struct osd_event; /*----------------------------------------------------------------------------- - osd_lock_event_alloc: allocate a new event + osd_event_alloc: allocate a new event Parameters: @@ -174,18 +174,4 @@ int osd_thread_cpu_affinity(osd_thread *thread, UINT32 mask); -----------------------------------------------------------------------------*/ void osd_thread_wait_free(osd_thread *thread); -//============================================================ -// Scalable Locks -//============================================================ - -struct osd_scalable_lock; - -osd_scalable_lock *osd_scalable_lock_alloc(void); - -INT32 osd_scalable_lock_acquire(osd_scalable_lock *lock); - -void osd_scalable_lock_release(osd_scalable_lock *lock, INT32 myslot); - -void osd_scalable_lock_free(osd_scalable_lock *lock); - #endif /* __OSDSYNC__ */ diff --git a/src/osd/modules/sync/sync_mini.cpp b/src/osd/modules/sync/sync_mini.cpp index f5e6accb0c7..5829eb6d63c 100644 --- a/src/osd/modules/sync/sync_mini.cpp +++ b/src/osd/modules/sync/sync_mini.cpp @@ -19,63 +19,6 @@ struct _osd_thread { }; -//============================================================ -// osd_lock_alloc -//============================================================ - -osd_lock *osd_lock_alloc(void) -{ - // the minimal implementation does not support threading - // just return a dummy value here - return (osd_lock *)1; -} - - -//============================================================ -// osd_lock_acquire -//============================================================ - -void osd_lock_acquire(osd_lock *lock) -{ - // the minimal implementation does not support threading - // the acquire always "succeeds" -} - - -//============================================================ -// osd_lock_try -//============================================================ - -int osd_lock_try(osd_lock *lock) -{ - // the minimal implementation does not support threading - // the acquire always "succeeds" - return TRUE; -} - - -//============================================================ -// osd_lock_release -//============================================================ - -void osd_lock_release(osd_lock *lock) -{ - // the minimal implementation does not support threading - // do nothing here -} - - -//============================================================ -// osd_lock_free -//============================================================ - -void osd_lock_free(osd_lock *lock) -{ - // the minimal implementation does not support threading - // do nothing here -} - - //============================================================ // osd_event_alloc //============================================================ diff --git a/src/osd/modules/sync/sync_ntc.cpp b/src/osd/modules/sync/sync_ntc.cpp index 462c56ee434..c78f67ce64a 100644 --- a/src/osd/modules/sync/sync_ntc.cpp +++ b/src/osd/modules/sync/sync_ntc.cpp @@ -38,16 +38,6 @@ #include #include -struct osd_lock { - volatile pthread_t holder; - INT32 count; -#ifdef PTR64 - INT8 padding[52]; // Fill a 64-byte cache line -#else - INT8 padding[56]; // A bit more padding -#endif -}; - struct osd_event { pthread_mutex_t mutex; pthread_cond_t cond; @@ -69,275 +59,6 @@ struct osd_thread { pthread_t thread; }; -struct osd_scalable_lock -{ - struct - { - volatile INT32 haslock; // do we have the lock? - INT32 filler[64/4-1]; // assumes a 64-byte cache line - } slot[WORK_MAX_THREADS]; // one slot per thread - volatile INT32 nextindex; // index of next slot to use -}; - - -//============================================================ -// Scalable Locks -//============================================================ - -osd_scalable_lock *osd_scalable_lock_alloc(void) -{ - osd_scalable_lock *lock; - - lock = (osd_scalable_lock *)calloc(1, sizeof(*lock)); - if (lock == NULL) - return NULL; - - memset(lock, 0, sizeof(*lock)); - lock->slot[0].haslock = TRUE; - return lock; -} - - -INT32 osd_scalable_lock_acquire(osd_scalable_lock *lock) -{ - INT32 myslot = (atomic_increment32(&lock->nextindex) - 1) & (WORK_MAX_THREADS - 1); - -#if defined(__i386__) || defined(__x86_64__) - register INT32 tmp; - __asm__ __volatile__ ( - "1: clr %[tmp] ;" - " xchg %[haslock], %[tmp] ;" - " test %[tmp], %[tmp] ;" - " jne 3f ;" - "2: mov %[haslock], %[tmp] ;" - " test %[tmp], %[tmp] ;" - " jne 1b ;" - " pause ;" - " jmp 2b ;" - "3: " - : [haslock] "+m" (lock->slot[myslot].haslock) - , [tmp] "=&r" (tmp) - : - : "cc" - ); -#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__) - register INT32 tmp; - __asm__ __volatile__ ( - "1: lwarx %[tmp], 0, %[haslock] \n" - " cmpwi %[tmp], 0 \n" - " bne 3f \n" - "2: lwzx %[tmp], 0, %[haslock] \n" - " cmpwi %[tmp], 0 \n" - " bne 1b \n" - " nop \n" - " nop \n" - " b 2b \n" - "3: li %[tmp], 0 \n" - " stwcx. %[tmp], 0, %[haslock] \n" - " bne- 1b \n" - " lwsync \n" - : [tmp] "=&r" (tmp) - : [haslock] "r" (&lock->slot[myslot].haslock) - : "cr0" - ); -#else - INT32 backoff = 1; - while (!osd_compare_exchange32(&lock->slot[myslot].haslock, TRUE, FALSE)) - { - INT32 backcount; - for (backcount = 0; backcount < backoff; backcount++) - osd_yield_processor(); - backoff <<= 1; - } -#endif - return myslot; -} - - -void osd_scalable_lock_release(osd_scalable_lock *lock, INT32 myslot) -{ -#if defined(__i386__) || defined(__x86_64__) - register INT32 tmp = TRUE; - __asm__ __volatile__ ( - " xchg %[haslock], %[tmp] ;" - : [haslock] "+m" (lock->slot[(myslot + 1) & (WORK_MAX_THREADS - 1)].haslock) - , [tmp] "+r" (tmp) - : - ); -#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__) - lock->slot[(myslot + 1) & (WORK_MAX_THREADS - 1)].haslock = TRUE; - __asm__ __volatile__ ( " lwsync " : : ); -#else - osd_exchange32(&lock->slot[(myslot + 1) & (WORK_MAX_THREADS - 1)].haslock, TRUE); -#endif -} - -void osd_scalable_lock_free(osd_scalable_lock *lock) -{ - free(lock); -} - -static inline pthread_t osd_compare_exchange_pthread_t(pthread_t volatile *ptr, pthread_t compare, pthread_t exchange) -{ -#ifdef PTR64 - INT64 result = compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange); -#else - INT32 result = compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange); -#endif - return (pthread_t)result; -} - -static inline pthread_t osd_exchange_pthread_t(pthread_t volatile *ptr, pthread_t exchange) -{ -#ifdef PTR64 - INT64 result = osd_exchange64((INT64 volatile *)ptr, (INT64)exchange); -#else - INT32 result = atomic_exchange32((INT32 volatile *)ptr, (INT32)exchange); -#endif - return (pthread_t)result; -} - - -//============================================================ -// osd_lock_alloc -//============================================================ - -osd_lock *osd_lock_alloc(void) -{ - osd_lock *lock; - - lock = (osd_lock *)calloc(1, sizeof(osd_lock)); - if (lock == NULL) - return NULL; - - lock->holder = 0; - lock->count = 0; - - return lock; -} - -//============================================================ -// osd_lock_acquire -//============================================================ - -void osd_lock_acquire(osd_lock *lock) -{ - pthread_t current, prev; - - current = pthread_self(); - prev = osd_compare_exchange_pthread_t(&lock->holder, 0, current); - if (prev != nullptr && prev != current) - { - do { - register INT32 spin = 10000; // Convenient spin count - register pthread_t tmp; -#if defined(__i386__) || defined(__x86_64__) - __asm__ __volatile__ ( - "1: pause ;" - " mov %[holder], %[tmp] ;" - " test %[tmp], %[tmp] ;" - " loopne 1b ;" - : [spin] "+c" (spin) - , [tmp] "=&r" (tmp) - : [holder] "m" (lock->holder) - : "cc" - ); -#elif defined(__ppc__) || defined(__PPC__) - __asm__ __volatile__ ( - "1: nop \n" - " nop \n" - " lwzx %[tmp], 0, %[holder] \n" - " cmpwi %[tmp], 0 \n" - " bdnzt eq, 1b \n" - : [spin] "+c" (spin) - , [tmp] "=&r" (tmp) - : [holder] "r" (&lock->holder) - : "cr0" - ); -#elif defined(__ppc64__) || defined(__PPC64__) - __asm__ __volatile__ ( - "1: nop \n" - " nop \n" - " ldx %[tmp], 0, %[holder] \n" - " cmpdi %[tmp], 0 \n" - " bdnzt eq, 1b \n" - : [spin] "+c" (spin) - , [tmp] "=&r" (tmp) - : [holder] "r" (&lock->holder) - : "cr0" - ); -#else - while (--spin > 0 && lock->holder != NULL) - osd_yield_processor(); -#endif -#if 0 - /* If you mean to use locks as a blocking mechanism for extended - * periods of time, you should do something like this. However, - * it kills the performance of gaelco3d. - */ - if (spin == 0) - { - struct timespec sleep = { 0, 100000 }, remaining; - nanosleep(&sleep, &remaining); // sleep for 100us - } -#endif - } while (osd_compare_exchange_pthread_t(&lock->holder, 0, current) != nullptr); - } - lock->count++; -} - -//============================================================ -// osd_lock_try -//============================================================ - -int osd_lock_try(osd_lock *lock) -{ - pthread_t current, prev; - - current = pthread_self(); - prev = osd_compare_exchange_pthread_t(&lock->holder, 0, current); - if (prev == nullptr || prev == current) - { - lock->count++; - return 1; - } - return 0; -} - -//============================================================ -// osd_lock_release -//============================================================ - -void osd_lock_release(osd_lock *lock) -{ - pthread_t current; - - current = pthread_self(); - if (lock->holder == current) - { - if (--lock->count == 0) -#if defined(__ppc__) || defined(__PPC__) || defined(__ppc64__) || defined(__PPC64__) - lock->holder = 0; - __asm__ __volatile__( " lwsync " : : ); -#else - osd_exchange_pthread_t(&lock->holder, 0); -#endif - return; - } - - // trying to release a lock you don't hold is bad! -// assert(lock->holder == pthread_self()); -} - -//============================================================ -// osd_lock_free -//============================================================ - -void osd_lock_free(osd_lock *lock) -{ - free(lock); -} - //============================================================ // osd_event_alloc //============================================================ diff --git a/src/osd/modules/sync/sync_os2.cpp b/src/osd/modules/sync/sync_os2.cpp index dba34065610..6e3265bb198 100644 --- a/src/osd/modules/sync/sync_os2.cpp +++ b/src/osd/modules/sync/sync_os2.cpp @@ -31,16 +31,6 @@ #define pthread_t int #define pthread_self _gettid -struct osd_lock { - volatile pthread_t holder; - INT32 count; -#ifdef PTR64 - INT8 padding[52]; // Fill a 64-byte cache line -#else - INT8 padding[56]; // A bit more padding -#endif -}; - struct osd_event { HMTX hmtx; HEV hev; @@ -58,276 +48,6 @@ struct osd_thread { void *param; }; -struct osd_scalable_lock -{ - struct - { - volatile INT32 haslock; // do we have the lock? - INT32 filler[64/4-1]; // assumes a 64-byte cache line - } slot[WORK_MAX_THREADS]; // one slot per thread - volatile INT32 nextindex; // index of next slot to use -}; - - -//============================================================ -// Scalable Locks -//============================================================ - -osd_scalable_lock *osd_scalable_lock_alloc(void) -{ - osd_scalable_lock *lock; - - lock = (osd_scalable_lock *)calloc(1, sizeof(*lock)); - if (lock == NULL) - return NULL; - - memset(lock, 0, sizeof(*lock)); - lock->slot[0].haslock = TRUE; - return lock; -} - - -INT32 osd_scalable_lock_acquire(osd_scalable_lock *lock) -{ - INT32 myslot = (atomic_increment32(&lock->nextindex) - 1) & (WORK_MAX_THREADS - 1); - -#if defined(__i386__) || defined(__x86_64__) - register INT32 tmp; - __asm__ __volatile__ ( - "1: clr %[tmp] ;" - " xchg %[haslock], %[tmp] ;" - " test %[tmp], %[tmp] ;" - " jne 3f ;" - "2: mov %[haslock], %[tmp] ;" - " test %[tmp], %[tmp] ;" - " jne 1b ;" - " pause ;" - " jmp 2b ;" - "3: " - : [haslock] "+m" (lock->slot[myslot].haslock) - , [tmp] "=&r" (tmp) - : - : "%cc" - ); -#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__) - register INT32 tmp; - __asm__ __volatile__ ( - "1: lwarx %[tmp], 0, %[haslock] \n" - " cmpwi %[tmp], 0 \n" - " bne 3f \n" - "2: lwzx %[tmp], 0, %[haslock] \n" - " cmpwi %[tmp], 0 \n" - " bne 1b \n" - " nop \n" - " nop \n" - " b 2b \n" - "3: li %[tmp], 0 \n" - " sync \n" - " stwcx. %[tmp], 0, %[haslock] \n" - " bne- 1b \n" - " eieio \n" - : [tmp] "=&r" (tmp) - : [haslock] "r" (&lock->slot[myslot].haslock) - : "cr0" - ); -#else - INT32 backoff = 1; - while (!osd_compare_exchange32(&lock->slot[myslot].haslock, TRUE, FALSE)) - { - INT32 backcount; - for (backcount = 0; backcount < backoff; backcount++) - osd_yield_processor(); - backoff <<= 1; - } -#endif - return myslot; -} - - -void osd_scalable_lock_release(osd_scalable_lock *lock, INT32 myslot) -{ -#if defined(__i386__) || defined(__x86_64__) - register INT32 tmp = TRUE; - __asm__ __volatile__ ( - " xchg %[haslock], %[tmp] ;" - : [haslock] "+m" (lock->slot[(myslot + 1) & (WORK_MAX_THREADS - 1)].haslock) - , [tmp] "+r" (tmp) - : - ); -#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__) - lock->slot[(myslot + 1) & (WORK_MAX_THREADS - 1)].haslock = TRUE; - __asm__ __volatile__ ( " eieio " : : ); -#else - osd_exchange32(&lock->slot[(myslot + 1) & (WORK_MAX_THREADS - 1)].haslock, TRUE); -#endif -} - -void osd_scalable_lock_free(osd_scalable_lock *lock) -{ - free(lock); -} - -static inline pthread_t osd_compare_exchange_pthread_t(pthread_t volatile *ptr, pthread_t compare, pthread_t exchange) -{ -#ifdef PTR64 - INT64 result = compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange); -#else - INT32 result = compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange); -#endif - return (pthread_t)result; -} - -static inline pthread_t osd_exchange_pthread_t(pthread_t volatile *ptr, pthread_t exchange) -{ -#ifdef PTR64 - INT64 result = osd_exchange64((INT64 volatile *)ptr, (INT64)exchange); -#else - INT32 result = atomic_exchange32((INT32 volatile *)ptr, (INT32)exchange); -#endif - return (pthread_t)result; -} - - -//============================================================ -// osd_lock_alloc -//============================================================ - -osd_lock *osd_lock_alloc(void) -{ - osd_lock *lock; - - lock = (osd_lock *)calloc(1, sizeof(osd_lock)); - if (lock == NULL) - return NULL; - - lock->holder = 0; - lock->count = 0; - - return lock; -} - -//============================================================ -// osd_lock_acquire -//============================================================ - -void osd_lock_acquire(osd_lock *lock) -{ - pthread_t current, prev; - - current = pthread_self(); - prev = osd_compare_exchange_pthread_t(&lock->holder, 0, current); - if (prev != (size_t)NULL && prev != current) - { - do { - register INT32 spin = 10000; // Convenient spin count - register pthread_t tmp; -#if defined(__i386__) || defined(__x86_64__) - __asm__ __volatile__ ( - "1: pause ;" - " mov %[holder], %[tmp] ;" - " test %[tmp], %[tmp] ;" - " loopne 1b ;" - : [spin] "+c" (spin) - , [tmp] "=&r" (tmp) - : [holder] "m" (lock->holder) - : "%cc" - ); -#elif defined(__ppc__) || defined(__PPC__) - __asm__ __volatile__ ( - "1: nop \n" - " nop \n" - " lwzx %[tmp], 0, %[holder] \n" - " cmpwi %[tmp], 0 \n" - " bdnzt eq, 1b \n" - : [spin] "+c" (spin) - , [tmp] "=&r" (tmp) - : [holder] "r" (&lock->holder) - : "cr0" - ); -#elif defined(__ppc64__) || defined(__PPC64__) - __asm__ __volatile__ ( - "1: nop \n" - " nop \n" - " ldx %[tmp], 0, %[holder] \n" - " cmpdi %[tmp], 0 \n" - " bdnzt eq, 1b \n" - : [spin] "+c" (spin) - , [tmp] "=&r" (tmp) - : [holder] "r" (&lock->holder) - : "cr0" - ); -#else - while (--spin > 0 && lock->holder != NULL) - osd_yield_processor(); -#endif -#if 0 - /* If you mean to use locks as a blocking mechanism for extended - * periods of time, you should do something like this. However, - * it kills the performance of gaelco3d. - */ - if (spin == 0) - { - struct timespec sleep = { 0, 100000 }, remaining; - nanosleep(&sleep, &remaining); // sleep for 100us - } -#endif - } while (osd_compare_exchange_pthread_t(&lock->holder, 0, current) != (size_t)NULL); - } - lock->count++; -} - -//============================================================ -// osd_lock_try -//============================================================ - -int osd_lock_try(osd_lock *lock) -{ - pthread_t current, prev; - - current = pthread_self(); - prev = osd_compare_exchange_pthread_t(&lock->holder, 0, current); - if (prev == (size_t)NULL || prev == current) - { - lock->count++; - return 1; - } - return 0; -} - -//============================================================ -// osd_lock_release -//============================================================ - -void osd_lock_release(osd_lock *lock) -{ - pthread_t current; - - current = pthread_self(); - if (lock->holder == current) - { - if (--lock->count == 0) -#if defined(__ppc__) || defined(__PPC__) || defined(__ppc64__) || defined(__PPC64__) - lock->holder = 0; - __asm__ __volatile__( " eieio " : : ); -#else - osd_exchange_pthread_t(&lock->holder, 0); -#endif - return; - } - - // trying to release a lock you don't hold is bad! -// assert(lock->holder == pthread_self()); -} - -//============================================================ -// osd_lock_free -//============================================================ - -void osd_lock_free(osd_lock *lock) -{ - free(lock); -} - //============================================================ // osd_event_alloc //============================================================ diff --git a/src/osd/modules/sync/sync_sdl.cpp b/src/osd/modules/sync/sync_sdl.cpp index 90969b2a068..8a525723a45 100644 --- a/src/osd/modules/sync/sync_sdl.cpp +++ b/src/osd/modules/sync/sync_sdl.cpp @@ -51,138 +51,6 @@ struct osd_thread { void *param; }; -struct osd_scalable_lock -{ - SDL_mutex * mutex; -}; - -//============================================================ -// Scalable Locks -//============================================================ - -osd_scalable_lock *osd_scalable_lock_alloc(void) -{ - osd_scalable_lock *lock; - - lock = (osd_scalable_lock *)calloc(1, sizeof(*lock)); - if (lock == NULL) - return NULL; - - lock->mutex = SDL_CreateMutex(); - return lock; -} - - -INT32 osd_scalable_lock_acquire(osd_scalable_lock *lock) -{ - SDL_mutexP(lock->mutex); - return 0; -} - - -void osd_scalable_lock_release(osd_scalable_lock *lock, INT32 myslot) -{ - SDL_mutexV(lock->mutex); -} - -void osd_scalable_lock_free(osd_scalable_lock *lock) -{ - SDL_DestroyMutex(lock->mutex); - free(lock); -} - -//============================================================ -// osd_lock_alloc -//============================================================ - -osd_lock *osd_lock_alloc(void) -{ - hidden_mutex_t *mutex; - - mutex = (hidden_mutex_t *)calloc(1, sizeof(hidden_mutex_t)); - if (mutex == NULL) - return NULL; - - mutex->id = SDL_CreateMutex(); - - return (osd_lock *)mutex; -} - -//============================================================ -// osd_lock_acquire -//============================================================ - -void osd_lock_acquire(osd_lock *lock) -{ - hidden_mutex_t *mutex = (hidden_mutex_t *) lock; - - LOG(("osd_lock_acquire")); - /* get the lock */ - mutex->locked++; /* signal that we are *about* to lock - prevent osd_lock_try */ - SDL_mutexP(mutex->id); - mutex->threadid = SDL_ThreadID(); -} - -//============================================================ -// osd_lock_try -//============================================================ - -int osd_lock_try(osd_lock *lock) -{ - hidden_mutex_t *mutex = (hidden_mutex_t *) lock; - - LOG(("osd_lock_try")); - if (mutex->locked && mutex->threadid == SDL_ThreadID()) - { - /* get the lock */ - SDL_mutexP(mutex->id); - mutex->locked++; - mutex->threadid = SDL_ThreadID(); - return 1; - } - else if ((mutex->locked == 0)) - { - /* get the lock */ - mutex->locked++; - SDL_mutexP(mutex->id); - mutex->threadid = SDL_ThreadID(); - return 1; - } - else - { - /* fail */ - return 0; - } -} - -//============================================================ -// osd_lock_release -//============================================================ - -void osd_lock_release(osd_lock *lock) -{ - hidden_mutex_t *mutex = (hidden_mutex_t *) lock; - - LOG(("osd_lock_release")); - mutex->locked--; - if (mutex->locked == 0) - mutex->threadid = -1; - SDL_mutexV(mutex->id); -} - -//============================================================ -// osd_lock_free -//============================================================ - -void osd_lock_free(osd_lock *lock) -{ - hidden_mutex_t *mutex = (hidden_mutex_t *) lock; - - LOG(("osd_lock_free")); - //osd_lock_release(lock); - SDL_DestroyMutex(mutex->id); - free(mutex); -} //============================================================ // osd_event_alloc diff --git a/src/osd/modules/sync/sync_tc.cpp b/src/osd/modules/sync/sync_tc.cpp index 06dc699edce..64a6a760e96 100644 --- a/src/osd/modules/sync/sync_tc.cpp +++ b/src/osd/modules/sync/sync_tc.cpp @@ -58,123 +58,6 @@ struct osd_thread { pthread_t thread; }; -struct osd_scalable_lock -{ - osd_lock *lock; -}; - -//============================================================ -// Scalable Locks -//============================================================ - -osd_scalable_lock *osd_scalable_lock_alloc(void) -{ - osd_scalable_lock *lock; - - lock = (osd_scalable_lock *)calloc(1, sizeof(*lock)); - if (lock == NULL) - return NULL; - - lock->lock = osd_lock_alloc(); - return lock; -} - - -INT32 osd_scalable_lock_acquire(osd_scalable_lock *lock) -{ - osd_lock_acquire(lock->lock); - return 0; -} - - -void osd_scalable_lock_release(osd_scalable_lock *lock, INT32 myslot) -{ - osd_lock_release(lock->lock); -} - -void osd_scalable_lock_free(osd_scalable_lock *lock) -{ - osd_lock_free(lock->lock); - free(lock); -} - - -//============================================================ -// osd_lock_alloc -//============================================================ - -osd_lock *osd_lock_alloc(void) -{ - hidden_mutex_t *mutex; - pthread_mutexattr_t mtxattr; - - mutex = (hidden_mutex_t *)calloc(1, sizeof(hidden_mutex_t)); - if (mutex == NULL) - return NULL; - - pthread_mutexattr_init(&mtxattr); - pthread_mutexattr_settype(&mtxattr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&mutex->id, &mtxattr); - - return (osd_lock *)mutex; -} - -//============================================================ -// osd_lock_acquire -//============================================================ - -void osd_lock_acquire(osd_lock *lock) -{ - hidden_mutex_t *mutex = (hidden_mutex_t *) lock; - int r; - - r = pthread_mutex_lock(&mutex->id); - if (r==0) - return; - //osd_printf_error("Error on lock: %d: %s\n", r, strerror(r)); -} - -//============================================================ -// osd_lock_try -//============================================================ - -int osd_lock_try(osd_lock *lock) -{ - hidden_mutex_t *mutex = (hidden_mutex_t *) lock; - int r; - - r = pthread_mutex_trylock(&mutex->id); - if (r==0) - return 1; - //if (r!=EBUSY) - // osd_printf_error("Error on trylock: %d: %s\n", r, strerror(r)); - return 0; -} - -//============================================================ -// osd_lock_release -//============================================================ - -void osd_lock_release(osd_lock *lock) -{ - hidden_mutex_t *mutex = (hidden_mutex_t *) lock; - - pthread_mutex_unlock(&mutex->id); -} - -//============================================================ -// osd_lock_free -//============================================================ - -void osd_lock_free(osd_lock *lock) -{ - hidden_mutex_t *mutex = (hidden_mutex_t *) lock; - - //pthread_mutex_unlock(&mutex->id); - pthread_mutex_destroy(&mutex->id); - free(mutex); -} - //============================================================ // osd_event_alloc //============================================================ diff --git a/src/osd/modules/sync/sync_windows.cpp b/src/osd/modules/sync/sync_windows.cpp index 9439d68b72c..c744f345e6f 100644 --- a/src/osd/modules/sync/sync_windows.cpp +++ b/src/osd/modules/sync/sync_windows.cpp @@ -23,8 +23,6 @@ //============================================================ #define DEBUG_SLOW_LOCKS 0 -#define USE_SCALABLE_LOCKS (0) - //============================================================ @@ -33,11 +31,6 @@ typedef BOOL (WINAPI *try_enter_critical_section_ptr)(LPCRITICAL_SECTION lpCriticalSection); -struct osd_lock -{ - CRITICAL_SECTION critsect; -}; - struct osd_event { void * ptr; @@ -49,113 +42,6 @@ struct osd_thread { void *param; }; -struct osd_scalable_lock -{ -#if USE_SCALABLE_LOCKS - struct - { - volatile INT32 haslock; // do we have the lock? - INT32 filler[64/4-1]; // assumes a 64-byte cache line - } slot[WORK_MAX_THREADS]; // one slot per thread - volatile INT32 nextindex; // index of next slot to use -#else - CRITICAL_SECTION section; -#endif -}; - - -//============================================================ -// GLOBAL VARIABLES -//============================================================ - -static try_enter_critical_section_ptr try_enter_critical_section = nullptr; -static int checked_for_try_enter = FALSE; - - - -//============================================================ -// osd_lock_alloc -//============================================================ - -osd_lock *osd_lock_alloc(void) -{ - osd_lock *lock = (osd_lock *)malloc(sizeof(*lock)); - if (lock == nullptr) - return nullptr; - InitializeCriticalSection(&lock->critsect); - return lock; -} - - -//============================================================ -// osd_lock_acquire -//============================================================ - -void osd_lock_acquire(osd_lock *lock) -{ -#if DEBUG_SLOW_LOCKS - osd_ticks_t ticks = osd_ticks(); -#endif - - // block until we can acquire the lock - EnterCriticalSection(&lock->critsect); - -#if DEBUG_SLOW_LOCKS - // log any locks that take more than 1ms - ticks = osd_ticks() - ticks; - if (ticks > osd_ticks_per_second() / 1000) osd_printf_debug("Blocked %d ticks on lock acquire\n", (int)ticks); -#endif -} - - -//============================================================ -// osd_lock_try -//============================================================ - -int osd_lock_try(osd_lock *lock) -{ - int result = TRUE; - - // if we haven't yet checked for the TryEnter API, do it now - if (!checked_for_try_enter) - { - // see if we can use TryEnterCriticalSection - HMODULE library = LoadLibrary(TEXT("kernel32.dll")); - if (library != nullptr) - try_enter_critical_section = (try_enter_critical_section_ptr)GetProcAddress(library, "TryEnterCriticalSection"); - checked_for_try_enter = TRUE; - } - - // if we have it, use it, otherwise just block - if (try_enter_critical_section != nullptr) - result = (*try_enter_critical_section)(&lock->critsect); - else - EnterCriticalSection(&lock->critsect); - return result; -} - - -//============================================================ -// osd_lock_release -//============================================================ - -void osd_lock_release(osd_lock *lock) -{ - LeaveCriticalSection(&lock->critsect); -} - - -//============================================================ -// osd_lock_free -//============================================================ - -void osd_lock_free(osd_lock *lock) -{ - DeleteCriticalSection(&lock->critsect); - free(lock); -} - - //============================================================ // win_compare_exchange32 //============================================================ @@ -317,66 +203,3 @@ int osd_thread_cpu_affinity(osd_thread *thread, UINT32 mask) { return TRUE; } - -//============================================================ -// Scalable Locks -//============================================================ - -osd_scalable_lock *osd_scalable_lock_alloc(void) -{ - osd_scalable_lock *lock; - - lock = (osd_scalable_lock *)calloc(1, sizeof(*lock)); - if (lock == nullptr) - return nullptr; - - memset(lock, 0, sizeof(*lock)); -#if USE_SCALABLE_LOCKS - lock->slot[0].haslock = TRUE; -#else - InitializeCriticalSection(&lock->section); -#endif - return lock; -} - - -INT32 osd_scalable_lock_acquire(osd_scalable_lock *lock) -{ -#if USE_SCALABLE_LOCKS - INT32 myslot = (atomic_increment32(&lock->nextindex) - 1) & (WORK_MAX_THREADS - 1); - INT32 backoff = 1; - - while (!lock->slot[myslot].haslock) - { - INT32 backcount; - for (backcount = 0; backcount < backoff; backcount++) - osd_yield_processor(); - backoff <<= 1; - } - lock->slot[myslot].haslock = FALSE; - return myslot; -#else - EnterCriticalSection(&lock->section); - return 0; -#endif -} - - -void osd_scalable_lock_release(osd_scalable_lock *lock, INT32 myslot) -{ -#if USE_SCALABLE_LOCKS - atomic_exchange32(&lock->slot[(myslot + 1) & (WORK_MAX_THREADS - 1)].haslock, TRUE); -#else - LeaveCriticalSection(&lock->section); -#endif -} - - -void osd_scalable_lock_free(osd_scalable_lock *lock) -{ -#if USE_SCALABLE_LOCKS -#else - DeleteCriticalSection(&lock->section); -#endif - free(lock); -} diff --git a/src/osd/modules/sync/work_osd.cpp b/src/osd/modules/sync/work_osd.cpp index e5582584666..2d37feb0c56 100644 --- a/src/osd/modules/sync/work_osd.cpp +++ b/src/osd/modules/sync/work_osd.cpp @@ -18,6 +18,7 @@ #include #endif #endif +#include // MAME headers #include "osdcore.h" @@ -109,7 +110,7 @@ struct work_thread_info struct osd_work_queue { - osd_scalable_lock * lock; // lock for protecting the queue + std::mutex *lock; // lock for protecting the queue osd_work_item * volatile list; // list of items in the queue osd_work_item ** volatile tailptr; // pointer to the tail pointer of work items in the queue osd_work_item * volatile free; // free list of work items @@ -188,7 +189,7 @@ osd_work_queue *osd_work_queue_alloc(int flags) goto error; // initialize the critical section - queue->lock = osd_scalable_lock_alloc(); + queue->lock = new std::mutex(); if (queue->lock == NULL) goto error; @@ -421,7 +422,7 @@ void osd_work_queue_free(osd_work_queue *queue) printf("Spin loops = %9d\n", queue->spinloops); #endif - osd_scalable_lock_free(queue->lock); + delete queue->lock; // free the queue itself osd_free(queue); } @@ -435,7 +436,6 @@ osd_work_item *osd_work_item_queue_multiple(osd_work_queue *queue, osd_work_call { osd_work_item *itemlist = NULL, *lastitem = NULL; osd_work_item **item_tailptr = &itemlist; - INT32 lockslot; int itemnum; // loop over items, building up a local list of work @@ -444,12 +444,13 @@ osd_work_item *osd_work_item_queue_multiple(osd_work_queue *queue, osd_work_call osd_work_item *item; // first allocate a new work item; try the free list first - INT32 myslot = osd_scalable_lock_acquire(queue->lock); - do { - item = (osd_work_item *)queue->free; - } while (item != NULL && compare_exchange_ptr((PVOID volatile *)&queue->free, item, item->next) != item); - osd_scalable_lock_release(queue->lock, myslot); + std::lock_guard(*queue->lock); + do + { + item = (osd_work_item *)queue->free; + } while (item != NULL && compare_exchange_ptr((PVOID volatile *)&queue->free, item, item->next) != item); + } // if nothing, allocate something new if (item == NULL) @@ -482,10 +483,11 @@ osd_work_item *osd_work_item_queue_multiple(osd_work_queue *queue, osd_work_call } // enqueue the whole thing within the critical section - lockslot = osd_scalable_lock_acquire(queue->lock); - *queue->tailptr = itemlist; - queue->tailptr = item_tailptr; - osd_scalable_lock_release(queue->lock, lockslot); + { + std::lock_guard(*queue->lock); + *queue->tailptr = itemlist; + queue->tailptr = item_tailptr; + } // increment the number of items in the queue atomic_add32(&queue->items, numitems); @@ -539,9 +541,8 @@ int osd_work_item_wait(osd_work_item *item, osd_ticks_t timeout) // if we don't have an event, create one if (item->event == NULL) { - INT32 lockslot = osd_scalable_lock_acquire(item->queue->lock); + std::lock_guard(*item->queue->lock); item->event = osd_event_alloc(TRUE, FALSE); // manual reset, not signalled - osd_scalable_lock_release(item->queue->lock, lockslot); } else osd_event_reset(item->event); @@ -584,13 +585,12 @@ void osd_work_item_release(osd_work_item *item) osd_work_item_wait(item, 100 * osd_ticks_per_second()); // add us to the free list on our queue - INT32 lockslot = osd_scalable_lock_acquire(item->queue->lock); + std::lock_guard(*item->queue->lock); do { next = (osd_work_item *)item->queue->free; item->next = next; } while (compare_exchange_ptr((PVOID volatile *)&item->queue->free, next, item) != next); - osd_scalable_lock_release(item->queue->lock, lockslot); } @@ -711,7 +711,7 @@ static void worker_thread_process(osd_work_queue *queue, work_thread_info *threa // use a critical section to synchronize the removal of items { - INT32 lockslot = osd_scalable_lock_acquire(queue->lock); + std::lock_guard(*queue->lock); if (queue->list == NULL) { end_loop = true; @@ -727,7 +727,6 @@ static void worker_thread_process(osd_work_queue *queue, work_thread_info *threa queue->tailptr = (osd_work_item **)&queue->list; } } - osd_scalable_lock_release(queue->lock, lockslot); } if (end_loop) @@ -753,13 +752,12 @@ static void worker_thread_process(osd_work_queue *queue, work_thread_info *threa // set the result and signal the event else { - INT32 lockslot = osd_scalable_lock_acquire(item->queue->lock); + std::lock_guard(*queue->lock); if (item->event != NULL) { osd_event_set(item->event); add_to_stat(&item->queue->setevents, 1); } - osd_scalable_lock_release(item->queue->lock, lockslot); } // if we removed an item and there's still work to do, bump the stats @@ -780,8 +778,7 @@ static void worker_thread_process(osd_work_queue *queue, work_thread_info *threa bool queue_has_list_items(osd_work_queue *queue) { - INT32 lockslot = osd_scalable_lock_acquire(queue->lock); + std::lock_guard(*queue->lock); bool has_list_items = (queue->list != NULL); - osd_scalable_lock_release(queue->lock, lockslot); return has_list_items; } diff --git a/src/osd/osdcore.h b/src/osd/osdcore.h index 0a4f351e5e9..cd08fa8aa4e 100644 --- a/src/osd/osdcore.h +++ b/src/osd/osdcore.h @@ -440,93 +440,6 @@ osd_ticks_t osd_ticks_per_second(void); -----------------------------------------------------------------------------*/ void osd_sleep(osd_ticks_t duration); - - -/*************************************************************************** - SYNCHRONIZATION INTERFACES -***************************************************************************/ - -/* osd_lock is an opaque type which represents a recursive lock/mutex */ -struct osd_lock; - - -/*----------------------------------------------------------------------------- - osd_lock_alloc: allocate a new lock - - Parameters: - - None. - - Return value: - - A pointer to the allocated lock. ------------------------------------------------------------------------------*/ -osd_lock *osd_lock_alloc(void); - - -/*----------------------------------------------------------------------------- - osd_lock_acquire: acquire a lock, blocking until it can be acquired - - Parameters: - - lock - a pointer to a previously allocated osd_lock. - - Return value: - - None. - - Notes: - - osd_locks are defined to be recursive. If the current thread already - owns the lock, this function should return immediately. ------------------------------------------------------------------------------*/ -void osd_lock_acquire(osd_lock *lock); - - -/*----------------------------------------------------------------------------- - osd_lock_try: attempt to acquire a lock - - Parameters: - - lock - a pointer to a previously allocated osd_lock. - - Return value: - - TRUE if the lock was available and was acquired successfully. - FALSE if the lock was already in used by another thread. ------------------------------------------------------------------------------*/ -int osd_lock_try(osd_lock *lock); - - -/*----------------------------------------------------------------------------- - osd_lock_release: release control of a lock that has been acquired - - Parameters: - - lock - a pointer to a previously allocated osd_lock. - - Return value: - - None. ------------------------------------------------------------------------------*/ -void osd_lock_release(osd_lock *lock); - - -/*----------------------------------------------------------------------------- - osd_lock_free: free the memory and resources associated with an osd_lock - - Parameters: - - lock - a pointer to a previously allocated osd_lock. - - Return value: - - None. ------------------------------------------------------------------------------*/ -void osd_lock_free(osd_lock *lock); - - - /*************************************************************************** WORK ITEM INTERFACES ***************************************************************************/ diff --git a/src/osd/osdmini/minisync.cpp b/src/osd/osdmini/minisync.cpp deleted file mode 100644 index a78765f29ed..00000000000 --- a/src/osd/osdmini/minisync.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -//============================================================ -// -// minisync.c - Minimal core synchronization functions -// -//============================================================ - -#include "osdcore.h" - - -//============================================================ -// osd_lock_alloc -//============================================================ - -osd_lock *osd_lock_alloc(void) -{ - // the minimal implementation does not support threading - // just return a dummy value here - return (osd_lock *)1; -} - - -//============================================================ -// osd_lock_acquire -//============================================================ - -void osd_lock_acquire(osd_lock *lock) -{ - // the minimal implementation does not support threading - // the acquire always "succeeds" -} - - -//============================================================ -// osd_lock_try -//============================================================ - -int osd_lock_try(osd_lock *lock) -{ - // the minimal implementation does not support threading - // the acquire always "succeeds" - return TRUE; -} - - -//============================================================ -// osd_lock_release -//============================================================ - -void osd_lock_release(osd_lock *lock) -{ - // the minimal implementation does not support threading - // do nothing here -} - - -//============================================================ -// osd_lock_free -//============================================================ - -void osd_lock_free(osd_lock *lock) -{ - // the minimal implementation does not support threading - // do nothing here -} diff --git a/src/osd/sdl/input.cpp b/src/osd/sdl/input.cpp index 4dfb5bd0ad0..b0d4d8c1096 100644 --- a/src/osd/sdl/input.cpp +++ b/src/osd/sdl/input.cpp @@ -15,6 +15,7 @@ #include "sdlinc.h" #include #include +#include #if USE_XINPUT // for xinput @@ -154,7 +155,7 @@ struct device_info //============================================================ // global states -static osd_lock * input_lock; +static std::mutex input_lock; static UINT8 input_paused; static sdl_window_info * focus_window = NULL; @@ -1380,10 +1381,6 @@ bool sdl_osd_interface::input_init() app_has_mouse_focus = 1; - // allocate a lock for input synchronizations - input_lock = osd_lock_alloc(); - assert_always(input_lock != NULL, "Failed to allocate input_lock"); - // register the keyboards sdlinput_register_keyboards(machine()); @@ -1441,9 +1438,6 @@ void sdl_osd_interface::input_resume() void sdl_osd_interface::input_exit() { - // free the lock - osd_lock_free(input_lock); - // deregister sdlinput_deregister_joysticks(machine()); @@ -1568,7 +1562,7 @@ void sdlinput_process_events_buf() if (SDLMAME_EVENTS_IN_WORKER_THREAD) { - osd_lock_acquire(input_lock); + std::lock_guard lock(input_lock); #if (SDLMAME_SDL2) /* Make sure we get all pending events */ SDL_PumpEvents(); @@ -1580,7 +1574,6 @@ void sdlinput_process_events_buf() else osd_printf_warning("Event Buffer Overflow!\n"); } - osd_lock_release(input_lock); } else SDL_PumpEvents(); @@ -1709,11 +1702,10 @@ void sdlinput_poll(running_machine &machine) if (SDLMAME_EVENTS_IN_WORKER_THREAD) { - osd_lock_acquire(input_lock); + std::lock_guard lock(input_lock); memcpy(loc_event_buf, event_buf, sizeof(event_buf)); loc_event_buf_count = event_buf_count; event_buf_count = 0; - osd_lock_release(input_lock); bufp = 0; } diff --git a/src/osd/windows/input.cpp b/src/osd/windows/input.cpp index 77adda7a2ca..9157036ffd5 100644 --- a/src/osd/windows/input.cpp +++ b/src/osd/windows/input.cpp @@ -39,6 +39,7 @@ #include "config.h" #include "winutil.h" +#include //============================================================ // PARAMETERS @@ -166,7 +167,7 @@ typedef /*WINUSERAPI*/ BOOL (WINAPI *register_rawinput_devices_ptr)(IN PCRAWINPU // global states static bool input_enabled; -static osd_lock * input_lock; +static std::mutex input_lock; static bool input_paused; static DWORD last_poll; @@ -469,10 +470,6 @@ static inline INT32 normalize_absolute_axis(INT32 raw, INT32 rawmin, INT32 rawma bool windows_osd_interface::input_init() { - // allocate a lock for input synchronizations, since messages sometimes come from another thread - input_lock = osd_lock_alloc(); - assert_always(input_lock != NULL, "Failed to allocate input_lock"); - // decode the options lightgun_shared_axis_mode = downcast(machine().options()).dual_lightgun(); @@ -512,15 +509,8 @@ void windows_osd_interface::input_resume() void windows_osd_interface::input_exit() { // acquire the lock and turn off input (this ensures everyone is done) - if (input_lock != NULL) - { - osd_lock_acquire(input_lock); - input_enabled = false; - osd_lock_release(input_lock); - - // free the lock - osd_lock_free(input_lock); - } + std::lock_guard lock(input_lock); + input_enabled = false; } @@ -613,7 +603,7 @@ BOOL wininput_handle_mouse_button(int button, int down, int x, int y) } // take the lock - osd_lock_acquire(input_lock); + std::lock_guard lock(input_lock); // set the button state devinfo->mouse.state.rgbButtons[button] = down ? 0x80 : 0x00; @@ -632,9 +622,6 @@ BOOL wininput_handle_mouse_button(int button, int down, int x, int y) devinfo->mouse.state.lX = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right); devinfo->mouse.state.lY = normalize_absolute_axis(mousepos.y, client_rect.top, client_rect.bottom); } - - // release the lock - osd_lock_release(input_lock); return TRUE; } @@ -675,18 +662,16 @@ BOOL wininput_handle_raw(HANDLE device) // handle keyboard input if (input->header.dwType == RIM_TYPEKEYBOARD) { - osd_lock_acquire(input_lock); + std::lock_guard lock(input_lock); rawinput_keyboard_update(input->header.hDevice, &input->data.keyboard); - osd_lock_release(input_lock); result = TRUE; } // handle mouse input else if (input->header.dwType == RIM_TYPEMOUSE) { - osd_lock_acquire(input_lock); + std::lock_guard lock(input_lock); rawinput_mouse_update(input->header.hDevice, &input->data.mouse); - osd_lock_release(input_lock); result = TRUE; } } @@ -2201,14 +2186,13 @@ static void rawinput_mouse_poll(device_info *devinfo) poll_if_necessary(devinfo->machine()); // copy the accumulated raw state to the actual state - osd_lock_acquire(input_lock); + std::lock_guard lock(input_lock); devinfo->mouse.state.lX = devinfo->mouse.raw_x; devinfo->mouse.state.lY = devinfo->mouse.raw_y; devinfo->mouse.state.lZ = devinfo->mouse.raw_z; devinfo->mouse.raw_x = 0; devinfo->mouse.raw_y = 0; devinfo->mouse.raw_z = 0; - osd_lock_release(input_lock); } diff --git a/src/osd/windows/window.cpp b/src/osd/windows/window.cpp index 6111859a255..046211d4f29 100644 --- a/src/osd/windows/window.cpp +++ b/src/osd/windows/window.cpp @@ -300,7 +300,6 @@ win_window_info::win_window_info(running_machine &machine) m_fullscreen(0), m_fullscreen_safe(0), m_aspect(0), - m_render_lock(NULL), m_target(NULL), m_targetview(0), m_targetorient(0), @@ -672,9 +671,6 @@ void win_window_info::create(running_machine &machine, int index, osd_monitor_in *last_window_ptr = window; last_window_ptr = &window->m_next; - // create a lock that we can use to skip blitting - window->m_render_lock = osd_lock_alloc(); - // load the layout window->m_target = machine.render().target_alloc(); @@ -746,11 +742,6 @@ void win_window_info::destroy() // free the render target machine().render().target_free(m_target); - - // FIXME: move to destructor - // free the lock - osd_lock_free(m_render_lock); - } @@ -798,9 +789,9 @@ void win_window_info::update() // only block if we're throttled if (machine().video().throttled() || timeGetTime() - last_update_time > 250) - osd_lock_acquire(m_render_lock); + m_render_lock.lock(); else - got_lock = osd_lock_try(m_render_lock); + got_lock = m_render_lock.try_lock(); // only render if we were able to get the lock if (got_lock) @@ -810,7 +801,7 @@ void win_window_info::update() mtlog_add("winwindow_video_window_update: got lock"); // don't hold the lock; we just used it to see if rendering was still happening - osd_lock_release(m_render_lock); + m_render_lock.unlock(); // ensure the target bounds are up-to-date, and then get the primitives primlist = m_renderer->get_primitives(); @@ -1492,7 +1483,7 @@ void win_window_info::draw_video_contents(HDC dc, int update) mtlog_add("draw_video_contents: begin"); mtlog_add("draw_video_contents: render lock acquire"); - osd_lock_acquire(m_render_lock); + std::lock_guard lock(m_render_lock); mtlog_add("draw_video_contents: render lock acquired"); // if we're iconic, don't bother @@ -1516,7 +1507,6 @@ void win_window_info::draw_video_contents(HDC dc, int update) } } - osd_lock_release(m_render_lock); mtlog_add("draw_video_contents: render lock released"); mtlog_add("draw_video_contents: end"); diff --git a/src/osd/windows/window.h b/src/osd/windows/window.h index 62d4f57db55..6a925494f93 100644 --- a/src/osd/windows/window.h +++ b/src/osd/windows/window.h @@ -9,6 +9,7 @@ #ifndef __WIN_WINDOW__ #define __WIN_WINDOW__ +#include #include "video.h" #include "render.h" @@ -92,7 +93,7 @@ public: float m_aspect; // rendering info - osd_lock * m_render_lock; + std::mutex m_render_lock; render_target * m_target; int m_targetview; int m_targetorient; -- cgit v1.2.3-70-g09d2 From f5be205f6ecb1916cde9228d638a8d61239743ec Mon Sep 17 00:00:00 2001 From: hap Date: Sat, 30 Jan 2016 23:52:58 +0100 Subject: fix a mutex regression (this doesn't fix the lockups i'm seeing) --- src/emu/luaengine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/emu/luaengine.cpp') diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp index f487c02bed6..c4136cd744a 100644 --- a/src/emu/luaengine.cpp +++ b/src/emu/luaengine.cpp @@ -848,7 +848,7 @@ void lua_engine::serve_lua() // Do action on client side { - osd_sleep(osd_ticks_per_second() / 1000); + std::lock_guard lock(g_mutex); if (msg.status == -1) { b = LUA_PROMPT2; -- cgit v1.2.3-70-g09d2