summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2023-04-14 06:45:20 +1000
committer Vas Crabb <vas@vastheman.com>2023-04-14 06:45:20 +1000
commit7d26d641d3e94943b351ad55d7ffe25ec02ac791 (patch)
treed9fabd7ddf5c487711b1ee6b5599d0e4a7cb5902 /src/osd
parentc0b57d30f0ce39c445190fe4e27bec6c57ebb137 (diff)
Miscellaneous improvements:
infoxml.cpp: Thread device processing. Gives about a 10% speed improvement overall, and avoids the need to mess with the locale of the ultimate output stream. debugger/win/consolewininfo.cpp: Show image mount/create error messages on the console. emu/devdelegate.h, util/delegate.h: Added deduction guides for common delegate creation patterns (only used in sega/segas16a.cpp so far). More noexcept on things that have no business throwing exceptions.
Diffstat (limited to 'src/osd')
-rw-r--r--src/osd/modules/debugger/win/consolewininfo.cpp12
-rw-r--r--src/osd/modules/lib/osdlib.h28
-rw-r--r--src/osd/modules/lib/osdlib_macosx.cpp10
-rw-r--r--src/osd/modules/lib/osdlib_unix.cpp10
-rw-r--r--src/osd/modules/lib/osdlib_win32.cpp10
-rw-r--r--src/osd/osdcore.h2
-rw-r--r--src/osd/osdsync.cpp71
7 files changed, 74 insertions, 69 deletions
diff --git a/src/osd/modules/debugger/win/consolewininfo.cpp b/src/osd/modules/debugger/win/consolewininfo.cpp
index 1c70cb8e7a0..3a4a52be2e2 100644
--- a/src/osd/modules/debugger/win/consolewininfo.cpp
+++ b/src/osd/modules/debugger/win/consolewininfo.cpp
@@ -556,9 +556,11 @@ void consolewin_info::open_image_file(device_image_interface &device)
window(),
CLSID_FileOpenDialog,
true,
- [&device] (std::string_view selection)
+ [this, &device] (std::string_view selection)
{
- device.load(selection);
+ auto [err, message] = device.load(selection);
+ if (err)
+ machine().debugger().console().printf("Error mounting image file: %s\n", !message.empty() ? message : err.message());
});
}
@@ -570,9 +572,11 @@ void consolewin_info::create_image_file(device_image_interface &device)
window(),
CLSID_FileSaveDialog,
false,
- [&device] (std::string_view selection)
+ [this, &device] (std::string_view selection)
{
- device.create(selection, device.device_get_indexed_creatable_format(0), nullptr);
+ auto [err, message] = device.create(selection, device.device_get_indexed_creatable_format(0), nullptr);
+ if (err)
+ machine().debugger().console().printf("Error creating image file: %s\n", !message.empty() ? message : err.message());
});
}
diff --git a/src/osd/modules/lib/osdlib.h b/src/osd/modules/lib/osdlib.h
index c84901002ad..72815d687db 100644
--- a/src/osd/modules/lib/osdlib.h
+++ b/src/osd/modules/lib/osdlib.h
@@ -78,7 +78,7 @@ std::error_condition osd_set_clipboard_text(std::string_view text) noexcept;
namespace osd {
-bool invalidate_instruction_cache(void const *start, std::size_t size);
+bool invalidate_instruction_cache(void const *start, std::size_t size) noexcept;
class virtual_memory_allocation
@@ -98,12 +98,12 @@ public:
virtual_memory_allocation(virtual_memory_allocation const &) = delete;
virtual_memory_allocation &operator=(virtual_memory_allocation const &) = delete;
- virtual_memory_allocation() { }
- virtual_memory_allocation(std::initializer_list<std::size_t> blocks, unsigned intent)
+ virtual_memory_allocation() noexcept { }
+ virtual_memory_allocation(std::initializer_list<std::size_t> blocks, unsigned intent) noexcept
{
m_memory = do_alloc(blocks, intent, m_size, m_page_size);
}
- virtual_memory_allocation(virtual_memory_allocation &&that) : m_memory(that.m_memory), m_size(that.m_size), m_page_size(that.m_page_size)
+ virtual_memory_allocation(virtual_memory_allocation &&that) noexcept : m_memory(that.m_memory), m_size(that.m_size), m_page_size(that.m_page_size)
{
that.m_memory = nullptr;
that.m_size = that.m_page_size = 0U;
@@ -114,12 +114,12 @@ public:
do_free(m_memory, m_size);
}
- explicit operator bool() const { return bool(m_memory); }
- void *get() { return m_memory; }
- std::size_t size() const { return m_size; }
- std::size_t page_size() const { return m_page_size; }
+ explicit operator bool() const noexcept { return bool(m_memory); }
+ void *get() noexcept { return m_memory; }
+ std::size_t size() const noexcept { return m_size; }
+ std::size_t page_size() const noexcept { return m_page_size; }
- bool set_access(std::size_t start, std::size_t size, unsigned access)
+ bool set_access(std::size_t start, std::size_t size, unsigned access) noexcept
{
if ((start % m_page_size) || (size % m_page_size) || (start > m_size) || ((m_size - start) < size))
return false;
@@ -127,7 +127,7 @@ public:
return do_set_access(reinterpret_cast<std::uint8_t *>(m_memory) + start, size, access);
}
- virtual_memory_allocation &operator=(std::nullptr_t)
+ virtual_memory_allocation &operator=(std::nullptr_t) noexcept
{
if (m_memory)
do_free(m_memory, m_size);
@@ -136,7 +136,7 @@ public:
return *this;
}
- virtual_memory_allocation &operator=(virtual_memory_allocation &&that)
+ virtual_memory_allocation &operator=(virtual_memory_allocation &&that) noexcept
{
if (&that != this)
{
@@ -152,9 +152,9 @@ public:
}
private:
- static void *do_alloc(std::initializer_list<std::size_t> blocks, unsigned intent, std::size_t &size, std::size_t &page_size);
- static void do_free(void *start, std::size_t size);
- static bool do_set_access(void *start, std::size_t size, unsigned access);
+ static void *do_alloc(std::initializer_list<std::size_t> blocks, unsigned intent, std::size_t &size, std::size_t &page_size) noexcept;
+ static void do_free(void *start, std::size_t size) noexcept;
+ static bool do_set_access(void *start, std::size_t size, unsigned access) noexcept;
void *m_memory = nullptr;
std::size_t m_size = 0U, m_page_size = 0U;
diff --git a/src/osd/modules/lib/osdlib_macosx.cpp b/src/osd/modules/lib/osdlib_macosx.cpp
index 8f61bb4e998..9d13f118ff2 100644
--- a/src/osd/modules/lib/osdlib_macosx.cpp
+++ b/src/osd/modules/lib/osdlib_macosx.cpp
@@ -218,7 +218,7 @@ std::error_condition osd_set_clipboard_text(std::string_view text) noexcept
// osd_getpid
//============================================================
-int osd_getpid()
+int osd_getpid() noexcept
{
return getpid();
}
@@ -282,7 +282,7 @@ private:
} // anonymous namespace
-bool invalidate_instruction_cache(void const *start, std::size_t size)
+bool invalidate_instruction_cache(void const *start, std::size_t size) noexcept
{
char const *const begin(reinterpret_cast<char const *>(start));
char const *const end(begin + size);
@@ -291,7 +291,7 @@ bool invalidate_instruction_cache(void const *start, std::size_t size)
}
-void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blocks, unsigned intent, std::size_t &size, std::size_t &page_size)
+void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blocks, unsigned intent, std::size_t &size, std::size_t &page_size) noexcept
{
long const p(sysconf(_SC_PAGE_SIZE));
if (0 >= p)
@@ -310,12 +310,12 @@ void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blo
return result;
}
-void virtual_memory_allocation::do_free(void *start, std::size_t size)
+void virtual_memory_allocation::do_free(void *start, std::size_t size) noexcept
{
munmap(start, size);
}
-bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, unsigned access)
+bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, unsigned access) noexcept
{
int prot((NONE == access) ? PROT_NONE : 0);
if (access & READ)
diff --git a/src/osd/modules/lib/osdlib_unix.cpp b/src/osd/modules/lib/osdlib_unix.cpp
index 0c6eb8622ab..20f6a9ab40c 100644
--- a/src/osd/modules/lib/osdlib_unix.cpp
+++ b/src/osd/modules/lib/osdlib_unix.cpp
@@ -135,7 +135,7 @@ std::error_condition osd_set_clipboard_text(std::string_view text) noexcept
// osd_getpid
//============================================================
-int osd_getpid()
+int osd_getpid() noexcept
{
return getpid();
}
@@ -199,7 +199,7 @@ private:
} // anonymous namespace
-bool invalidate_instruction_cache(void const *start, std::size_t size)
+bool invalidate_instruction_cache(void const *start, std::size_t size) noexcept
{
#if !defined(SDLMAME_EMSCRIPTEN)
char const *const begin(reinterpret_cast<char const *>(start));
@@ -210,7 +210,7 @@ bool invalidate_instruction_cache(void const *start, std::size_t size)
}
-void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blocks, unsigned intent, std::size_t &size, std::size_t &page_size)
+void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blocks, unsigned intent, std::size_t &size, std::size_t &page_size) noexcept
{
long const p(sysconf(_SC_PAGE_SIZE));
if (0 >= p)
@@ -247,12 +247,12 @@ void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blo
return result;
}
-void virtual_memory_allocation::do_free(void *start, std::size_t size)
+void virtual_memory_allocation::do_free(void *start, std::size_t size) noexcept
{
munmap(reinterpret_cast<char *>(start), size);
}
-bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, unsigned access)
+bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, unsigned access) noexcept
{
int prot((NONE == access) ? PROT_NONE : 0);
if (access & READ)
diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp
index 23e75bf9dc2..d42ad14d3df 100644
--- a/src/osd/modules/lib/osdlib_win32.cpp
+++ b/src/osd/modules/lib/osdlib_win32.cpp
@@ -253,7 +253,7 @@ std::error_condition osd_set_clipboard_text(std::string_view text) noexcept
// osd_getpid
//============================================================
-int osd_getpid()
+int osd_getpid() noexcept
{
return GetCurrentProcessId();
}
@@ -324,13 +324,13 @@ private:
} // anonymous namespace
-bool invalidate_instruction_cache(void const *start, std::size_t size)
+bool invalidate_instruction_cache(void const *start, std::size_t size) noexcept
{
return FlushInstructionCache(GetCurrentProcess(), start, size) != 0;
}
-void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blocks, unsigned intent, std::size_t &size, std::size_t &page_size)
+void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blocks, unsigned intent, std::size_t &size, std::size_t &page_size) noexcept
{
SYSTEM_INFO info;
GetSystemInfo(&info);
@@ -349,12 +349,12 @@ void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blo
return result;
}
-void virtual_memory_allocation::do_free(void *start, std::size_t size)
+void virtual_memory_allocation::do_free(void *start, std::size_t size) noexcept
{
VirtualFree(start, 0, MEM_RELEASE);
}
-bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, unsigned access)
+bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, unsigned access) noexcept
{
DWORD p;
if (access & EXECUTE)
diff --git a/src/osd/osdcore.h b/src/osd/osdcore.h
index c714b4b313e..f3f5fc2e9b3 100644
--- a/src/osd/osdcore.h
+++ b/src/osd/osdcore.h
@@ -35,7 +35,7 @@ const char *osd_getenv(const char *name);
/// \brief Get current process ID
///
/// \return The process ID of the current process.
-int osd_getpid();
+int osd_getpid() noexcept;
/*-----------------------------------------------------------------------------
diff --git a/src/osd/osdsync.cpp b/src/osd/osdsync.cpp
index 3fa32f9141c..b2300e93ee6 100644
--- a/src/osd/osdsync.cpp
+++ b/src/osd/osdsync.cpp
@@ -104,26 +104,27 @@ int osd_get_num_processors(bool heavy_mt)
struct work_thread_info
{
work_thread_info(uint32_t aid, osd_work_queue &aqueue)
- : queue(aqueue)
- , handle(nullptr)
- , wakeevent(true, false) // manual reset, not signalled
- , id(aid)
+ : queue(aqueue)
+ , handle(nullptr)
+ , wakeevent(true, false) // manual reset, not signalled
+ , id(aid)
#if KEEP_STATISTICS
- , itemsdone(0)
- , actruntime(0)
- , runtime(0)
- , spintime(0)
- , waittime(0)
+ , itemsdone(0)
+ , actruntime(0)
+ , runtime(0)
+ , spintime(0)
+ , waittime(0)
#endif
{
}
+
osd_work_queue & queue; // pointer back to the queue
std::thread * handle; // handle to the thread
osd_event wakeevent; // wake event for the thread
- uint32_t id;
+ uint32_t id;
#if KEEP_STATISTICS
- int32_t itemsdone;
+ int32_t itemsdone;
osd_ticks_t actruntime;
osd_ticks_t runtime;
osd_ticks_t spintime;
@@ -135,21 +136,21 @@ struct work_thread_info
struct osd_work_queue
{
osd_work_queue()
- : list(nullptr)
- , tailptr(nullptr)
- , free(nullptr)
- , items(0)
- , livethreads(0)
- , waiting(0)
- , exiting(0)
- , threads(0)
- , flags(0)
- , doneevent(true, true) // manual reset, signalled
+ : list(nullptr)
+ , tailptr(nullptr)
+ , free(nullptr)
+ , items(0)
+ , livethreads(0)
+ , waiting(0)
+ , exiting(0)
+ , threads(0)
+ , flags(0)
+ , doneevent(true, true) // manual reset, signalled
#if KEEP_STATISTICS
- , itemsqueued(0)
- , setevents(0)
- , extraitems(0)
- , spinloops(0)
+ , itemsqueued(0)
+ , setevents(0)
+ , extraitems(0)
+ , spinloops(0)
#endif
{
}
@@ -179,14 +180,14 @@ struct osd_work_queue
struct osd_work_item
{
osd_work_item(osd_work_queue &aqueue)
- : next(nullptr)
- , queue(aqueue)
- , callback(nullptr)
- , param(nullptr)
- , result(nullptr)
- , event(nullptr) // manual reset, not signalled
- , flags(0)
- , done(false)
+ : next(nullptr)
+ , queue(aqueue)
+ , callback(nullptr)
+ , param(nullptr)
+ , result(nullptr)
+ , event(nullptr) // manual reset, not signalled
+ , flags(0)
+ , done(false)
{
}
@@ -196,7 +197,7 @@ struct osd_work_item
void * param; // callback parameter
void * result; // callback result
osd_event * event; // event signalled when complete
- uint32_t flags; // creation flags
+ uint32_t flags; // creation flags
std::atomic<int32_t> done; // is the item done?
};
@@ -211,7 +212,7 @@ int osd_num_processors = 0;
//============================================================
static int effective_num_processors(bool heavy_mt);
-static void * worker_thread_entry(void *param);
+static void *worker_thread_entry(void *param);
static void worker_thread_process(osd_work_queue *queue, work_thread_info *thread);
static bool queue_has_list_items(osd_work_queue *queue);