-static void *JoyThread(void *param) {
- while (!TerminateThread) {
- CheckJoy();
- usleep(1000);
- }
- pthread_exit(0);
- return NULL;
-}
-
-long PADopen(unsigned long *Disp) {
- g.Disp = (Display *)*Disp;
-
- if (!g.Opened) {
- if (SDL_WasInit(SDL_INIT_EVERYTHING)) {
- if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) {
- return PSE_PAD_ERR_FAILURE;
- }
- } else if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) == -1) {
- return PSE_PAD_ERR_FAILURE;
- }
-
- InitSDLJoy();
- InitKeyboard();
-
- g.KeyLeftOver = 0;
-
- if (g.cfg.Threaded) {
- TerminateThread = 0;
-
- if (pthread_create(&ThreadID, NULL, JoyThread, NULL) != 0) {
- // thread creation failed, fallback to polling
- g.cfg.Threaded = 0;
- }
- }
- }
-
- g.Opened = 1;
-
- return PSE_PAD_ERR_SUCCESS;
-}
-
-long PADclose(void) {
- if (g.Opened) {
- if (g.cfg.Threaded) {
- TerminateThread = 1;
- pthread_join(ThreadID, NULL);
- }
-
- DestroySDLJoy();
- DestroyKeyboard();
-
- if (SDL_WasInit(SDL_INIT_EVERYTHING & ~SDL_INIT_JOYSTICK)) {
- SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
- } else {
- SDL_Quit();
- }
- }
-
- g.Opened = 0;
-
- return PSE_PAD_ERR_SUCCESS;
-}