mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-11 22:42:31 +02:00
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
This commit is contained in:
@@ -20,14 +20,14 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* These are functions that need to be implemented by a port of SDL */
|
||||
// These are functions that need to be implemented by a port of SDL
|
||||
|
||||
#ifndef SDL_systhread_h_
|
||||
#define SDL_systhread_h_
|
||||
|
||||
#include "SDL_thread_c.h"
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
// Set up for C function definitions, even when using C++
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -40,10 +40,10 @@ extern int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread);
|
||||
|
||||
/* This function does any necessary setup in the child thread */
|
||||
// This function does any necessary setup in the child thread
|
||||
extern void SDL_SYS_SetupThread(const char *name);
|
||||
|
||||
/* This function sets the current thread priority */
|
||||
// This function sets the current thread priority
|
||||
extern int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority);
|
||||
|
||||
/* This function waits for the thread to finish and frees any data
|
||||
@@ -51,27 +51,27 @@ extern int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority);
|
||||
*/
|
||||
extern void SDL_SYS_WaitThread(SDL_Thread *thread);
|
||||
|
||||
/* Mark thread as cleaned up as soon as it exits, without joining. */
|
||||
// Mark thread as cleaned up as soon as it exits, without joining.
|
||||
extern void SDL_SYS_DetachThread(SDL_Thread *thread);
|
||||
|
||||
/* Initialize the global TLS data */
|
||||
// Initialize the global TLS data
|
||||
extern void SDL_SYS_InitTLSData(void);
|
||||
|
||||
/* Get the thread local storage for this thread */
|
||||
// Get the thread local storage for this thread
|
||||
extern SDL_TLSData *SDL_SYS_GetTLSData(void);
|
||||
|
||||
/* Set the thread local storage for this thread */
|
||||
// Set the thread local storage for this thread
|
||||
extern int SDL_SYS_SetTLSData(SDL_TLSData *data);
|
||||
|
||||
/* Quit the global TLS data */
|
||||
// Quit the global TLS data
|
||||
extern void SDL_SYS_QuitTLSData(void);
|
||||
|
||||
/* A helper function for setting up a thread with a stack size. */
|
||||
// A helper function for setting up a thread with a stack size.
|
||||
extern SDL_Thread *SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, size_t stacksize, void *data);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
// Ends C function definitions when using C++
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_systhread_h_ */
|
||||
#endif // SDL_systhread_h_
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* System independent thread management routines for SDL */
|
||||
// System independent thread management routines for SDL
|
||||
|
||||
#include "SDL_thread_c.h"
|
||||
#include "SDL_systhread.h"
|
||||
#include "../SDL_error_c.h"
|
||||
|
||||
/* The storage is local to the thread, but the IDs are global for the process */
|
||||
// The storage is local to the thread, but the IDs are global for the process
|
||||
|
||||
static SDL_AtomicInt SDL_tls_allocated;
|
||||
static SDL_AtomicInt SDL_tls_id;
|
||||
@@ -69,7 +69,7 @@ int SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destr
|
||||
*/
|
||||
SDL_InitTLSData();
|
||||
|
||||
/* Get the storage index associated with the ID in a thread-safe way */
|
||||
// Get the storage index associated with the ID in a thread-safe way
|
||||
storage_index = SDL_AtomicGet(id) - 1;
|
||||
if (storage_index < 0) {
|
||||
int new_id = (SDL_AtomicIncRef(&SDL_tls_id) + 1);
|
||||
@@ -82,7 +82,7 @@ int SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destr
|
||||
storage_index = SDL_AtomicGet(id) - 1;
|
||||
}
|
||||
|
||||
/* Get the storage for the current thread */
|
||||
// Get the storage for the current thread
|
||||
storage = SDL_SYS_GetTLSData();
|
||||
if (!storage || storage_index >= storage->limit) {
|
||||
unsigned int i, oldlimit, newlimit;
|
||||
@@ -116,7 +116,7 @@ void SDL_CleanupTLS(void)
|
||||
{
|
||||
SDL_TLSData *storage;
|
||||
|
||||
/* Cleanup the storage for the current thread */
|
||||
// Cleanup the storage for the current thread
|
||||
storage = SDL_SYS_GetTLSData();
|
||||
if (storage) {
|
||||
int i;
|
||||
@@ -138,7 +138,7 @@ void SDL_QuitTLSData(void)
|
||||
if (SDL_AtomicGet(&SDL_tls_allocated) == 0) {
|
||||
SDL_SYS_QuitTLSData();
|
||||
} else {
|
||||
/* Some thread hasn't called SDL_CleanupTLS() */
|
||||
// Some thread hasn't called SDL_CleanupTLS()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ void SDL_Generic_QuitTLSData(void)
|
||||
{
|
||||
SDL_TLSEntry *entry;
|
||||
|
||||
/* This should have been cleaned up by the time we get here */
|
||||
// This should have been cleaned up by the time we get here
|
||||
SDL_assert(!SDL_generic_TLS);
|
||||
if (SDL_generic_TLS) {
|
||||
SDL_LockMutex(SDL_generic_TLS_mutex);
|
||||
@@ -249,7 +249,7 @@ void SDL_Generic_QuitTLSData(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* Non-thread-safe global error variable */
|
||||
// Non-thread-safe global error variable
|
||||
static SDL_error *SDL_GetStaticErrBuf(void)
|
||||
{
|
||||
static SDL_error SDL_global_error;
|
||||
@@ -271,7 +271,7 @@ static void SDLCALL SDL_FreeErrBuf(void *data)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Routine to get the thread-specific error variable */
|
||||
// Routine to get the thread-specific error variable
|
||||
SDL_error *SDL_GetErrBuf(SDL_bool create)
|
||||
{
|
||||
#ifdef SDL_THREADS_DISABLED
|
||||
@@ -303,7 +303,7 @@ SDL_error *SDL_GetErrBuf(SDL_bool create)
|
||||
SDL_SetTLS(&tls_errbuf, errbuf, SDL_FreeErrBuf);
|
||||
}
|
||||
return errbuf;
|
||||
#endif /* SDL_THREADS_DISABLED */
|
||||
#endif // SDL_THREADS_DISABLED
|
||||
}
|
||||
|
||||
void SDL_RunThread(SDL_Thread *thread)
|
||||
@@ -313,23 +313,23 @@ void SDL_RunThread(SDL_Thread *thread)
|
||||
|
||||
int *statusloc = &thread->status;
|
||||
|
||||
/* Perform any system-dependent setup - this function may not fail */
|
||||
// Perform any system-dependent setup - this function may not fail
|
||||
SDL_SYS_SetupThread(thread->name);
|
||||
|
||||
/* Get the thread id */
|
||||
// Get the thread id
|
||||
thread->threadid = SDL_GetCurrentThreadID();
|
||||
|
||||
/* Run the function */
|
||||
// Run the function
|
||||
*statusloc = userfunc(userdata);
|
||||
|
||||
/* Clean up thread-local storage */
|
||||
// Clean up thread-local storage
|
||||
SDL_CleanupTLS();
|
||||
|
||||
/* Mark us as ready to be joined (or detached) */
|
||||
// Mark us as ready to be joined (or detached)
|
||||
if (!SDL_AtomicCompareAndSwap(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_ZOMBIE)) {
|
||||
/* Clean up if something already detached us. */
|
||||
// Clean up if something already detached us.
|
||||
if (SDL_AtomicCompareAndSwap(&thread->state, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_CLEANED)) {
|
||||
SDL_free(thread->name); /* Can't free later, we've already cleaned up TLS */
|
||||
SDL_free(thread->name); // Can't free later, we've already cleaned up TLS
|
||||
SDL_free(thread);
|
||||
}
|
||||
}
|
||||
@@ -462,16 +462,16 @@ void SDL_DetachThread(SDL_Thread *thread)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Grab dibs if the state is alive+joinable. */
|
||||
// Grab dibs if the state is alive+joinable.
|
||||
if (SDL_AtomicCompareAndSwap(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_DETACHED)) {
|
||||
SDL_SYS_DetachThread(thread);
|
||||
} else {
|
||||
/* all other states are pretty final, see where we landed. */
|
||||
// all other states are pretty final, see where we landed.
|
||||
const int thread_state = SDL_AtomicGet(&thread->state);
|
||||
if ((thread_state == SDL_THREAD_STATE_DETACHED) || (thread_state == SDL_THREAD_STATE_CLEANED)) {
|
||||
return; /* already detached (you shouldn't call this twice!) */
|
||||
return; // already detached (you shouldn't call this twice!)
|
||||
} else if (thread_state == SDL_THREAD_STATE_ZOMBIE) {
|
||||
SDL_WaitThread(thread, NULL); /* already done, clean it up. */
|
||||
SDL_WaitThread(thread, NULL); // already done, clean it up.
|
||||
} else {
|
||||
SDL_assert(0 && "Unexpected thread state");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#ifndef SDL_thread_c_h_
|
||||
#define SDL_thread_c_h_
|
||||
|
||||
/* Need the definitions of SYS_ThreadHandle */
|
||||
// Need the definitions of SYS_ThreadHandle
|
||||
#ifdef SDL_THREADS_DISABLED
|
||||
#include "generic/SDL_systhread_c.h"
|
||||
#elif defined(SDL_THREAD_PTHREAD)
|
||||
@@ -56,7 +56,7 @@ typedef enum SDL_ThreadState
|
||||
SDL_THREAD_STATE_CLEANED,
|
||||
} SDL_ThreadState;
|
||||
|
||||
/* This is the system-independent thread info structure */
|
||||
// This is the system-independent thread info structure
|
||||
struct SDL_Thread
|
||||
{
|
||||
SDL_ThreadID threadid;
|
||||
@@ -65,17 +65,17 @@ struct SDL_Thread
|
||||
SDL_AtomicInt state; /* SDL_THREAD_STATE_* */
|
||||
SDL_error errbuf;
|
||||
char *name;
|
||||
size_t stacksize; /* 0 for default, >0 for user-specified stack size. */
|
||||
size_t stacksize; // 0 for default, >0 for user-specified stack size.
|
||||
int(SDLCALL *userfunc)(void *);
|
||||
void *userdata;
|
||||
void *data;
|
||||
SDL_FunctionPointer endfunc; /* only used on some platforms. */
|
||||
SDL_FunctionPointer endfunc; // only used on some platforms.
|
||||
};
|
||||
|
||||
/* This is the function called to run a thread */
|
||||
// This is the function called to run a thread
|
||||
extern void SDL_RunThread(SDL_Thread *thread);
|
||||
|
||||
/* This is the system-independent thread local storage structure */
|
||||
// This is the system-independent thread local storage structure
|
||||
typedef struct
|
||||
{
|
||||
int limit;
|
||||
@@ -86,7 +86,7 @@ typedef struct
|
||||
} array[1];
|
||||
} SDL_TLSData;
|
||||
|
||||
/* This is how many TLS entries we allocate at once */
|
||||
// This is how many TLS entries we allocate at once
|
||||
#define TLS_ALLOC_CHUNKSIZE 4
|
||||
|
||||
extern void SDL_InitTLSData(void);
|
||||
@@ -101,4 +101,4 @@ extern SDL_TLSData *SDL_Generic_GetTLSData(void);
|
||||
extern int SDL_Generic_SetTLSData(SDL_TLSData *data);
|
||||
extern void SDL_Generic_QuitTLSData(void);
|
||||
|
||||
#endif /* SDL_thread_c_h_ */
|
||||
#endif // SDL_thread_c_h_
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* An implementation of condition variables using semaphores and mutexes */
|
||||
// An implementation of condition variables using semaphores and mutexes
|
||||
/*
|
||||
This implementation borrows heavily from the BeOS condition variable
|
||||
implementation, written by Christopher Tate and Owen Smith. Thanks!
|
||||
@@ -49,7 +49,7 @@ typedef struct SDL_cond_generic
|
||||
SDL_Semaphore *wait_done;
|
||||
} SDL_cond_generic;
|
||||
|
||||
/* Create a condition variable */
|
||||
// Create a condition variable
|
||||
SDL_Condition *SDL_CreateCondition_generic(void)
|
||||
{
|
||||
SDL_cond_generic *cond = (SDL_cond_generic *)SDL_calloc(1, sizeof(*cond));
|
||||
@@ -70,7 +70,7 @@ SDL_Condition *SDL_CreateCondition_generic(void)
|
||||
return (SDL_Condition *)cond;
|
||||
}
|
||||
|
||||
/* Destroy a condition variable */
|
||||
// Destroy a condition variable
|
||||
void SDL_DestroyCondition_generic(SDL_Condition *_cond)
|
||||
{
|
||||
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
|
||||
@@ -88,7 +88,7 @@ void SDL_DestroyCondition_generic(SDL_Condition *_cond)
|
||||
}
|
||||
}
|
||||
|
||||
/* Restart one of the threads that are waiting on the condition variable */
|
||||
// Restart one of the threads that are waiting on the condition variable
|
||||
int SDL_SignalCondition_generic(SDL_Condition *_cond)
|
||||
{
|
||||
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
|
||||
@@ -114,7 +114,7 @@ int SDL_SignalCondition_generic(SDL_Condition *_cond)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Restart all threads that are waiting on the condition variable */
|
||||
// Restart all threads that are waiting on the condition variable
|
||||
int SDL_BroadcastCondition_generic(SDL_Condition *_cond)
|
||||
{
|
||||
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
|
||||
@@ -189,10 +189,10 @@ int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, S
|
||||
++cond->waiting;
|
||||
SDL_UnlockMutex(cond->lock);
|
||||
|
||||
/* Unlock the mutex, as is required by condition variable semantics */
|
||||
// Unlock the mutex, as is required by condition variable semantics
|
||||
SDL_UnlockMutex(mutex);
|
||||
|
||||
/* Wait for a signal */
|
||||
// Wait for a signal
|
||||
retval = SDL_WaitSemaphoreTimeoutNS(cond->wait_sem, timeoutNS);
|
||||
|
||||
/* Let the signaler know we have completed the wait, otherwise
|
||||
@@ -203,20 +203,20 @@ int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, S
|
||||
*/
|
||||
SDL_LockMutex(cond->lock);
|
||||
if (cond->signals > 0) {
|
||||
/* If we timed out, we need to eat a condition signal */
|
||||
// If we timed out, we need to eat a condition signal
|
||||
if (retval > 0) {
|
||||
SDL_WaitSemaphore(cond->wait_sem);
|
||||
}
|
||||
/* We always notify the signal thread that we are done */
|
||||
// We always notify the signal thread that we are done
|
||||
SDL_SignalSemaphore(cond->wait_done);
|
||||
|
||||
/* Signal handshake complete */
|
||||
// Signal handshake complete
|
||||
--cond->signals;
|
||||
}
|
||||
--cond->waiting;
|
||||
SDL_UnlockMutex(cond->lock);
|
||||
|
||||
/* Lock the mutex, as is required by condition variable semantics */
|
||||
// Lock the mutex, as is required by condition variable semantics
|
||||
SDL_LockMutex(mutex);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -31,6 +31,6 @@ int SDL_SignalCondition_generic(SDL_Condition *cond);
|
||||
int SDL_BroadcastCondition_generic(SDL_Condition *cond);
|
||||
int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS);
|
||||
|
||||
#endif /* SDL_THREAD_GENERIC_COND_SUFFIX */
|
||||
#endif // SDL_THREAD_GENERIC_COND_SUFFIX
|
||||
|
||||
#endif /* SDL_syscond_generic_h_ */
|
||||
#endif // SDL_syscond_generic_h_
|
||||
|
||||
@@ -37,7 +37,7 @@ SDL_Mutex *SDL_CreateMutex(void)
|
||||
|
||||
#ifndef SDL_THREADS_DISABLED
|
||||
if (mutex) {
|
||||
/* Create the mutex semaphore, with initial value 1 */
|
||||
// Create the mutex semaphore, with initial value 1
|
||||
mutex->sem = SDL_CreateSemaphore(1);
|
||||
mutex->recursive = 0;
|
||||
mutex->owner = 0;
|
||||
@@ -78,7 +78,7 @@ void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doe
|
||||
mutex->recursive = 0;
|
||||
}
|
||||
}
|
||||
#endif /* SDL_THREADS_DISABLED */
|
||||
#endif // SDL_THREADS_DISABLED
|
||||
}
|
||||
|
||||
int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* An implementation of semaphores using mutexes and condition variables */
|
||||
// An implementation of semaphores using mutexes and condition variables
|
||||
|
||||
#include "SDL_systhread_c.h"
|
||||
|
||||
@@ -111,7 +111,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
/* A timeout of 0 is an easy case */
|
||||
// A timeout of 0 is an easy case
|
||||
if (timeoutNS == 0) {
|
||||
retval = SDL_MUTEX_TIMEDOUT;
|
||||
SDL_LockMutex(sem->count_lock);
|
||||
@@ -169,4 +169,4 @@ int SDL_SignalSemaphore(SDL_Semaphore *sem)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREADS_DISABLED */
|
||||
#endif // SDL_THREADS_DISABLED
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* Thread management routines for SDL */
|
||||
// Thread management routines for SDL
|
||||
|
||||
#include "../SDL_systhread.h"
|
||||
|
||||
|
||||
@@ -20,5 +20,5 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* Stub until we implement threads on this platform */
|
||||
// Stub until we implement threads on this platform
|
||||
typedef int SYS_ThreadHandle;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_N3DS
|
||||
|
||||
/* An implementation of condition variables using libctru's CondVar */
|
||||
// An implementation of condition variables using libctru's CondVar
|
||||
|
||||
#include "SDL_sysmutex_c.h"
|
||||
|
||||
@@ -31,7 +31,7 @@ struct SDL_Condition
|
||||
CondVar cond_variable;
|
||||
};
|
||||
|
||||
/* Create a condition variable */
|
||||
// Create a condition variable
|
||||
SDL_Condition *SDL_CreateCondition(void)
|
||||
{
|
||||
SDL_Condition *cond = (SDL_Condition *)SDL_malloc(sizeof(SDL_Condition));
|
||||
@@ -41,7 +41,7 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
return cond;
|
||||
}
|
||||
|
||||
/* Destroy a condition variable */
|
||||
// Destroy a condition variable
|
||||
void SDL_DestroyCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond) {
|
||||
@@ -49,7 +49,7 @@ void SDL_DestroyCondition(SDL_Condition *cond)
|
||||
}
|
||||
}
|
||||
|
||||
/* Restart one of the threads that are waiting on the condition variable */
|
||||
// Restart one of the threads that are waiting on the condition variable
|
||||
int SDL_SignalCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (!cond) {
|
||||
@@ -60,7 +60,7 @@ int SDL_SignalCondition(SDL_Condition *cond)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Restart all threads that are waiting on the condition variable */
|
||||
// Restart all threads that are waiting on the condition variable
|
||||
int SDL_BroadcastCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (!cond) {
|
||||
@@ -113,4 +113,4 @@ int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 tim
|
||||
return R_SUCCEEDED(res) ? 0 : SDL_MUTEX_TIMEDOUT;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_N3DS */
|
||||
#endif // SDL_THREAD_N3DS
|
||||
|
||||
@@ -30,4 +30,4 @@ struct SDL_Mutex
|
||||
RecursiveLock lock;
|
||||
};
|
||||
|
||||
#endif /* SDL_sysmutex_c_h */
|
||||
#endif // SDL_sysmutex_c_h
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_N3DS
|
||||
|
||||
/* An implementation of semaphores using libctru's LightSemaphore */
|
||||
// An implementation of semaphores using libctru's LightSemaphore
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
@@ -86,12 +86,12 @@ int WaitOnSemaphoreFor(SDL_Semaphore *sem, Sint64 timeout)
|
||||
if (LightSemaphore_TryAcquire(&sem->semaphore, 1) == 0) {
|
||||
return 0;
|
||||
}
|
||||
/* 100 microseconds seems to be the sweet spot */
|
||||
// 100 microseconds seems to be the sweet spot
|
||||
SDL_DelayNS(SDL_US_TO_NS(100));
|
||||
current_time = SDL_GetTicksNS();
|
||||
}
|
||||
|
||||
/* If we failed, yield to avoid starvation on busy waits */
|
||||
// If we failed, yield to avoid starvation on busy waits
|
||||
SDL_DelayNS(1);
|
||||
return SDL_MUTEX_TIMEDOUT;
|
||||
}
|
||||
@@ -114,4 +114,4 @@ int SDL_SignalSemaphore(SDL_Semaphore *sem)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_N3DS */
|
||||
#endif // SDL_THREAD_N3DS
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
|
||||
#ifdef SDL_THREAD_N3DS
|
||||
|
||||
/* Thread management routines for SDL */
|
||||
// Thread management routines for SDL
|
||||
|
||||
#include "../SDL_systhread.h"
|
||||
|
||||
/* N3DS has very limited RAM (128MB), so we set a low default thread stack size. */
|
||||
// N3DS has very limited RAM (128MB), so we set a low default thread stack size.
|
||||
#define N3DS_THREAD_STACK_SIZE_DEFAULT (80 * 1024)
|
||||
|
||||
#define N3DS_THREAD_PRIORITY_LOW 0x3F /**< Minimum priority */
|
||||
@@ -53,7 +53,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
|
||||
svcGetThreadPriority(&priority, CUR_THREAD_HANDLE);
|
||||
|
||||
/* prefer putting audio thread on system core */
|
||||
// prefer putting audio thread on system core
|
||||
if (thread->name && (SDL_strncmp(thread->name, "SDLAudioP", 9) == 0) && R_SUCCEEDED(APT_SetAppCpuTimeLimit(30))) {
|
||||
cpu = 1;
|
||||
}
|
||||
@@ -133,4 +133,4 @@ void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
threadDetach(thread->handle);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_N3DS */
|
||||
#endif // SDL_THREAD_N3DS
|
||||
|
||||
@@ -27,4 +27,4 @@
|
||||
|
||||
typedef Thread SYS_ThreadHandle;
|
||||
|
||||
#endif /* SDL_systhread_c_h_ */
|
||||
#endif // SDL_systhread_c_h_
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* An implementation of mutexes using the Symbian API. */
|
||||
// An implementation of mutexes using the Symbian API.
|
||||
|
||||
#include <e32std.h>
|
||||
|
||||
@@ -38,7 +38,7 @@ static TInt NewMutex(const TDesC &aName, TAny *aPtr1, TAny *)
|
||||
return ((RMutex *)aPtr1)->CreateGlobal(aName);
|
||||
}
|
||||
|
||||
/* Create a mutex */
|
||||
// Create a mutex
|
||||
SDL_Mutex *SDL_CreateMutex(void)
|
||||
{
|
||||
RMutex rmutex;
|
||||
@@ -53,7 +53,7 @@ SDL_Mutex *SDL_CreateMutex(void)
|
||||
return mutex;
|
||||
}
|
||||
|
||||
/* Free the mutex */
|
||||
// Free the mutex
|
||||
void SDL_DestroyMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
if (mutex) {
|
||||
@@ -66,8 +66,8 @@ void SDL_DestroyMutex(SDL_Mutex *mutex)
|
||||
}
|
||||
}
|
||||
|
||||
/* Lock the mutex */
|
||||
void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS /* clang doesn't know about NULL mutexes */
|
||||
// Lock the mutex
|
||||
void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
|
||||
{
|
||||
if (mutex != NULL) {
|
||||
RMutex rmutex;
|
||||
@@ -76,7 +76,7 @@ void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS /* clang does
|
||||
}
|
||||
}
|
||||
|
||||
/* Try to lock the mutex */
|
||||
// Try to lock the mutex
|
||||
#if 0
|
||||
int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
@@ -90,8 +90,8 @@ int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Unlock the mutex */
|
||||
void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS /* clang doesn't know about NULL mutexes */
|
||||
// Unlock the mutex
|
||||
void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
|
||||
{
|
||||
if (mutex != NULL) {
|
||||
RMutex rmutex;
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* An implementation of semaphores using the Symbian API. */
|
||||
// An implementation of semaphores using the Symbian API.
|
||||
|
||||
#include <e32std.h>
|
||||
|
||||
/* !!! FIXME: Should this be SDL_MUTEX_TIMEDOUT? */
|
||||
// !!! FIXME: Should this be SDL_MUTEX_TIMEDOUT?
|
||||
#define SDL_MUTEX_TIMEOUT -2
|
||||
|
||||
struct SDL_Semaphore
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_NGAGE
|
||||
|
||||
/* N-Gage thread management routines for SDL */
|
||||
// N-Gage thread management routines for SDL
|
||||
|
||||
#include <e32std.h>
|
||||
|
||||
@@ -109,4 +109,4 @@ void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_NGAGE */
|
||||
#endif // SDL_THREAD_NGAGE
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_PS2
|
||||
|
||||
/* Semaphore functions for the PS2. */
|
||||
// Semaphore functions for the PS2.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -35,7 +35,7 @@ struct SDL_Semaphore
|
||||
s32 semid;
|
||||
};
|
||||
|
||||
/* Create a semaphore */
|
||||
// Create a semaphore
|
||||
SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
SDL_Semaphore *sem;
|
||||
@@ -43,7 +43,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
|
||||
sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem));
|
||||
if (sem) {
|
||||
/* TODO: Figure out the limit on the maximum value. */
|
||||
// TODO: Figure out the limit on the maximum value.
|
||||
sema.init_count = initial_value;
|
||||
sema.max_count = 255;
|
||||
sema.option = 0;
|
||||
@@ -59,7 +59,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
return sem;
|
||||
}
|
||||
|
||||
/* Free the semaphore */
|
||||
// Free the semaphore
|
||||
void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem) {
|
||||
@@ -104,7 +104,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
return 0; // Wait condition satisfied.
|
||||
}
|
||||
|
||||
/* Returns the current count of the semaphore */
|
||||
// Returns the current count of the semaphore
|
||||
Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
{
|
||||
ee_sema_t info;
|
||||
@@ -137,4 +137,4 @@ int SDL_SignalSemaphore(SDL_Semaphore *sem)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_PS2 */
|
||||
#endif // SDL_THREAD_PS2
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_PS2
|
||||
|
||||
/* PS2 thread management routines for SDL */
|
||||
// PS2 thread management routines for SDL
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -64,7 +64,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
size_t stack_size;
|
||||
int priority = 32;
|
||||
|
||||
/* Set priority of new thread to the same as the current thread */
|
||||
// Set priority of new thread to the same as the current thread
|
||||
// status.size = sizeof(ee_thread_t);
|
||||
if (ReferThreadStatus(GetThreadId(), &status) == 0) {
|
||||
priority = status.current_priority;
|
||||
@@ -72,7 +72,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
|
||||
stack_size = thread->stacksize ? ((int)thread->stacksize) : 0x1800;
|
||||
|
||||
/* Create EE Thread */
|
||||
// Create EE Thread
|
||||
eethread.attr = 0;
|
||||
eethread.option = 0;
|
||||
eethread.func = &childThread;
|
||||
@@ -97,7 +97,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
|
||||
void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
/* Do nothing. */
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
SDL_ThreadID SDL_GetCurrentThreadID(void)
|
||||
@@ -114,7 +114,7 @@ void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
|
||||
void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
/* Do nothing. */
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
@@ -134,4 +134,4 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
return ChangeThreadPriority(GetThreadId(), value);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_PS2 */
|
||||
#endif // SDL_THREAD_PS2
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_PSP
|
||||
|
||||
/* Semaphore functions for the PSP. */
|
||||
// Semaphore functions for the PSP.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -35,14 +35,14 @@ struct SDL_Semaphore
|
||||
SceUID semid;
|
||||
};
|
||||
|
||||
/* Create a semaphore */
|
||||
// Create a semaphore
|
||||
SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
SDL_Semaphore *sem;
|
||||
|
||||
sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem));
|
||||
if (sem) {
|
||||
/* TODO: Figure out the limit on the maximum value. */
|
||||
// TODO: Figure out the limit on the maximum value.
|
||||
sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
|
||||
if (sem->semid < 0) {
|
||||
SDL_SetError("Couldn't create semaphore");
|
||||
@@ -54,7 +54,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
return sem;
|
||||
}
|
||||
|
||||
/* Free the semaphore */
|
||||
// Free the semaphore
|
||||
void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem) {
|
||||
@@ -92,7 +92,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
if (timeoutNS < 0) {
|
||||
pTimeout = NULL;
|
||||
} else {
|
||||
timeoutUS = (SceUInt)SDL_NS_TO_US(timeoutNS); /* Convert to microseconds. */
|
||||
timeoutUS = (SceUInt)SDL_NS_TO_US(timeoutNS); // Convert to microseconds.
|
||||
pTimeout = &timeoutUS;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns the current count of the semaphore */
|
||||
// Returns the current count of the semaphore
|
||||
Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
{
|
||||
SceKernelSemaInfo info;
|
||||
@@ -140,4 +140,4 @@ int SDL_SignalSemaphore(SDL_Semaphore *sem)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_PSP */
|
||||
#endif // SDL_THREAD_PSP
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_PSP
|
||||
|
||||
/* PSP thread management routines for SDL */
|
||||
// PSP thread management routines for SDL
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -45,7 +45,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SceKernelThreadInfo status;
|
||||
int priority = 32;
|
||||
|
||||
/* Set priority of new thread to the same as the current thread */
|
||||
// Set priority of new thread to the same as the current thread
|
||||
status.size = sizeof(SceKernelThreadInfo);
|
||||
if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
|
||||
priority = status.currentPriority;
|
||||
@@ -64,7 +64,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
|
||||
void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
/* Do nothing. */
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
SDL_ThreadID SDL_GetCurrentThreadID(void)
|
||||
@@ -80,7 +80,7 @@ void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
|
||||
void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
/* !!! FIXME: is this correct? */
|
||||
// !!! FIXME: is this correct?
|
||||
sceKernelDeleteThread(thread->handle);
|
||||
}
|
||||
|
||||
@@ -106,4 +106,4 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
return sceKernelChangeThreadPriority(sceKernelGetThreadId(), value);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_PSP */
|
||||
#endif // SDL_THREAD_PSP
|
||||
|
||||
@@ -33,7 +33,7 @@ struct SDL_Condition
|
||||
pthread_cond_t cond;
|
||||
};
|
||||
|
||||
/* Create a condition variable */
|
||||
// Create a condition variable
|
||||
SDL_Condition *SDL_CreateCondition(void)
|
||||
{
|
||||
SDL_Condition *cond;
|
||||
@@ -49,7 +49,7 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
return cond;
|
||||
}
|
||||
|
||||
/* Destroy a condition variable */
|
||||
// Destroy a condition variable
|
||||
void SDL_DestroyCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond) {
|
||||
@@ -58,7 +58,7 @@ void SDL_DestroyCondition(SDL_Condition *cond)
|
||||
}
|
||||
}
|
||||
|
||||
/* Restart one of the threads that are waiting on the condition variable */
|
||||
// Restart one of the threads that are waiting on the condition variable
|
||||
int SDL_SignalCondition(SDL_Condition *cond)
|
||||
{
|
||||
int retval;
|
||||
@@ -74,7 +74,7 @@ int SDL_SignalCondition(SDL_Condition *cond)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Restart all threads that are waiting on the condition variable */
|
||||
// Restart all threads that are waiting on the condition variable
|
||||
int SDL_BroadcastCondition(SDL_Condition *cond)
|
||||
{
|
||||
int retval;
|
||||
@@ -130,7 +130,7 @@ tryagain:
|
||||
switch (retval) {
|
||||
case EINTR:
|
||||
goto tryagain;
|
||||
/* break; -Wunreachable-code-break */
|
||||
// break; -Wunreachable-code-break
|
||||
case ETIMEDOUT:
|
||||
retval = SDL_MUTEX_TIMEDOUT;
|
||||
break;
|
||||
|
||||
@@ -37,4 +37,4 @@ struct SDL_Mutex
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* SDL_mutex_c_h_ */
|
||||
#endif // SDL_mutex_c_h_
|
||||
|
||||
@@ -33,7 +33,7 @@ SDL_RWLock *SDL_CreateRWLock(void)
|
||||
{
|
||||
SDL_RWLock *rwlock;
|
||||
|
||||
/* Allocate the structure */
|
||||
// Allocate the structure
|
||||
rwlock = (SDL_RWLock *)SDL_calloc(1, sizeof(*rwlock));
|
||||
if (rwlock) {
|
||||
if (pthread_rwlock_init(&rwlock->id, NULL) != 0) {
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Wrapper around POSIX 1003.1b semaphores */
|
||||
// Wrapper around POSIX 1003.1b semaphores
|
||||
|
||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)
|
||||
/* macOS doesn't support sem_getvalue() as of version 10.4 */
|
||||
// macOS doesn't support sem_getvalue() as of version 10.4
|
||||
#include "../generic/SDL_syssem.c"
|
||||
#else
|
||||
|
||||
@@ -38,7 +38,7 @@ struct SDL_Semaphore
|
||||
sem_t sem;
|
||||
};
|
||||
|
||||
/* Create a semaphore, initialized with value */
|
||||
// Create a semaphore, initialized with value
|
||||
SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
SDL_Semaphore *sem = (SDL_Semaphore *)SDL_malloc(sizeof(SDL_Semaphore));
|
||||
@@ -76,7 +76,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
/* Try the easy cases first */
|
||||
// Try the easy cases first
|
||||
if (timeoutNS == 0) {
|
||||
retval = SDL_MUTEX_TIMEDOUT;
|
||||
if (sem_trywait(&sem->sem) == 0) {
|
||||
@@ -103,24 +103,24 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
clock_gettime(CLOCK_REALTIME, &ts_timeout);
|
||||
|
||||
/* Add our timeout to current time */
|
||||
// Add our timeout to current time
|
||||
ts_timeout.tv_sec += (timeoutNS / SDL_NS_PER_SECOND);
|
||||
ts_timeout.tv_nsec += (timeoutNS % SDL_NS_PER_SECOND);
|
||||
#else
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
/* Add our timeout to current time */
|
||||
// Add our timeout to current time
|
||||
ts_timeout.tv_sec = now.tv_sec + (timeoutNS / SDL_NS_PER_SECOND);
|
||||
ts_timeout.tv_nsec = SDL_US_TO_NS(now.tv_usec) + (timeoutNS % SDL_NS_PER_SECOND);
|
||||
#endif
|
||||
|
||||
/* Wrap the second if needed */
|
||||
// Wrap the second if needed
|
||||
while (ts_timeout.tv_nsec >= 1000000000) {
|
||||
ts_timeout.tv_sec += 1;
|
||||
ts_timeout.tv_nsec -= 1000000000;
|
||||
}
|
||||
|
||||
/* Wait. */
|
||||
// Wait.
|
||||
do {
|
||||
retval = sem_timedwait(&sem->sem, &ts_timeout);
|
||||
} while (retval < 0 && errno == EINTR);
|
||||
@@ -141,7 +141,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
}
|
||||
SDL_DelayNS(100);
|
||||
}
|
||||
#endif /* HAVE_SEM_TIMEDWAIT */
|
||||
#endif // HAVE_SEM_TIMEDWAIT
|
||||
|
||||
return retval;
|
||||
}
|
||||
@@ -177,4 +177,4 @@ int SDL_SignalSemaphore(SDL_Semaphore *sem)
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_PLATFORM_MACOS */
|
||||
#endif // SDL_PLATFORM_MACOS
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../core/linux/SDL_dbus.h"
|
||||
#endif /* SDL_PLATFORM_LINUX */
|
||||
#endif // SDL_PLATFORM_LINUX
|
||||
|
||||
#if (defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS)) && defined(HAVE_DLOPEN)
|
||||
#include <dlfcn.h>
|
||||
@@ -55,7 +55,7 @@
|
||||
#include <kernel/OS.h>
|
||||
#endif
|
||||
|
||||
/* List of signals to mask in the subthreads */
|
||||
// List of signals to mask in the subthreads
|
||||
static const int sig_list[] = {
|
||||
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
|
||||
SIGVTALRM, SIGPROF, 0
|
||||
@@ -83,7 +83,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
{
|
||||
pthread_attr_t type;
|
||||
|
||||
/* do this here before any threads exist, so there's no race condition. */
|
||||
// do this here before any threads exist, so there's no race condition.
|
||||
#if (defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_LINUX)) && defined(HAVE_DLOPEN)
|
||||
if (!checked_setname) {
|
||||
void *fn = dlsym(RTLD_DEFAULT, "pthread_setname_np");
|
||||
@@ -96,18 +96,18 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set the thread attributes */
|
||||
// Set the thread attributes
|
||||
if (pthread_attr_init(&type) != 0) {
|
||||
return SDL_SetError("Couldn't initialize pthread attributes");
|
||||
}
|
||||
pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
/* Set caller-requested stack size. Otherwise: use the system default. */
|
||||
// Set caller-requested stack size. Otherwise: use the system default.
|
||||
if (thread->stacksize) {
|
||||
pthread_attr_setstacksize(&type, thread->stacksize);
|
||||
}
|
||||
|
||||
/* Create the thread and go! */
|
||||
// Create the thread and go!
|
||||
if (pthread_create(&thread->handle, &type, RunThread, thread) != 0) {
|
||||
return SDL_SetError("Not enough resources to create thread");
|
||||
}
|
||||
@@ -128,7 +128,7 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
ppthread_setname_np(name);
|
||||
#elif defined(SDL_PLATFORM_LINUX)
|
||||
if (ppthread_setname_np(pthread_self(), name) == ERANGE) {
|
||||
char namebuf[16]; /* Limited to 16 char */
|
||||
char namebuf[16]; // Limited to 16 char
|
||||
SDL_strlcpy(namebuf, name, sizeof(namebuf));
|
||||
ppthread_setname_np(pthread_self(), namebuf);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
pthread_setname_np(pthread_self(), "%s", name);
|
||||
#else
|
||||
if (pthread_setname_np(pthread_self(), name) == ERANGE) {
|
||||
char namebuf[16]; /* Limited to 16 char */
|
||||
char namebuf[16]; // Limited to 16 char
|
||||
SDL_strlcpy(namebuf, name, sizeof(namebuf));
|
||||
pthread_setname_np(pthread_self(), namebuf);
|
||||
}
|
||||
@@ -147,14 +147,14 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
|
||||
pthread_set_name_np(pthread_self(), name);
|
||||
#elif defined(SDL_PLATFORM_HAIKU)
|
||||
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
|
||||
// The docs say the thread name can't be longer than B_OS_NAME_LENGTH.
|
||||
char namebuf[B_OS_NAME_LENGTH];
|
||||
SDL_strlcpy(namebuf, name, sizeof(namebuf));
|
||||
rename_thread(find_thread(NULL), namebuf);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Mask asynchronous signals for this thread */
|
||||
// Mask asynchronous signals for this thread
|
||||
sigemptyset(&mask);
|
||||
for (i = 0; sig_list[i]; ++i) {
|
||||
sigaddset(&mask, sig_list[i]);
|
||||
@@ -162,7 +162,7 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
pthread_sigmask(SIG_BLOCK, &mask, 0);
|
||||
|
||||
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
|
||||
/* Allow ourselves to be asynchronously cancelled */
|
||||
// Allow ourselves to be asynchronously cancelled
|
||||
{
|
||||
int oldstate;
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
|
||||
@@ -178,7 +178,7 @@ SDL_ThreadID SDL_GetCurrentThreadID(void)
|
||||
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
#ifdef SDL_PLATFORM_RISCOS
|
||||
/* FIXME: Setting thread priority does not seem to be supported */
|
||||
// FIXME: Setting thread priority does not seem to be supported
|
||||
return 0;
|
||||
#else
|
||||
struct sched_param sched;
|
||||
@@ -203,7 +203,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
case SDL_THREAD_PRIORITY_HIGH:
|
||||
case SDL_THREAD_PRIORITY_TIME_CRITICAL:
|
||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS)
|
||||
/* Apple requires SCHED_RR for high priority threads */
|
||||
// Apple requires SCHED_RR for high priority threads
|
||||
pri_policy = SCHED_RR;
|
||||
break;
|
||||
#else
|
||||
@@ -221,7 +221,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
|
||||
if (policyhint) {
|
||||
if (SDL_strcmp(policyhint, "current") == 0) {
|
||||
/* Leave current thread scheduler policy unchanged */
|
||||
// Leave current thread scheduler policy unchanged
|
||||
} else if (SDL_strcmp(policyhint, "other") == 0) {
|
||||
policy = SCHED_OTHER;
|
||||
} else if (SDL_strcmp(policyhint, "rr") == 0) {
|
||||
@@ -251,14 +251,14 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
|
||||
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS)
|
||||
if (min_priority == 15 && max_priority == 47) {
|
||||
/* Apple has a specific set of thread priorities */
|
||||
// Apple has a specific set of thread priorities
|
||||
if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
sched.sched_priority = 45;
|
||||
} else {
|
||||
sched.sched_priority = 37;
|
||||
}
|
||||
} else
|
||||
#endif /* SDL_PLATFORM_MACOS || SDL_PLATFORM_IOS || SDL_PLATFORM_TVOS */
|
||||
#endif // SDL_PLATFORM_MACOS || SDL_PLATFORM_IOS || SDL_PLATFORM_TVOS
|
||||
{
|
||||
sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
|
||||
if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
@@ -270,8 +270,8 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
return SDL_SetError("pthread_setschedparam() failed");
|
||||
}
|
||||
return 0;
|
||||
#endif /* linux */
|
||||
#endif /* #if SDL_PLATFORM_RISCOS */
|
||||
#endif // linux
|
||||
#endif // #if SDL_PLATFORM_RISCOS
|
||||
}
|
||||
|
||||
void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
|
||||
@@ -35,11 +35,11 @@ struct SDL_Condition
|
||||
std::condition_variable_any cpp_cond;
|
||||
};
|
||||
|
||||
/* Create a condition variable */
|
||||
// Create a condition variable
|
||||
extern "C" SDL_Condition *
|
||||
SDL_CreateCondition(void)
|
||||
{
|
||||
/* Allocate and initialize the condition variable */
|
||||
// Allocate and initialize the condition variable
|
||||
try {
|
||||
SDL_Condition *cond = new SDL_Condition;
|
||||
return cond;
|
||||
@@ -52,7 +52,7 @@ SDL_CreateCondition(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* Destroy a condition variable */
|
||||
// Destroy a condition variable
|
||||
extern "C" void
|
||||
SDL_DestroyCondition(SDL_Condition *cond)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ SDL_DestroyCondition(SDL_Condition *cond)
|
||||
}
|
||||
}
|
||||
|
||||
/* Restart one of the threads that are waiting on the condition variable */
|
||||
// Restart one of the threads that are waiting on the condition variable
|
||||
extern "C" int
|
||||
SDL_SignalCondition(SDL_Condition *cond)
|
||||
{
|
||||
@@ -73,7 +73,7 @@ SDL_SignalCondition(SDL_Condition *cond)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Restart all threads that are waiting on the condition variable */
|
||||
// Restart all threads that are waiting on the condition variable
|
||||
extern "C" int
|
||||
SDL_BroadcastCondition(SDL_Condition *cond)
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ extern "C" int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
return ((!mutex) || mutex->cpp_mutex.try_lock()) ? 0 : SDL_MUTEX_TIMEDOUT;
|
||||
}
|
||||
|
||||
/* Unlock the mutex */
|
||||
// Unlock the mutex
|
||||
extern "C" void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
|
||||
{
|
||||
if (mutex != NULL) {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* Thread management routines for SDL */
|
||||
// Thread management routines for SDL
|
||||
|
||||
extern "C" {
|
||||
#include "../SDL_thread_c.h"
|
||||
@@ -58,7 +58,7 @@ SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
extern "C" void
|
||||
SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
/* Do nothing. */
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
extern "C" SDL_ThreadID
|
||||
|
||||
@@ -20,5 +20,5 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* For a thread handle, use a void pointer to a std::thread */
|
||||
// For a thread handle, use a void pointer to a std::thread
|
||||
typedef void *SYS_ThreadHandle;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_VITA
|
||||
|
||||
/* Semaphore functions for the VITA. */
|
||||
// Semaphore functions for the VITA.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -36,14 +36,14 @@ struct SDL_Semaphore
|
||||
SceUID semid;
|
||||
};
|
||||
|
||||
/* Create a semaphore */
|
||||
// Create a semaphore
|
||||
SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
SDL_Semaphore *sem;
|
||||
|
||||
sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem));
|
||||
if (sem) {
|
||||
/* TODO: Figure out the limit on the maximum value. */
|
||||
// TODO: Figure out the limit on the maximum value.
|
||||
sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
|
||||
if (sem->semid < 0) {
|
||||
SDL_SetError("Couldn't create semaphore");
|
||||
@@ -55,7 +55,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
return sem;
|
||||
}
|
||||
|
||||
/* Free the semaphore */
|
||||
// Free the semaphore
|
||||
void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem) {
|
||||
@@ -93,7 +93,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
if (timeoutNS < 0) {
|
||||
pTimeout = NULL;
|
||||
} else {
|
||||
timeoutUS = (SceUInt)SDL_NS_TO_US(timeoutNS); /* Convert to microseconds. */
|
||||
timeoutUS = (SceUInt)SDL_NS_TO_US(timeoutNS); // Convert to microseconds.
|
||||
pTimeout = &timeoutUS;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns the current count of the semaphore */
|
||||
// Returns the current count of the semaphore
|
||||
Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
{
|
||||
SceKernelSemaInfo info;
|
||||
@@ -142,4 +142,4 @@ int SDL_SignalSemaphore(SDL_Semaphore *sem)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_VITA */
|
||||
#endif // SDL_THREAD_VITA
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_VITA
|
||||
|
||||
/* VITA thread management routines for SDL */
|
||||
// VITA thread management routines for SDL
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -71,7 +71,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
stack_size = thread->stacksize;
|
||||
}
|
||||
|
||||
/* Create new thread with the same priority as the current thread */
|
||||
// Create new thread with the same priority as the current thread
|
||||
thread->handle = sceKernelCreateThread(
|
||||
thread_name, // name
|
||||
ThreadEntry, // function to run
|
||||
@@ -92,7 +92,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
|
||||
void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
/* Do nothing. */
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
SDL_ThreadID SDL_GetCurrentThreadID(void)
|
||||
@@ -108,7 +108,7 @@ void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
|
||||
void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
/* Do nothing. */
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
@@ -133,4 +133,4 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
return sceKernelChangeThreadPriority(0, value);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_VITA */
|
||||
#endif // SDL_THREAD_VITA
|
||||
|
||||
@@ -38,7 +38,7 @@ typedef struct SDL_cond_impl_t
|
||||
pfnSDL_WaitConditionTimeoutNS WaitTimeoutNS;
|
||||
} SDL_cond_impl_t;
|
||||
|
||||
/* Implementation will be chosen at runtime based on available Kernel features */
|
||||
// Implementation will be chosen at runtime based on available Kernel features
|
||||
static SDL_cond_impl_t SDL_cond_impl_active = { 0 };
|
||||
|
||||
/**
|
||||
@@ -80,13 +80,13 @@ typedef struct SDL_cond_cv
|
||||
|
||||
static SDL_Condition *SDL_CreateCondition_cv(void)
|
||||
{
|
||||
/* Relies on CONDITION_VARIABLE_INIT == 0. */
|
||||
// Relies on CONDITION_VARIABLE_INIT == 0.
|
||||
return (SDL_Condition *)SDL_calloc(1, sizeof(SDL_cond_cv));
|
||||
}
|
||||
|
||||
static void SDL_DestroyCondition_cv(SDL_Condition *cond)
|
||||
{
|
||||
/* There are no kernel allocated resources */
|
||||
// There are no kernel allocated resources
|
||||
SDL_free(cond);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ static int SDL_WaitConditionTimeoutNS_cv(SDL_Condition *_cond, SDL_Mutex *_mutex
|
||||
return SDL_SetError("Passed mutex is not locked or locked recursively");
|
||||
}
|
||||
|
||||
/* The mutex must be updated to the released state */
|
||||
// The mutex must be updated to the released state
|
||||
mutex->count = 0;
|
||||
mutex->owner = 0;
|
||||
|
||||
@@ -154,7 +154,7 @@ static int SDL_WaitConditionTimeoutNS_cv(SDL_Condition *_cond, SDL_Mutex *_mutex
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
/* The mutex is owned by us again, regardless of status of the wait */
|
||||
// The mutex is owned by us again, regardless of status of the wait
|
||||
SDL_assert(mutex->count == 0 && mutex->owner == 0);
|
||||
mutex->count = 1;
|
||||
mutex->owner = GetCurrentThreadId();
|
||||
@@ -187,7 +187,7 @@ static const SDL_cond_impl_t SDL_cond_impl_cv = {
|
||||
|
||||
|
||||
#ifndef SDL_PLATFORM_WINRT
|
||||
/* Generic Condition Variable implementation using SDL_Mutex and SDL_Semaphore */
|
||||
// Generic Condition Variable implementation using SDL_Mutex and SDL_Semaphore
|
||||
static const SDL_cond_impl_t SDL_cond_impl_generic = {
|
||||
&SDL_CreateCondition_generic,
|
||||
&SDL_DestroyCondition_generic,
|
||||
@@ -203,7 +203,7 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
const SDL_cond_impl_t *impl = NULL;
|
||||
|
||||
if (SDL_mutex_impl_active.Type == SDL_MUTEX_INVALID) {
|
||||
/* The mutex implementation isn't decided yet, trigger it */
|
||||
// The mutex implementation isn't decided yet, trigger it
|
||||
SDL_Mutex *mutex = SDL_CreateMutex();
|
||||
if (!mutex) {
|
||||
return NULL;
|
||||
@@ -214,10 +214,10 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
}
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Link statically on this platform */
|
||||
// Link statically on this platform
|
||||
impl = &SDL_cond_impl_cv;
|
||||
#else
|
||||
/* Default to generic implementation, works with all mutex implementations */
|
||||
// Default to generic implementation, works with all mutex implementations
|
||||
impl = &SDL_cond_impl_generic;
|
||||
{
|
||||
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
|
||||
@@ -227,7 +227,7 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
pSleepConditionVariableSRW = (pfnSleepConditionVariableSRW)GetProcAddress(kernel32, "SleepConditionVariableSRW");
|
||||
pSleepConditionVariableCS = (pfnSleepConditionVariableCS)GetProcAddress(kernel32, "SleepConditionVariableCS");
|
||||
if (pWakeConditionVariable && pWakeAllConditionVariable && pSleepConditionVariableSRW && pSleepConditionVariableCS) {
|
||||
/* Use the Windows provided API */
|
||||
// Use the Windows provided API
|
||||
impl = &SDL_cond_impl_cv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
#include "SDL_sysmutex_c.h"
|
||||
|
||||
/* Implementation will be chosen at runtime based on available Kernel features */
|
||||
// Implementation will be chosen at runtime based on available Kernel features
|
||||
SDL_mutex_impl_t SDL_mutex_impl_active = { 0 };
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ SDL_mutex_impl_t SDL_mutex_impl_active = { 0 };
|
||||
*/
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Functions are guaranteed to be available */
|
||||
// Functions are guaranteed to be available
|
||||
#define pInitializeSRWLock InitializeSRWLock
|
||||
#define pReleaseSRWLockExclusive ReleaseSRWLockExclusive
|
||||
#define pAcquireSRWLockExclusive AcquireSRWLockExclusive
|
||||
@@ -67,7 +67,7 @@ static SDL_Mutex *SDL_CreateMutex_srw(void)
|
||||
|
||||
static void SDL_DestroyMutex_srw(SDL_Mutex *mutex)
|
||||
{
|
||||
/* There are no kernel allocated resources */
|
||||
// There are no kernel allocated resources
|
||||
SDL_free(mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ typedef struct SDL_mutex_impl_t
|
||||
pfnSDL_LockMutex Lock;
|
||||
pfnSDL_TryLockMutex TryLock;
|
||||
pfnSDL_UnlockMutex Unlock;
|
||||
/* Needed by SDL_Condition: */
|
||||
// Needed by SDL_Condition:
|
||||
SDL_MutexType Type;
|
||||
} SDL_mutex_impl_t;
|
||||
|
||||
@@ -62,7 +62,7 @@ typedef struct _SRWLOCK
|
||||
typedef struct SDL_mutex_srw
|
||||
{
|
||||
SRWLOCK srw;
|
||||
/* SRW Locks are not recursive, that has to be handled by SDL: */
|
||||
// SRW Locks are not recursive, that has to be handled by SDL:
|
||||
DWORD count;
|
||||
DWORD owner;
|
||||
} SDL_mutex_srw;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Implementation based on Slim Reader/Writer (SRW) Locks for Win 7 and newer.
|
||||
*/
|
||||
|
||||
/* This header makes sure SRWLOCK is actually declared, even on ancient WinSDKs. */
|
||||
// This header makes sure SRWLOCK is actually declared, even on ancient WinSDKs.
|
||||
#include "SDL_sysmutex_c.h"
|
||||
|
||||
typedef VOID(WINAPI *pfnInitializeSRWLock)(PSRWLOCK);
|
||||
@@ -36,7 +36,7 @@ typedef VOID(WINAPI *pfnAcquireSRWLockExclusive)(PSRWLOCK);
|
||||
typedef BOOLEAN(WINAPI *pfnTryAcquireSRWLockExclusive)(PSRWLOCK);
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Functions are guaranteed to be available */
|
||||
// Functions are guaranteed to be available
|
||||
#define pTryAcquireSRWLockExclusive TryAcquireSRWLockExclusive
|
||||
#define pInitializeSRWLock InitializeSRWLock
|
||||
#define pReleaseSRWLockShared ReleaseSRWLockShared
|
||||
@@ -74,10 +74,10 @@ typedef struct SDL_rwlock_impl_t
|
||||
pfnSDL_UnlockRWLock Unlock;
|
||||
} SDL_rwlock_impl_t;
|
||||
|
||||
/* Implementation will be chosen at runtime based on available Kernel features */
|
||||
// Implementation will be chosen at runtime based on available Kernel features
|
||||
static SDL_rwlock_impl_t SDL_rwlock_impl_active = { 0 };
|
||||
|
||||
/* rwlock implementation using Win7+ slim read/write locks (SRWLOCK) */
|
||||
// rwlock implementation using Win7+ slim read/write locks (SRWLOCK)
|
||||
|
||||
typedef struct SDL_rwlock_srw
|
||||
{
|
||||
@@ -98,7 +98,7 @@ static void SDL_DestroyRWLock_srw(SDL_RWLock *_rwlock)
|
||||
{
|
||||
SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock;
|
||||
if (rwlock) {
|
||||
/* There are no kernel allocated resources */
|
||||
// There are no kernel allocated resources
|
||||
SDL_free(rwlock);
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ static const SDL_rwlock_impl_t SDL_rwlock_impl_srw = {
|
||||
|
||||
#include "../generic/SDL_sysrwlock_c.h"
|
||||
|
||||
/* Generic rwlock implementation using SDL_Mutex, SDL_Condition, and SDL_AtomicInt */
|
||||
// Generic rwlock implementation using SDL_Mutex, SDL_Condition, and SDL_AtomicInt
|
||||
static const SDL_rwlock_impl_t SDL_rwlock_impl_generic = {
|
||||
&SDL_CreateRWLock_generic,
|
||||
&SDL_DestroyRWLock_generic,
|
||||
@@ -185,10 +185,10 @@ SDL_RWLock *SDL_CreateRWLock(void)
|
||||
const SDL_rwlock_impl_t *impl;
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Link statically on this platform */
|
||||
// Link statically on this platform
|
||||
impl = &SDL_rwlock_impl_srw;
|
||||
#else
|
||||
/* Default to generic implementation, works with all mutex implementations */
|
||||
// Default to generic implementation, works with all mutex implementations
|
||||
impl = &SDL_rwlock_impl_generic;
|
||||
{
|
||||
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
|
||||
@@ -204,7 +204,7 @@ SDL_RWLock *SDL_CreateRWLock(void)
|
||||
LOOKUP_SRW_SYM(TryAcquireSRWLockExclusive);
|
||||
#undef LOOKUP_SRW_SYM
|
||||
if (okay) {
|
||||
impl = &SDL_rwlock_impl_srw; /* Use the Windows provided API instead of generic fallback */
|
||||
impl = &SDL_rwlock_impl_srw; // Use the Windows provided API instead of generic fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,19 +50,19 @@ typedef struct SDL_semaphore_impl_t
|
||||
pfnSDL_SignalSemaphore Post;
|
||||
} SDL_sem_impl_t;
|
||||
|
||||
/* Implementation will be chosen at runtime based on available Kernel features */
|
||||
// Implementation will be chosen at runtime based on available Kernel features
|
||||
static SDL_sem_impl_t SDL_sem_impl_active = { 0 };
|
||||
|
||||
/**
|
||||
* Atomic + WaitOnAddress implementation
|
||||
*/
|
||||
|
||||
/* APIs not available on WinPhone 8.1 */
|
||||
/* https://www.microsoft.com/en-us/download/details.aspx?id=47328 */
|
||||
// APIs not available on WinPhone 8.1
|
||||
// https://www.microsoft.com/en-us/download/details.aspx?id=47328
|
||||
|
||||
#if !SDL_WINAPI_FAMILY_PHONE
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Functions are guaranteed to be available */
|
||||
// Functions are guaranteed to be available
|
||||
#define pWaitOnAddress WaitOnAddress
|
||||
#define pWakeByAddressSingle WakeByAddressSingle
|
||||
#else
|
||||
@@ -143,7 +143,7 @@ static int SDL_WaitSemaphoreTimeoutNS_atom(SDL_Semaphore *_sem, Sint64 timeoutNS
|
||||
|
||||
for (;;) {
|
||||
count = sem->count;
|
||||
/* If no semaphore is available we need to wait */
|
||||
// If no semaphore is available we need to wait
|
||||
while (count == 0) {
|
||||
now = SDL_GetTicksNS();
|
||||
if (deadline > now) {
|
||||
@@ -160,8 +160,8 @@ static int SDL_WaitSemaphoreTimeoutNS_atom(SDL_Semaphore *_sem, Sint64 timeoutNS
|
||||
count = sem->count;
|
||||
}
|
||||
|
||||
/* Actually the semaphore is only consumed if this succeeds */
|
||||
/* If it doesn't we need to do everything again */
|
||||
// Actually the semaphore is only consumed if this succeeds
|
||||
// If it doesn't we need to do everything again
|
||||
if (InterlockedCompareExchange(&sem->count, count - 1, count) == count) {
|
||||
return 0;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ static const SDL_sem_impl_t SDL_sem_impl_atom = {
|
||||
&SDL_GetSemaphoreValue_atom,
|
||||
&SDL_SignalSemaphore_atom,
|
||||
};
|
||||
#endif /* !SDL_WINAPI_FAMILY_PHONE */
|
||||
#endif // !SDL_WINAPI_FAMILY_PHONE
|
||||
|
||||
/**
|
||||
* Fallback Semaphore implementation using Kernel Semaphores
|
||||
@@ -213,15 +213,15 @@ typedef struct SDL_semaphore_kern
|
||||
LONG count;
|
||||
} SDL_sem_kern;
|
||||
|
||||
/* Create a semaphore */
|
||||
// Create a semaphore
|
||||
static SDL_Semaphore *SDL_CreateSemaphore_kern(Uint32 initial_value)
|
||||
{
|
||||
SDL_sem_kern *sem;
|
||||
|
||||
/* Allocate sem memory */
|
||||
// Allocate sem memory
|
||||
sem = (SDL_sem_kern *)SDL_malloc(sizeof(*sem));
|
||||
if (sem) {
|
||||
/* Create the semaphore, with max value 32K */
|
||||
// Create the semaphore, with max value 32K
|
||||
// !!! FIXME: CreateSemaphoreEx is available in Vista and later, so if XP support is dropped, we can lose this #ifdef.
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS);
|
||||
@@ -238,7 +238,7 @@ static SDL_Semaphore *SDL_CreateSemaphore_kern(Uint32 initial_value)
|
||||
return (SDL_Semaphore *)sem;
|
||||
}
|
||||
|
||||
/* Free the semaphore */
|
||||
// Free the semaphore
|
||||
static void SDL_DestroySemaphore_kern(SDL_Semaphore *_sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
@@ -281,7 +281,7 @@ static int SDL_WaitSemaphoreTimeoutNS_kern(SDL_Semaphore *_sem, Sint64 timeoutNS
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Returns the current count of the semaphore */
|
||||
// Returns the current count of the semaphore
|
||||
static Uint32 SDL_GetSemaphoreValue_kern(SDL_Semaphore *_sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
@@ -305,7 +305,7 @@ static int SDL_SignalSemaphore_kern(SDL_Semaphore *_sem)
|
||||
*/
|
||||
InterlockedIncrement(&sem->count);
|
||||
if (ReleaseSemaphore(sem->id, 1, NULL) == FALSE) {
|
||||
InterlockedDecrement(&sem->count); /* restore */
|
||||
InterlockedDecrement(&sem->count); // restore
|
||||
return SDL_SetError("ReleaseSemaphore() failed");
|
||||
}
|
||||
return 0;
|
||||
@@ -326,13 +326,13 @@ static const SDL_sem_impl_t SDL_sem_impl_kern = {
|
||||
SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
if (!SDL_sem_impl_active.Create) {
|
||||
/* Default to fallback implementation */
|
||||
// Default to fallback implementation
|
||||
const SDL_sem_impl_t *impl = &SDL_sem_impl_kern;
|
||||
|
||||
#if !SDL_WINAPI_FAMILY_PHONE
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_WINDOWS_FORCE_SEMAPHORE_KERNEL, SDL_FALSE)) {
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
/* Link statically on this platform */
|
||||
// Link statically on this platform
|
||||
impl = &SDL_sem_impl_atom;
|
||||
#else
|
||||
/* We already statically link to features from this Api
|
||||
@@ -343,7 +343,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
*/
|
||||
HMODULE synch120 = GetModuleHandle(TEXT("api-ms-win-core-synch-l1-2-0.dll"));
|
||||
if (synch120) {
|
||||
/* Try to load required functions provided by Win 8 or newer */
|
||||
// Try to load required functions provided by Win 8 or newer
|
||||
pWaitOnAddress = (pfnWaitOnAddress)GetProcAddress(synch120, "WaitOnAddress");
|
||||
pWakeByAddressSingle = (pfnWakeByAddressSingle)GetProcAddress(synch120, "WakeByAddressSingle");
|
||||
|
||||
@@ -355,7 +355,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Copy instead of using pointer to save one level of indirection */
|
||||
// Copy instead of using pointer to save one level of indirection
|
||||
SDL_copyp(&SDL_sem_impl_active, impl);
|
||||
}
|
||||
return SDL_sem_impl_active.Create(initial_value);
|
||||
@@ -381,4 +381,4 @@ int SDL_SignalSemaphore(SDL_Semaphore *sem)
|
||||
return SDL_sem_impl_active.Post(sem);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_WINDOWS */
|
||||
#endif // SDL_THREAD_WINDOWS
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#ifdef SDL_THREAD_WINDOWS
|
||||
|
||||
/* Win32 thread management routines for SDL */
|
||||
// Win32 thread management routines for SDL
|
||||
|
||||
#include "../SDL_thread_c.h"
|
||||
#include "../SDL_systhread.h"
|
||||
@@ -66,10 +66,10 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
|
||||
const DWORD flags = thread->stacksize ? STACK_SIZE_PARAM_IS_A_RESERVATION : 0;
|
||||
|
||||
/* Save the function which we will have to call to clear the RTL of calling app! */
|
||||
// Save the function which we will have to call to clear the RTL of calling app!
|
||||
thread->endfunc = vpfnEndThread;
|
||||
|
||||
/* thread->stacksize == 0 means "system default", same as win32 expects */
|
||||
// thread->stacksize == 0 means "system default", same as win32 expects
|
||||
if (pfnBeginThread) {
|
||||
unsigned threadid = 0;
|
||||
thread->handle = (SYS_ThreadHandle)((size_t)pfnBeginThread(NULL, (unsigned int)thread->stacksize,
|
||||
@@ -90,10 +90,10 @@ int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
#pragma pack(push, 8)
|
||||
typedef struct tagTHREADNAME_INFO
|
||||
{
|
||||
DWORD dwType; /* must be 0x1000 */
|
||||
LPCSTR szName; /* pointer to name (in user addr space) */
|
||||
DWORD dwThreadID; /* thread ID (-1=caller thread) */
|
||||
DWORD dwFlags; /* reserved for future use, must be zero */
|
||||
DWORD dwType; // must be 0x1000
|
||||
LPCSTR szName; // pointer to name (in user addr space)
|
||||
DWORD dwThreadID; // thread ID (-1=caller thread)
|
||||
DWORD dwFlags; // reserved for future use, must be zero
|
||||
} THREADNAME_INFO;
|
||||
#pragma pack(pop)
|
||||
|
||||
@@ -109,7 +109,7 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
if (name) {
|
||||
PVOID exceptionHandlerHandle;
|
||||
#ifndef SDL_PLATFORM_WINRT /* !!! FIXME: There's no LoadLibrary() in WinRT; don't know if SetThreadDescription is available there at all at the moment. */
|
||||
#ifndef SDL_PLATFORM_WINRT // !!! FIXME: There's no LoadLibrary() in WinRT; don't know if SetThreadDescription is available there at all at the moment.
|
||||
static pfnSetThreadDescription pSetThreadDescription = NULL;
|
||||
static HMODULE kernel32 = NULL;
|
||||
|
||||
@@ -142,14 +142,14 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
exceptionHandlerHandle = AddVectoredExceptionHandler(1, EmptyVectoredExceptionHandler);
|
||||
if (exceptionHandlerHandle) {
|
||||
THREADNAME_INFO inf;
|
||||
/* This magic tells the debugger to name a thread if it's listening. */
|
||||
// This magic tells the debugger to name a thread if it's listening.
|
||||
SDL_zero(inf);
|
||||
inf.dwType = 0x1000;
|
||||
inf.szName = name;
|
||||
inf.dwThreadID = (DWORD)-1;
|
||||
inf.dwFlags = 0;
|
||||
|
||||
/* The debugger catches this, renames the thread, continues on. */
|
||||
// The debugger catches this, renames the thread, continues on.
|
||||
RaiseException(0x406D1388, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR *)&inf);
|
||||
RemoveVectoredExceptionHandler(exceptionHandlerHandle);
|
||||
}
|
||||
@@ -191,4 +191,4 @@ void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
CloseHandle(thread->handle);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_WINDOWS */
|
||||
#endif // SDL_THREAD_WINDOWS
|
||||
|
||||
@@ -27,4 +27,4 @@
|
||||
|
||||
typedef HANDLE SYS_ThreadHandle;
|
||||
|
||||
#endif /* SDL_systhread_c_h_ */
|
||||
#endif // SDL_systhread_c_h_
|
||||
|
||||
@@ -90,4 +90,4 @@ void SDL_SYS_QuitTLSData(void)
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_WINDOWS */
|
||||
#endif // SDL_THREAD_WINDOWS
|
||||
|
||||
Reference in New Issue
Block a user