diff --git a/plugins/onepad/mt_queue.h b/common/include/Utilities/mt_queue.h similarity index 100% rename from plugins/onepad/mt_queue.h rename to common/include/Utilities/mt_queue.h diff --git a/plugins/onepad_legacy/keyboard.cpp b/plugins/onepad_legacy/keyboard.cpp index 0efdb4206e..1375d57e70 100644 --- a/plugins/onepad_legacy/keyboard.cpp +++ b/plugins/onepad_legacy/keyboard.cpp @@ -221,24 +221,16 @@ void PollForX11KeyboardInput() XEvent E = {0}; // Keyboard input send by PCSX2 - while (!ev_fifo.empty()) - { - AnalyzeKeyEvent(ev_fifo.front()); - pthread_spin_lock(&mutex_KeyEvent); - ev_fifo.pop(); - pthread_spin_unlock(&mutex_KeyEvent); - } + g_ev_fifo.consume_all(AnalyzeKeyEvent); // keyboard input - while (XPending(GSdsp) > 0) - { + while (XPending(GSdsp) > 0) { XNextEvent(GSdsp, &E); // Change the format of the structure to be compatible with GSOpen2 // mode (event come from pcsx2 not X) evt.evt = E.type; - switch (E.type) - { + switch (E.type) { case MotionNotify: evt.key = (E.xbutton.x & 0xFFFF) | (E.xbutton.y << 16); break; diff --git a/plugins/onepad_legacy/onepad.cpp b/plugins/onepad_legacy/onepad.cpp index 9882eab5f7..212bdf3948 100644 --- a/plugins/onepad_legacy/onepad.cpp +++ b/plugins/onepad_legacy/onepad.cpp @@ -53,11 +53,8 @@ const u32 build = 3; // increase that with each version FILE *padLog = NULL; -pthread_spinlock_t mutex_KeyEvent; -bool mutex_WasInit = false; KeyStatus *key_status = NULL; - -std::queue ev_fifo; +MtQueue g_ev_fifo; static void InitLibraryName() { @@ -193,11 +190,7 @@ EXPORT_C_(s32) PADopen(void *pDsp) { memset(&event, 0, sizeof(event)); key_status->Init(); - - while (!ev_fifo.empty()) - ev_fifo.pop(); - pthread_spin_init(&mutex_KeyEvent, PTHREAD_PROCESS_PRIVATE); - mutex_WasInit = true; + g_ev_fifo.reset(); #if defined(__unix__) GamePad::EnumerateGamePads(s_vgamePad); @@ -223,10 +216,6 @@ EXPORT_C_(void) PADsetLogDir(const char *dir) EXPORT_C_(void) PADclose() { - while (!ev_fifo.empty()) - ev_fifo.pop(); - mutex_WasInit = false; - pthread_spin_destroy(&mutex_KeyEvent); _PADclose(); } @@ -349,13 +338,6 @@ EXPORT_C_(keyEvent *) PADkeyEvent() #if defined(__unix__) EXPORT_C_(void) PADWriteEvent(keyEvent &evt) { - // This function call be called before PADopen. Therefore we cann't - // guarantee that the spin lock was initialized - if (mutex_WasInit) - { - pthread_spin_lock(&mutex_KeyEvent); - ev_fifo.push(evt); - pthread_spin_unlock(&mutex_KeyEvent); - } + g_ev_fifo.push(evt); } #endif diff --git a/plugins/onepad_legacy/onepad.h b/plugins/onepad_legacy/onepad.h index ae55e82ec2..02c75ca0ec 100644 --- a/plugins/onepad_legacy/onepad.h +++ b/plugins/onepad_legacy/onepad.h @@ -43,7 +43,8 @@ #include #include #include -#include +#include +#include #define PADdefs #include "PS2Edefs.h" @@ -54,6 +55,7 @@ #include "bitwise.h" #include "controller.h" #include "KeyStatus.h" +#include "mt_queue.h" #ifdef _MSC_VER #define EXPORT_C_(type) extern "C" __declspec(dllexport) type CALLBACK @@ -122,8 +124,7 @@ enum gamePadValues { }; extern keyEvent event; -extern std::queue ev_fifo; -extern pthread_spinlock_t mutex_KeyEvent; +extern MtQueue g_ev_fifo; void clearPAD(int pad); s32 _PADopen(void *pDsp);