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

(cherry picked from commit 5750bcb174)
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
parent 5c4bc807f7
commit b8d85c6939
764 changed files with 50598 additions and 54407 deletions

View File

@@ -37,15 +37,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 &) {
@@ -55,9 +54,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;
@@ -65,9 +63,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");
@@ -78,9 +75,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");
@@ -111,9 +107,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");
@@ -127,15 +122,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;
@@ -143,15 +136,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);
}