From c2fe2ac4a4a018b036e4de123839b0df0bc86697 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 15 Sep 2019 19:47:36 +0300 Subject: [PATCH] cellMic: use g_fxo --- rpcs3/Emu/Cell/Modules/cellMic.cpp | 149 ++++++++++++++++------------- rpcs3/Emu/Cell/Modules/cellMic.h | 5 + 2 files changed, 89 insertions(+), 65 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellMic.cpp b/rpcs3/Emu/Cell/Modules/cellMic.cpp index 769f5cb4c8..0cd7dc8e85 100644 --- a/rpcs3/Emu/Cell/Modules/cellMic.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMic.cpp @@ -51,7 +51,7 @@ void mic_context::operator()() // Process signals { - auto micl = g_idm->lock(0); + std::lock_guard lock(mutex); for (auto& mic_entry : mic_list) { @@ -459,13 +459,13 @@ s32 cellMicInit() { cellMic.notice("cellMicInit()"); - auto mic_thr = g_idm->lock(id_new); - if (!mic_thr) + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (mic_thr->init) return CELL_MIC_ERROR_ALREADY_INIT; - mic_thr.create("Microphone Thread"); - mic_thr->load_config_and_init(); + mic_thr->init = 1; return CELL_OK; } @@ -474,31 +474,13 @@ s32 cellMicEnd(ppu_thread& ppu) { cellMic.notice("cellMicEnd()"); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; - *mic_thr.get() = thread_state::aborting; - mic_thr.unlock(); - - while (true) - { - if (ppu.is_stopped()) - { - return 0; - } - - thread_ctrl::wait_for(1000); - - auto mic_thr = g_idm->lock(0); - - if (*mic_thr.get() == thread_state::finished) - { - mic_thr.destroy(); - mic_thr.unlock(); - break; - } - } + // TODO + mic_thr->init = 0; return CELL_OK; } @@ -508,8 +490,10 @@ s32 cellMicEnd(ppu_thread& ppu) s32 cellMicOpen(u32 dev_num, u32 sampleRate) { cellMic.trace("cellMicOpen(dev_num=%um sampleRate=%u)", dev_num, sampleRate); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; if (!mic_thr->mic_list.count(dev_num)) @@ -526,8 +510,10 @@ s32 cellMicOpen(u32 dev_num, u32 sampleRate) s32 cellMicOpenRaw(u32 dev_num, u32 sampleRate, u32 maxChannels) { cellMic.trace("cellMicOpenRaw(dev_num=%d, sampleRate=%d, maxChannels=%d)", dev_num, sampleRate, maxChannels); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; if (!mic_thr->mic_list.count(dev_num)) @@ -543,10 +529,12 @@ s32 cellMicOpenRaw(u32 dev_num, u32 sampleRate, u32 maxChannels) s32 cellMicOpenEx(u32 dev_num, u32 rawSampleRate, u32 rawChannel, u32 DSPSampleRate, u32 bufferSizeMS, u8 signalType) { - cellMic.trace( - "cellMicOpenEx(dev_num=%d, rawSampleRate=%d, rawChannel=%d, DSPSampleRate=%d, bufferSizeMS=%d, signalType=0x%x)", dev_num, rawSampleRate, rawChannel, DSPSampleRate, bufferSizeMS, signalType); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + cellMic.trace("cellMicOpenEx(dev_num=%d, rawSampleRate=%d, rawChannel=%d, DSPSampleRate=%d, bufferSizeMS=%d, signalType=0x%x)", + dev_num, rawSampleRate, rawChannel, DSPSampleRate, bufferSizeMS, signalType); + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; if (!mic_thr->mic_list.count(dev_num)) @@ -565,8 +553,10 @@ s32 cellMicOpenEx(u32 dev_num, u32 rawSampleRate, u32 rawChannel, u32 DSPSampleR u8 cellMicIsOpen(u32 dev_num) { cellMic.trace("cellMicIsOpen(dev_num=%d)", dev_num); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return false; if (!mic_thr->mic_list.count(dev_num)) @@ -584,9 +574,12 @@ s32 cellMicIsAttached(u32 dev_num) s32 cellMicClose(u32 dev_num) { cellMic.trace("cellMicClose(dev_num=%d)", dev_num); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; + if (!mic_thr->mic_list.count(dev_num)) return CELL_MIC_ERROR_DEVICE_NOT_FOUND; @@ -604,8 +597,10 @@ s32 cellMicClose(u32 dev_num) s32 cellMicStart(u32 dev_num) { cellMic.trace("cellMicStart(dev_num=%d)", dev_num); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; if (!mic_thr->mic_list.count(dev_num)) @@ -625,8 +620,9 @@ s32 cellMicStartEx(u32 dev_num, u32 flags) // TODO: flags - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; if (!mic_thr->mic_list.count(dev_num)) @@ -645,9 +641,12 @@ s32 cellMicStartEx(u32 dev_num, u32 flags) s32 cellMicStop(u32 dev_num) { cellMic.trace("cellMicStop(dev_num=%d)", dev_num); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; + if (!mic_thr->mic_list.count(dev_num)) return CELL_MIC_ERROR_DEVICE_NOT_FOUND; @@ -673,9 +672,11 @@ s32 cellMicGetDeviceAttr(u32 dev_num, CellMicDeviceAttr deviceAttributes, vm::pt if (!arg1 || (!arg2 && deviceAttributes == CELLMIC_DEVATTR_CHANVOL)) return CELL_MIC_ERROR_PARAM; - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; + if (!mic_thr->mic_list.count(dev_num)) return CELL_MIC_ERROR_DEVICE_NOT_FOUND; @@ -699,9 +700,11 @@ s32 cellMicSetDeviceAttr(u32 dev_num, CellMicDeviceAttr deviceAttributes, u32 ar { cellMic.trace("cellMicSetDeviceAttr(dev_num=%d, deviceAttributes=%d, arg1=%d, arg2=%d)", dev_num, (u32)deviceAttributes, arg1, arg2); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; + if (!mic_thr->mic_list.count(dev_num)) return CELL_MIC_ERROR_DEVICE_NOT_FOUND; @@ -741,8 +744,10 @@ s32 cellMicSetSignalAttr() s32 cellMicGetSignalState(u32 dev_num, CellMicSignalState sig_state, vm::ptr value) { cellMic.todo("cellMicGetSignalState(dev_num=%d, signalSate=%d, value=*0x%x)", dev_num, (u32)sig_state, value); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; be_t* ival = (be_t*)value.get_ptr(); @@ -777,8 +782,10 @@ s32 cellMicGetSignalState(u32 dev_num, CellMicSignalState sig_state, vm::ptr format) { cellMic.trace("cellMicGetFormatRaw(dev_num=%d, format=0x%x)", dev_num, format); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; if (!mic_thr->mic_list.count(dev_num)) @@ -814,8 +821,10 @@ s32 cellMicGetFormatDsp(u32 dev_num, vm::ptr format) s32 cellMicSetNotifyEventQueue(u64 key) { cellMic.todo("cellMicSetNotifyEventQueue(key=0x%llx)", key); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; // default mic queue size = 4 @@ -837,15 +846,17 @@ s32 cellMicSetNotifyEventQueue2(u64 key, u64 source) { // TODO: Actually do things with the source variable cellMic.todo("cellMicSetNotifyEventQueue2(key=0x%llx, source=0x%llx", key, source); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; // default mic queue size = 4 auto mic_queue = lv2_event_queue::find(key); if (!mic_queue) return CELL_MIC_ERROR_EVENT_QUEUE; - + mic_queue->send(0, CELL_MIC_ATTACH, 0, 0); mic_thr->event_queue_key = key; @@ -855,8 +866,10 @@ s32 cellMicSetNotifyEventQueue2(u64 key, u64 source) s32 cellMicRemoveNotifyEventQueue(u64 key) { cellMic.warning("cellMicRemoveNotifyEventQueue(key=0x%llx)", key); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; mic_thr->event_queue_key = 0; @@ -869,9 +882,12 @@ s32 cellMicRemoveNotifyEventQueue(u64 key) s32 cellMicReadRaw(u32 dev_num, vm::ptr data, u32 maxBytes) { cellMic.trace("cellMicReadRaw(dev_num=%d, data=0x%x, maxBytes=%d)", dev_num, data, maxBytes); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; + if (!mic_thr->mic_list.count(dev_num)) return CELL_MIC_ERROR_DEVICE_NOT_FOUND; @@ -887,9 +903,12 @@ s32 cellMicReadRaw(u32 dev_num, vm::ptr data, u32 maxBytes) s32 cellMicRead(u32 dev_num, vm::ptr data, u32 maxBytes) { cellMic.todo("cellMicRead(dev_num=%d, data=0x%x, maxBytes=0x%x)", dev_num, data, maxBytes); - auto mic_thr = g_idm->lock(0); - if (!mic_thr) + + const auto mic_thr = g_fxo->get(); + const std::lock_guard lock(mic_thr->mutex); + if (!mic_thr->init) return CELL_MIC_ERROR_NOT_INIT; + if (!mic_thr->mic_list.count(dev_num)) return CELL_MIC_ERROR_DEVICE_NOT_FOUND; diff --git a/rpcs3/Emu/Cell/Modules/cellMic.h b/rpcs3/Emu/Cell/Modules/cellMic.h index aab3a25da2..c73576ab59 100644 --- a/rpcs3/Emu/Cell/Modules/cellMic.h +++ b/rpcs3/Emu/Cell/Modules/cellMic.h @@ -253,6 +253,11 @@ public: std::unordered_map mic_list; + shared_mutex mutex; + atomic_t init = 0; + + static constexpr auto thread_name = "Microphone Thread"sv; + protected: const u64 start_time = get_guest_system_time(); u64 m_counter = 0;