mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-17 16:58:13 +00:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594
This commit is contained in:
@@ -36,15 +36,14 @@ struct SDL_cond
|
||||
};
|
||||
|
||||
/* Create a condition variable */
|
||||
extern "C"
|
||||
SDL_cond *
|
||||
extern "C" SDL_cond *
|
||||
SDL_CreateCond(void)
|
||||
{
|
||||
/* Allocate and initialize the condition variable */
|
||||
try {
|
||||
SDL_cond * cond = new SDL_cond;
|
||||
SDL_cond *cond = new SDL_cond;
|
||||
return cond;
|
||||
} catch (std::system_error & ex) {
|
||||
} catch (std::system_error &ex) {
|
||||
SDL_SetError("unable to create a C++ condition variable: code=%d; %s", ex.code(), ex.what());
|
||||
return NULL;
|
||||
} catch (std::bad_alloc &) {
|
||||
@@ -54,9 +53,8 @@ SDL_CreateCond(void)
|
||||
}
|
||||
|
||||
/* Destroy a condition variable */
|
||||
extern "C"
|
||||
void
|
||||
SDL_DestroyCond(SDL_cond * cond)
|
||||
extern "C" void
|
||||
SDL_DestroyCond(SDL_cond *cond)
|
||||
{
|
||||
if (cond != NULL) {
|
||||
delete cond;
|
||||
@@ -64,9 +62,8 @@ SDL_DestroyCond(SDL_cond * cond)
|
||||
}
|
||||
|
||||
/* Restart one of the threads that are waiting on the condition variable */
|
||||
extern "C"
|
||||
int
|
||||
SDL_CondSignal(SDL_cond * cond)
|
||||
extern "C" int
|
||||
SDL_CondSignal(SDL_cond *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
@@ -77,9 +74,8 @@ SDL_CondSignal(SDL_cond * cond)
|
||||
}
|
||||
|
||||
/* Restart all threads that are waiting on the condition variable */
|
||||
extern "C"
|
||||
int
|
||||
SDL_CondBroadcast(SDL_cond * cond)
|
||||
extern "C" int
|
||||
SDL_CondBroadcast(SDL_cond *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
@@ -110,9 +106,8 @@ Thread B:
|
||||
SDL_CondSignal(cond);
|
||||
SDL_UnlockMutex(lock);
|
||||
*/
|
||||
extern "C"
|
||||
int
|
||||
SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
|
||||
extern "C" int
|
||||
SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
@@ -126,15 +121,13 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
|
||||
std::unique_lock<std::recursive_mutex> cpp_lock(mutex->cpp_mutex, std::adopt_lock_t());
|
||||
if (ms == SDL_MUTEX_MAXWAIT) {
|
||||
cond->cpp_cond.wait(
|
||||
cpp_lock
|
||||
);
|
||||
cpp_lock);
|
||||
cpp_lock.release();
|
||||
return 0;
|
||||
} else {
|
||||
auto wait_result = cond->cpp_cond.wait_for(
|
||||
cpp_lock,
|
||||
std::chrono::duration<Uint32, std::milli>(ms)
|
||||
);
|
||||
std::chrono::duration<Uint32, std::milli>(ms));
|
||||
cpp_lock.release();
|
||||
if (wait_result == std::cv_status::timeout) {
|
||||
return SDL_MUTEX_TIMEDOUT;
|
||||
@@ -142,15 +135,14 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} catch (std::system_error & ex) {
|
||||
} catch (std::system_error &ex) {
|
||||
return SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait on the condition variable forever */
|
||||
extern "C"
|
||||
int
|
||||
SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
|
||||
extern "C" int
|
||||
SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
|
||||
{
|
||||
return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
|
||||
}
|
||||
|
Reference in New Issue
Block a user