1.3 API CHANGE: Add support for naming threads.
--HG-- extra : rebase_source : ae532d4b4d68ef86de0fc2cb6794a622e0841bce
This commit is contained in:
parent
dead491b27
commit
0863dee582
22 changed files with 183 additions and 45 deletions
|
@ -143,7 +143,7 @@ void runAdder(void)
|
|||
SDL_AtomicSet(&threadsRunning, NThreads);
|
||||
|
||||
while (T--)
|
||||
SDL_CreateThread(adder, NULL);
|
||||
SDL_CreateThread(adder, "Adder", NULL);
|
||||
|
||||
while (SDL_AtomicGet(&threadsRunning) > 0)
|
||||
SDL_SemWait(threadDone);
|
||||
|
@ -618,7 +618,7 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
#ifdef TEST_SPINLOCK_FIFO
|
||||
/* Start a monitoring thread */
|
||||
if (lock_free) {
|
||||
SDL_CreateThread(FIFO_Watcher, &queue);
|
||||
SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -627,9 +627,11 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
SDL_zero(readerData);
|
||||
SDL_AtomicSet(&readersRunning, NUM_READERS);
|
||||
for (i = 0; i < NUM_READERS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "FIFOReader%d", i);
|
||||
readerData[i].queue = &queue;
|
||||
readerData[i].lock_free = lock_free;
|
||||
SDL_CreateThread(FIFO_Reader, &readerData[i]);
|
||||
SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
|
||||
}
|
||||
|
||||
/* Start up the writers */
|
||||
|
@ -637,10 +639,12 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
SDL_zero(writerData);
|
||||
SDL_AtomicSet(&writersRunning, NUM_WRITERS);
|
||||
for (i = 0; i < NUM_WRITERS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "FIFOWriter%d", i);
|
||||
writerData[i].queue = &queue;
|
||||
writerData[i].index = i;
|
||||
writerData[i].lock_free = lock_free;
|
||||
SDL_CreateThread(FIFO_Writer, &writerData[i]);
|
||||
SDL_CreateThread(FIFO_Writer, name, &writerData[i]);
|
||||
}
|
||||
|
||||
/* Wait for the writers */
|
||||
|
|
|
@ -58,7 +58,7 @@ main(int argc, char *argv[])
|
|||
SDL_SetError("No worries");
|
||||
|
||||
alive = 1;
|
||||
thread = SDL_CreateThread(ThreadFunc, "#1");
|
||||
thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
|
||||
if (thread == NULL) {
|
||||
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
|
|
|
@ -112,7 +112,9 @@ main(int argc, char *argv[])
|
|||
printf("Main thread: %lu\n", mainthread);
|
||||
atexit(printid);
|
||||
for (i = 0; i < maxproc; ++i) {
|
||||
if ((threads[i] = SDL_CreateThread(Run, NULL)) == NULL)
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Worker%d", i);
|
||||
if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL)
|
||||
fprintf(stderr, "Couldn't create thread!\n");
|
||||
}
|
||||
signal(SIGINT, terminate);
|
||||
|
|
|
@ -100,7 +100,9 @@ main(int argc, char **argv)
|
|||
init_sem);
|
||||
/* Create all the threads */
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
threads[i] = SDL_CreateThread(ThreadFunc, (void *) i);
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
|
||||
threads[i] = SDL_CreateThread(ThreadFunc, name, (void *) i);
|
||||
}
|
||||
|
||||
/* Wait 10 seconds */
|
||||
|
|
|
@ -63,7 +63,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
alive = 1;
|
||||
thread = SDL_CreateThread(ThreadFunc, "#1");
|
||||
thread = SDL_CreateThread(ThreadFunc, "One", "#1");
|
||||
if (thread == NULL) {
|
||||
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
|
@ -75,7 +75,7 @@ main(int argc, char *argv[])
|
|||
|
||||
alive = 1;
|
||||
signal(SIGTERM, killed);
|
||||
thread = SDL_CreateThread(ThreadFunc, "#2");
|
||||
thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
|
||||
if (thread == NULL) {
|
||||
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
|
|
|
@ -296,8 +296,8 @@ main(int argc, char *argv[])
|
|||
SDL_SetEventFilter(FilterEvents, NULL);
|
||||
|
||||
/* Create the event handling threads */
|
||||
mouse_thread = SDL_CreateThread(HandleMouse, NULL);
|
||||
keybd_thread = SDL_CreateThread(HandleKeyboard, NULL);
|
||||
mouse_thread = SDL_CreateThread(HandleMouse, "MouseHandler", NULL);
|
||||
keybd_thread = SDL_CreateThread(HandleKeyboard, "KeyboardHandler", NULL);
|
||||
|
||||
/* Set the surface pixels and refresh! */
|
||||
for (i = 0; i < 256; ++i) {
|
||||
|
|
|
@ -52,8 +52,10 @@ ThreadFunc(void *data)
|
|||
fprintf(stderr, "Creating Thread %d\n", tid);
|
||||
|
||||
for (i = 0; i < NUMTHREADS; i++) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Child%d_%d", tid, i);
|
||||
flags[i] = 0;
|
||||
sub_threads[i] = SDL_CreateThread(SubThreadFunc, &flags[i]);
|
||||
sub_threads[i] = SDL_CreateThread(SubThreadFunc, name, &flags[i]);
|
||||
}
|
||||
|
||||
printf("Thread '%d' waiting for signal\n", tid);
|
||||
|
@ -86,8 +88,10 @@ main(int argc, char *argv[])
|
|||
|
||||
signal(SIGSEGV, SIG_DFL);
|
||||
for (i = 0; i < NUMTHREADS; i++) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Parent%d", i);
|
||||
time_for_threads_to_die[i] = 0;
|
||||
threads[i] = SDL_CreateThread(ThreadFunc, (void *) (uintptr_t) i);
|
||||
threads[i] = SDL_CreateThread(ThreadFunc, name, (void*) (uintptr_t) i);
|
||||
|
||||
if (threads[i] == NULL) {
|
||||
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue