moonlight-common-c/src/PlatformThreads.h
Sunguk Lee ba27e97698 Add vita environment (#22)
* vita: initial port

* vita: implement events, enable input thread

* vita: gethostbyname

* vita: Enable audio

* vita: Fix thread crash on discoonect process

* vita: Handle cannot create thread

* vita: now use newlib's socket apis

* vita: Refactoring for moonlight-stream/moonlight-common-c

* Fix review things

https://github.com/moonlight-stream/moonlight-common-c/pull/22#pullrequestreview-2436093

- vita may not support IPv6; so add LC_ASSERT them.
- define inet_ntop to sceNetInetNtop
- guard about failure of sceKernelCreateMutex or sceKernelCreateCond
- remove meanless macros

https://github.com/moonlight-stream/moonlight-common-c/pull/22#pullrequestreview-2444677

- !*mutex to *mutex
- remove useless LC_ASSERT then change to use inet_ntop
  in vita system not defined `sockaddr_in6`, so just use `sockaddr_in` instead this.

https://github.com/moonlight-stream/moonlight-common-c/pull/22#pullrequestreview-2445642

- define sin6_addr
2016-10-05 16:43:33 -07:00

65 lines
No EOL
1.5 KiB
C
Executable file

#pragma once
#include "Limelight.h"
#include "Platform.h"
typedef void(*ThreadEntry)(void* context);
#if defined(LC_WINDOWS)
typedef HANDLE PLT_MUTEX;
typedef HANDLE PLT_EVENT;
typedef struct _PLT_THREAD {
HANDLE handle;
int cancelled;
} PLT_THREAD;
#elif defined(__vita__)
typedef int PLT_MUTEX;
typedef struct _PLT_EVENT {
int mutex;
int cond;
int signalled;
} PLT_EVENT;
typedef struct _PLT_THREAD {
int handle;
int cancelled;
void *context;
int alive;
} PLT_THREAD;
#elif defined (LC_POSIX)
typedef pthread_mutex_t PLT_MUTEX;
typedef struct _PLT_EVENT {
pthread_mutex_t mutex;
pthread_cond_t cond;
int signalled;
} PLT_EVENT;
typedef struct _PLT_THREAD {
pthread_t thread;
int cancelled;
} PLT_THREAD;
#else
#error Unsupported platform
#endif
int PltCreateMutex(PLT_MUTEX* mutex);
void PltDeleteMutex(PLT_MUTEX* mutex);
void PltLockMutex(PLT_MUTEX* mutex);
void PltUnlockMutex(PLT_MUTEX* mutex);
int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD*thread);
void PltCloseThread(PLT_THREAD*thread);
void PltInterruptThread(PLT_THREAD*thread);
int PltIsThreadInterrupted(PLT_THREAD*thread);
void PltJoinThread(PLT_THREAD*thread);
int PltCreateEvent(PLT_EVENT* event);
void PltCloseEvent(PLT_EVENT* event);
void PltSetEvent(PLT_EVENT* event);
void PltClearEvent(PLT_EVENT* event);
int PltWaitForEvent(PLT_EVENT* event);
void PltRunThreadProc(void);
#define PLT_WAIT_SUCCESS 0
#define PLT_WAIT_INTERRUPTED 1
void PltSleepMs(int ms);