Skip to content

Commit 0207ed6

Browse files
aldrik-ramaekersSiegeLord
authored andcommitted
fixed formatting, added SDL2 backend
1 parent 5283b9f commit 0207ed6

File tree

4 files changed

+57
-46
lines changed

4 files changed

+57
-46
lines changed

src/sdl/sdl_thread.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ void _al_thread_create(_AL_THREAD *thread, void (*proc)(_AL_THREAD*, void*),
2121
thread->thread = SDL_CreateThread(thread_trampoline, "allegro", thread);
2222
}
2323

24+
void _al_thread_with_stacksize_create(_AL_THREAD *thread, void (*proc)(_AL_THREAD*, void*),
25+
void *arg, size_t stacksize)
26+
{
27+
ASSERT(thread);
28+
ASSERT(proc);
29+
thread->should_stop = false;
30+
thread->proc = proc;
31+
thread->arg = arg;
32+
thread->thread = SDL_CreateThreadWithStackSize(thread_trampoline, "allegro", stacksize, thread);
33+
}
34+
2435
void _al_thread_set_should_stop(_AL_THREAD *thread)
2536
{
2637
ASSERT(thread);

src/threads.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,17 @@ ALLEGRO_THREAD *al_create_thread(
129129
/* Function: al_create_thread_with_stacksize
130130
*/
131131
ALLEGRO_THREAD *al_create_thread_with_stacksize(
132-
void *(*proc)(ALLEGRO_THREAD *thread, void *arg), void *arg, size_t stacksize)
132+
void *(*proc)(ALLEGRO_THREAD *thread, void *arg), void *arg, size_t stacksize)
133133
{
134-
ALLEGRO_THREAD *outer = create_thread();
135-
outer->thread_state = THREAD_STATE_CREATED;
136-
_al_mutex_init(&outer->mutex);
137-
_al_cond_init(&outer->cond);
138-
outer->arg = arg;
139-
outer->proc = proc;
140-
_al_thread_with_stacksize_create(&outer->thread, thread_func_trampoline, outer, stacksize);
141-
/* XXX _al_thread_create should return an error code */
142-
return outer;
134+
ALLEGRO_THREAD *outer = create_thread();
135+
outer->thread_state = THREAD_STATE_CREATED;
136+
_al_mutex_init(&outer->mutex);
137+
_al_cond_init(&outer->cond);
138+
outer->arg = arg;
139+
outer->proc = proc;
140+
_al_thread_with_stacksize_create(&outer->thread, thread_func_trampoline, outer, stacksize);
141+
/* XXX _al_thread_create should return an error code */
142+
return outer;
143143
}
144144

145145
/* Function: al_run_detached_thread

src/unix/uxthread.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,40 +65,40 @@ void _al_thread_create(_AL_THREAD *thread, void (*proc)(_AL_THREAD*, void*), voi
6565
status = pthread_create(&thread->thread, NULL, thread_proc_trampoline, thread);
6666
ASSERT(status == 0);
6767
if (status != 0)
68-
abort();
68+
abort();
6969
}
7070
}
7171

7272

7373
void _al_thread_with_stacksize_create(_AL_THREAD* thread, void (*proc)(_AL_THREAD*, void*), void *arg, size_t stacksize)
7474
{
75-
ASSERT(stacksize >= PTHREAD_STACK_MIN);
76-
ASSERT(thread);
77-
ASSERT(proc);
78-
{
79-
int status;
80-
81-
pthread_mutex_init(&thread->mutex, NULL);
82-
83-
thread->should_stop = false;
84-
thread->proc = proc;
85-
thread->arg = arg;
86-
87-
pthread_attr_t thread_attr;
88-
int result = 0;
89-
result = pthread_attr_init(&thread_attr);
90-
ASSERT(result == 0);
75+
ASSERT(stacksize >= PTHREAD_STACK_MIN);
76+
ASSERT(thread);
77+
ASSERT(proc);
78+
{
79+
int status;
80+
81+
pthread_mutex_init(&thread->mutex, NULL);
82+
83+
thread->should_stop = false;
84+
thread->proc = proc;
85+
thread->arg = arg;
86+
87+
pthread_attr_t thread_attr;
88+
int result = 0;
89+
result = pthread_attr_init(&thread_attr);
90+
ASSERT(result == 0);
9191

92-
// On some systems, pthread_attr_setstacksize() can fail
93-
// if stacksize is not a multiple of the system page size.
94-
result = pthread_attr_setstacksize(&thread_attr, stacksize);
95-
ASSERT(result == 0);
92+
// On some systems, pthread_attr_setstacksize() can fail
93+
// if stacksize is not a multiple of the system page size.
94+
result = pthread_attr_setstacksize(&thread_attr, stacksize);
95+
ASSERT(result == 0);
9696

97-
status = pthread_create(&thread->thread, &thread_attr, thread_proc_trampoline, thread);
98-
ASSERT(status == 0);
99-
if (status != 0)
100-
abort();
101-
}
97+
status = pthread_create(&thread->thread, &thread_attr, thread_proc_trampoline, thread);
98+
ASSERT(status == 0);
99+
if (status != 0)
100+
abort();
101+
}
102102
}
103103

104104

src/win/wxthread.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ void _al_thread_create(_AL_THREAD *thread, void (*proc)(_AL_THREAD*, void*), voi
5959

6060
void _al_thread_with_stacksize_create(_AL_THREAD* thread, void (*proc)(_AL_THREAD*, void*), void *arg, size_t stacksize)
6161
{
62-
ASSERT(thread);
63-
ASSERT(proc);
64-
{
65-
InitializeCriticalSection(&thread->cs);
62+
ASSERT(thread);
63+
ASSERT(proc);
64+
{
65+
InitializeCriticalSection(&thread->cs);
6666

67-
thread->should_stop = false;
68-
thread->proc = proc;
69-
thread->arg = arg;
67+
thread->should_stop = false;
68+
thread->proc = proc;
69+
thread->arg = arg;
7070

71-
thread->thread = (void *)_beginthreadex(NULL, stacksize,
72-
thread_proc_trampoline, thread, 0, NULL);
73-
}
71+
thread->thread = (void *)_beginthreadex(NULL, stacksize,
72+
thread_proc_trampoline, thread, 0, NULL);
73+
}
7474
}
7575

7676

0 commit comments

Comments
 (0)