mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-11 06:28:24 +02: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
(cherry picked from commit 5750bcb174)
This commit is contained in:
@@ -21,14 +21,15 @@
|
||||
#define NUM_THREADS 10
|
||||
/* This value should be smaller than the maximum count of the */
|
||||
/* semaphore implementation: */
|
||||
#define NUM_OVERHEAD_OPS 10000
|
||||
#define NUM_OVERHEAD_OPS 10000
|
||||
#define NUM_OVERHEAD_OPS_MULT 10
|
||||
|
||||
static SDL_sem *sem;
|
||||
int alive;
|
||||
|
||||
typedef struct Thread_State {
|
||||
SDL_Thread * thread;
|
||||
typedef struct Thread_State
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
int number;
|
||||
SDL_bool flag;
|
||||
int loop_count;
|
||||
@@ -44,7 +45,7 @@ killed(int sig)
|
||||
static int SDLCALL
|
||||
ThreadFuncRealWorld(void *data)
|
||||
{
|
||||
Thread_State *state = (Thread_State *) data;
|
||||
Thread_State *state = (Thread_State *)data;
|
||||
while (alive) {
|
||||
SDL_SemWait(sem);
|
||||
SDL_Log("Thread number %d has got the semaphore (value = %" SDL_PRIu32 ")!\n",
|
||||
@@ -54,29 +55,30 @@ ThreadFuncRealWorld(void *data)
|
||||
SDL_Log("Thread number %d has released the semaphore (value = %" SDL_PRIu32 ")!\n",
|
||||
state->number, SDL_SemValue(sem));
|
||||
++state->loop_count;
|
||||
SDL_Delay(1); /* For the scheduler */
|
||||
SDL_Delay(1); /* For the scheduler */
|
||||
}
|
||||
SDL_Log("Thread number %d exiting.\n", state->number);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
TestRealWorld(int init_sem) {
|
||||
Thread_State thread_states[NUM_THREADS] = { {0} };
|
||||
TestRealWorld(int init_sem)
|
||||
{
|
||||
Thread_State thread_states[NUM_THREADS] = { { 0 } };
|
||||
int i;
|
||||
int loop_count;
|
||||
|
||||
sem = SDL_CreateSemaphore(init_sem);
|
||||
|
||||
SDL_Log("Running %d threads, semaphore value = %d\n", NUM_THREADS,
|
||||
init_sem);
|
||||
init_sem);
|
||||
alive = 1;
|
||||
/* Create all the threads */
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
|
||||
SDL_snprintf(name, sizeof(name), "Thread%u", (unsigned int)i);
|
||||
thread_states[i].number = i;
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncRealWorld, name, (void *) &thread_states[i]);
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncRealWorld, name, (void *)&thread_states[i]);
|
||||
}
|
||||
|
||||
/* Wait 10 seconds */
|
||||
@@ -155,7 +157,7 @@ TestOverheadUncontended(void)
|
||||
static int SDLCALL
|
||||
ThreadFuncOverheadContended(void *data)
|
||||
{
|
||||
Thread_State *state = (Thread_State *) data;
|
||||
Thread_State *state = (Thread_State *)data;
|
||||
|
||||
if (state->flag) {
|
||||
while (alive) {
|
||||
@@ -182,7 +184,7 @@ TestOverheadContended(SDL_bool try_wait)
|
||||
Uint32 start_ticks;
|
||||
Uint32 end_ticks;
|
||||
Uint32 duration;
|
||||
Thread_State thread_states[NUM_THREADS] = { {0} };
|
||||
Thread_State thread_states[NUM_THREADS] = { { 0 } };
|
||||
char textBuffer[1024];
|
||||
int loop_count;
|
||||
int content_count;
|
||||
@@ -196,9 +198,9 @@ TestOverheadContended(SDL_bool try_wait)
|
||||
/* Create multiple threads to starve the semaphore and cause contention */
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
|
||||
SDL_snprintf(name, sizeof(name), "Thread%u", (unsigned int)i);
|
||||
thread_states[i].flag = try_wait;
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncOverheadContended, name, (void *) &thread_states[i]);
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncOverheadContended, name, (void *)&thread_states[i]);
|
||||
}
|
||||
|
||||
start_ticks = SDL_GetTicks();
|
||||
@@ -207,7 +209,8 @@ TestOverheadContended(SDL_bool try_wait)
|
||||
SDL_SemPost(sem);
|
||||
}
|
||||
/* Make sure threads consumed everything */
|
||||
while (SDL_SemValue(sem)) { }
|
||||
while (SDL_SemValue(sem)) {
|
||||
}
|
||||
}
|
||||
end_ticks = SDL_GetTicks();
|
||||
|
||||
@@ -224,7 +227,7 @@ TestOverheadContended(SDL_bool try_wait)
|
||||
duration = end_ticks - start_ticks;
|
||||
SDL_Log("Took %" SDL_PRIu32 " milliseconds, threads %s %d out of %d times in total (%.2f%%)\n",
|
||||
duration, try_wait ? "where contended" : "timed out", content_count,
|
||||
loop_count, ((float) content_count * 100) / loop_count);
|
||||
loop_count, ((float)content_count * 100) / loop_count);
|
||||
/* Print how many semaphores where consumed per thread */
|
||||
SDL_snprintf(textBuffer, sizeof(textBuffer), "{ ");
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
@@ -242,8 +245,7 @@ TestOverheadContended(SDL_bool try_wait)
|
||||
SDL_DestroySemaphore(sem);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int init_sem;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user