diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/sound/discrete.cpp | 8 | ||||
-rw-r--r-- | src/devices/video/poly.h | 7 | ||||
-rw-r--r-- | src/devices/video/polylgcy.cpp | 8 | ||||
-rw-r--r-- | src/mame/machine/gaelco3d.cpp | 66 | ||||
-rw-r--r-- | src/mame/machine/gaelco3d.h | 3 | ||||
-rw-r--r-- | src/osd/eminline.h | 16 | ||||
-rw-r--r-- | src/osd/sdl/watchdog.cpp | 2 | ||||
-rw-r--r-- | src/osd/sdl/watchdog.h | 3 | ||||
-rw-r--r-- | src/osd/windows/window.cpp | 9 |
9 files changed, 44 insertions, 78 deletions
diff --git a/src/devices/sound/discrete.cpp b/src/devices/sound/discrete.cpp index 22b5ebe942a..926db3a4a40 100644 --- a/src/devices/sound/discrete.cpp +++ b/src/devices/sound/discrete.cpp @@ -38,6 +38,7 @@ #include "emu.h" #include "sound/wavwrite.h" #include "discrete.h" +#include <atomic> /* for_each collides with c++ standard libraries - include it here */ #define for_each(_T, _e, _l) for (_T _e = (_l)->begin_ptr() ; _e <= (_l)->end_ptr(); _e++) @@ -110,9 +111,8 @@ public: inline void step_nodes(void); inline bool lock_threadid(INT32 threadid) { - INT32 prev_id; - prev_id = compare_exchange32(&m_threadid, -1, threadid); - return (prev_id == -1 && m_threadid == threadid); + int expected = -1; + return m_threadid.compare_exchange_weak(expected, threadid, std::memory_order_release,std::memory_order_relaxed); } inline void unlock(void) { m_threadid = -1; } @@ -144,7 +144,7 @@ protected: discrete_device & m_device; private: - volatile INT32 m_threadid; + std::atomic<INT32> m_threadid; volatile int m_samples; }; diff --git a/src/devices/video/poly.h b/src/devices/video/poly.h index 2ecc72491f7..e5739e39570 100644 --- a/src/devices/video/poly.h +++ b/src/devices/video/poly.h @@ -38,6 +38,7 @@ #define __POLY_H__ #include <limits.h> +#include <atomic> //************************************************************************** // DEBUGGING @@ -165,7 +166,7 @@ private: // internal unit of work struct work_unit { - volatile UINT32 count_next; // number of scanlines and index of next item to process + std::atomic<UINT32> count_next; // number of scanlines and index of next item to process polygon_info * polygon; // pointer to polygon INT16 scanline; // starting scanline UINT16 previtem; // index of previous item in the same bucket @@ -405,7 +406,7 @@ void *poly_manager<_BaseType, _ObjectData, _MaxParams, _MaxPolys>::work_item_cal { orig_count_next = prevunit.count_next; new_count_next = orig_count_next | (unitnum << 16); - } while (compare_exchange32((volatile INT32 *)&prevunit.count_next, orig_count_next, new_count_next) != orig_count_next); + } while (!prevunit.count_next.compare_exchange_weak(orig_count_next, new_count_next, std::memory_order_release, std::memory_order_relaxed)); #if KEEP_POLY_STATISTICS // track resolved conflicts @@ -427,7 +428,7 @@ void *poly_manager<_BaseType, _ObjectData, _MaxParams, _MaxPolys>::work_item_cal do { orig_count_next = unit.count_next; - } while (compare_exchange32((volatile INT32 *)&unit.count_next, orig_count_next, 0) != orig_count_next); + } while (!unit.count_next.compare_exchange_weak(orig_count_next, 0, std::memory_order_release, std::memory_order_relaxed)); // if we have no more work to do, do nothing orig_count_next >>= 16; diff --git a/src/devices/video/polylgcy.cpp b/src/devices/video/polylgcy.cpp index b5daf5a924b..25dd61aa733 100644 --- a/src/devices/video/polylgcy.cpp +++ b/src/devices/video/polylgcy.cpp @@ -10,7 +10,7 @@ #include "emu.h" #include "polylgcy.h" - +#include <atomic> /*************************************************************************** DEBUGGING @@ -88,7 +88,7 @@ struct poly_section struct work_unit_shared { polygon_info * polygon; /* pointer to polygon */ - volatile UINT32 count_next; /* number of scanlines and index of next item to process */ + std::atomic<UINT32> count_next; /* number of scanlines and index of next item to process */ INT16 scanline; /* starting scanline and count */ UINT16 previtem; /* index of previous item in the same bucket */ #ifndef PTR64 @@ -1305,7 +1305,7 @@ static void *poly_item_callback(void *param, int threadid) { orig_count_next = prevunit->shared.count_next; new_count_next = orig_count_next | (unitnum << 16); - } while (compare_exchange32((volatile INT32 *)&prevunit->shared.count_next, orig_count_next, new_count_next) != orig_count_next); + } while (!prevunit->shared.count_next.compare_exchange_weak(orig_count_next, new_count_next, std::memory_order_release, std::memory_order_relaxed)); #if KEEP_STATISTICS /* track resolved conflicts */ @@ -1336,7 +1336,7 @@ static void *poly_item_callback(void *param, int threadid) do { orig_count_next = unit->shared.count_next; - } while (compare_exchange32((volatile INT32 *)&unit->shared.count_next, orig_count_next, 0) != orig_count_next); + } while (!unit->shared.count_next.compare_exchange_weak(orig_count_next, 0, std::memory_order_release, std::memory_order_relaxed)); /* if we have no more work to do, do nothing */ orig_count_next >>= 16; diff --git a/src/mame/machine/gaelco3d.cpp b/src/mame/machine/gaelco3d.cpp index d4f9c58383a..138a7c818c6 100644 --- a/src/mame/machine/gaelco3d.cpp +++ b/src/mame/machine/gaelco3d.cpp @@ -155,22 +155,6 @@ static void *osd_sharedmem_ptr(osd_shared_mem *os_shmem) #endif /*************************************************************************** - INLINE FUNCTIONS -***************************************************************************/ - -static inline void shmem_lock(shmem_t *shmem) -{ - while (atomic_exchange32(&shmem->lock,1) == 0) - ; -} - -static inline void shmem_unlock(shmem_t *shmem) -{ - atomic_exchange32(&shmem->lock,0); -} - - -/*************************************************************************** DEVICE INTERFACE ***************************************************************************/ @@ -248,10 +232,9 @@ void gaelco_serial_device::device_reset() m_last_in_msg_cnt = -1; m_slack_cnt = LINK_SLACK_B; - shmem_lock(m_shmem); + std::lock_guard<std::mutex> guard(m_mutex); buf_reset(m_out_ptr); buf_reset(m_in_ptr); - shmem_unlock(m_shmem); } //------------------------------------------------- @@ -260,11 +243,11 @@ void gaelco_serial_device::device_reset() void gaelco_serial_device::device_stop() { - shmem_lock(m_shmem); - buf_reset(m_out_ptr); - buf_reset(m_in_ptr); - shmem_unlock(m_shmem); - + { + std::lock_guard<std::mutex> guard(m_mutex); + buf_reset(m_out_ptr); + buf_reset(m_in_ptr); + } osd_sharedmem_free(m_os_shmem); } @@ -313,7 +296,8 @@ void gaelco_serial_device::sync_link() int breakme = 1; do { - shmem_lock(m_shmem); + std::lock_guard<std::mutex> guard(m_mutex); + process_in(); /* HACK: put some timing noise on the line */ if (buf->cnt + m_slack_cnt > m_out_ptr->cnt) @@ -321,23 +305,23 @@ void gaelco_serial_device::sync_link() /* stop if not connected .. */ if ((m_out_ptr->stat & GAELCOSER_STATUS_RESET) != 0) breakme = 0; - shmem_unlock(m_shmem); + } while (breakme); m_slack_cnt++; m_slack_cnt = (m_slack_cnt % LINK_SLACK) + LINK_SLACK_B; - shmem_lock(m_shmem); - m_out_ptr->stat &= ~GAELCOSER_STATUS_RESET; - shmem_unlock(m_shmem); + { + std::lock_guard<std::mutex> guard(m_mutex); + m_out_ptr->stat &= ~GAELCOSER_STATUS_RESET; + } } TIMER_CALLBACK_MEMBER( gaelco_serial_device::link_cb ) { - shmem_lock(m_shmem); + std::lock_guard<std::mutex> guard(m_mutex); m_out_ptr->cnt++; sync_link(); - shmem_unlock(m_shmem); } @@ -356,19 +340,20 @@ READ8_MEMBER( gaelco_serial_device::status_r) { UINT8 ret = 0; - shmem_lock(m_shmem); + std::lock_guard<std::mutex> guard(m_mutex); + process_in(); if ((m_status & GAELCOSER_STATUS_READY) != 0) ret |= 0x01; if ((m_in_ptr->stat & GAELCOSER_STATUS_RTS) != 0) ret |= 0x02; - shmem_unlock(m_shmem); + return ret; } WRITE8_MEMBER( gaelco_serial_device::data_w) { - shmem_lock(m_shmem); + std::lock_guard<std::mutex> guard(m_mutex); m_out_ptr->data = data; m_status &= ~GAELCOSER_STATUS_READY; @@ -376,7 +361,6 @@ WRITE8_MEMBER( gaelco_serial_device::data_w) set_status( ~GAELCOSER_STATUS_READY, GAELCOSER_STATUS_READY, LINK_FREQ ); - shmem_unlock(m_shmem); LOGMSG(("command send %02x at %d\n", data, m_out_ptr->cnt)); } @@ -384,7 +368,7 @@ READ8_MEMBER( gaelco_serial_device::data_r) { UINT8 ret; - shmem_lock(m_shmem); + std::lock_guard<std::mutex> guard(m_mutex); process_in(); ret = (m_in_ptr->data & 0xff); @@ -395,21 +379,19 @@ READ8_MEMBER( gaelco_serial_device::data_r) if ((m_status & GAELCOSER_STATUS_SEND) == 0) m_status |= GAELCOSER_STATUS_READY; - shmem_unlock(m_shmem); return ret; } WRITE8_MEMBER( gaelco_serial_device::unknown_w) { - shmem_lock(m_shmem); + std::lock_guard<std::mutex> guard(m_mutex); LOGMSG(("???? unknown serial access %d\n", data)); - shmem_unlock(m_shmem); } WRITE8_MEMBER( gaelco_serial_device::rts_w ) { - shmem_lock(m_shmem); + std::lock_guard<std::mutex> guard(m_mutex); if (data == 0) m_out_ptr->stat |= GAELCOSER_STATUS_RTS; @@ -419,18 +401,14 @@ WRITE8_MEMBER( gaelco_serial_device::rts_w ) //m_status |= GAELCOSER_STATUS_READY; m_out_ptr->stat &= ~GAELCOSER_STATUS_RTS; } - - shmem_unlock(m_shmem); } WRITE8_MEMBER( gaelco_serial_device::tr_w) { LOGMSG(("set transmit %d\n", data)); - shmem_lock(m_shmem); + std::lock_guard<std::mutex> guard(m_mutex); if ((data & 0x01) != 0) m_status |= GAELCOSER_STATUS_SEND; else m_status &= ~GAELCOSER_STATUS_SEND; - - shmem_unlock(m_shmem); } diff --git a/src/mame/machine/gaelco3d.h b/src/mame/machine/gaelco3d.h index 36ab65082f1..1c1eec722d3 100644 --- a/src/mame/machine/gaelco3d.h +++ b/src/mame/machine/gaelco3d.h @@ -7,7 +7,6 @@ ***************************************************************************/ - /*************************************************************************** DEVICE CONFIGURATION MACROS ***************************************************************************/ @@ -47,7 +46,6 @@ struct buf_t struct shmem_t { - volatile INT32 lock; buf_t buf[2]; }; @@ -106,6 +104,7 @@ private: buf_t *m_out_ptr; osd_shared_mem *m_os_shmem; shmem_t *m_shmem; + std::mutex m_mutex; TIMER_CALLBACK_MEMBER( set_status_cb ); TIMER_CALLBACK_MEMBER( link_cb ); diff --git a/src/osd/eminline.h b/src/osd/eminline.h index 80b31437f2a..ccdcd65b9c6 100644 --- a/src/osd/eminline.h +++ b/src/osd/eminline.h @@ -18,14 +18,6 @@ #if defined(__i386__) || defined(__x86_64__) - -static inline void ATTR_FORCE_INLINE -osd_yield_processor(void) -{ - __asm__ __volatile__ ( " rep ; nop ;" ); -} - - #if defined(__x86_64__) //============================================================ @@ -52,14 +44,6 @@ _osd_exchange64(INT64 volatile *ptr, INT64 exchange) #elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__) -static inline void ATTR_FORCE_INLINE -osd_yield_processor(void) -{ - __asm__ __volatile__ ( " nop \n nop \n" ); -} - - - #if defined(__ppc64__) || defined(__PPC64__) //============================================================ diff --git a/src/osd/sdl/watchdog.cpp b/src/osd/sdl/watchdog.cpp index 01d98f460dc..6d3aa3c7f69 100644 --- a/src/osd/sdl/watchdog.cpp +++ b/src/osd/sdl/watchdog.cpp @@ -51,7 +51,7 @@ watchdog::watchdog(void) watchdog::~watchdog(void) { - atomic_exchange32(&m_do_exit, 1); + m_do_exit = 1; osd_event_set(m_event); osd_thread_wait_free(m_thread); osd_event_free(m_event); diff --git a/src/osd/sdl/watchdog.h b/src/osd/sdl/watchdog.h index 0f15b68f469..18aa11a54f5 100644 --- a/src/osd/sdl/watchdog.h +++ b/src/osd/sdl/watchdog.h @@ -11,6 +11,7 @@ //============================================================ #include "modules/sync/osdsync.h" +#include <atomic> class watchdog { @@ -27,7 +28,7 @@ public: private: osd_event * m_event; osd_thread * m_thread; - volatile INT32 m_do_exit; + std::atomic<INT32> m_do_exit; osd_ticks_t m_timeout; }; diff --git a/src/osd/windows/window.cpp b/src/osd/windows/window.cpp index 33c202c1da8..52d0a898df7 100644 --- a/src/osd/windows/window.cpp +++ b/src/osd/windows/window.cpp @@ -12,9 +12,12 @@ // Needed for RAW Input #define WM_INPUT 0x00FF +#include <stdio.h> // must be here otherwise issues with I64FMT in MINGW // standard C headers #include <process.h> +#include <atomic> + // MAME headers #include "emu.h" #include "uiinput.h" @@ -127,11 +130,11 @@ struct mtlog }; static mtlog mtlog[100000]; -static volatile INT32 mtlogindex; +static std::atomic<INT32> mtlogindex; void mtlog_add(const char *event) { - int index = atomic_increment32((INT32 *) &mtlogindex) - 1; + int index = mtlogindex++; if (index < ARRAY_LENGTH(mtlog)) { mtlog[index].timestamp = osd_ticks(); @@ -149,7 +152,7 @@ static void mtlog_dump(void) for (i = 0; i < mtlogindex; i++) { osd_ticks_t curr = mtlog[i].timestamp * 1000000 / cps; - fprintf(f, "%20I64d %10I64d %s\n", curr, curr - last, mtlog[i].event); + fprintf(f, "%20" I64FMT "d %10" I64FMT "d %s\n", (UINT64)curr, (UINT64)(curr - last), mtlog[i].event); last = curr; } fclose(f); |