Skip to content
Permalink
Browse files

onepad-legacy: Use mt_queue, and move it from onepad to common. (#3060)

  • Loading branch information...
arcum42 committed Aug 10, 2019
1 parent 4e58558 commit ed6ac001865d1d7e0bea5a9c6dadf48b247c7d4f
File renamed without changes.
@@ -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;
@@ -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<keyEvent> ev_fifo;
MtQueue<keyEvent> 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
@@ -43,7 +43,8 @@
#include <vector>
#include <map>
#include <string>
#include <pthread.h>
#include <mutex>
#include <queue>

#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<keyEvent> ev_fifo;
extern pthread_spinlock_t mutex_KeyEvent;
extern MtQueue<keyEvent> g_ev_fifo;

void clearPAD(int pad);
s32 _PADopen(void *pDsp);

0 comments on commit ed6ac00

Please sign in to comment.
You can’t perform that action at this time.