src/thread/SDL_thread.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 20 Jul 2013 19:59:31 -0400
changeset 7484 c6c4f8719af6
parent 7482 249d8ecbbb7d
child 7606 bb2aa25cca1c
permissions -rw-r--r--
One more compiler warning.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5509
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    21
#include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
/* System independent thread management routines for SDL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
#include "SDL_thread.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
#include "SDL_thread_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
#include "SDL_systhread.h"
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5969
diff changeset
    28
#include "../SDL_error_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    31
SDL_TLSID
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    32
SDL_TLSCreate()
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    33
{
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    34
    static SDL_atomic_t SDL_tls_id;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    35
    return SDL_AtomicIncRef(&SDL_tls_id)+1;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    36
}
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    37
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    38
void *
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    39
SDL_TLSGet(SDL_TLSID id)
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    40
{
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    41
    SDL_TLSData *storage;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    42
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    43
    storage = SDL_SYS_GetTLSData();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    44
    if (!storage || id == 0 || id > storage->limit) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    45
        return NULL;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    46
    }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    47
    return storage->array[id-1].data;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    48
}
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    49
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    50
int
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    51
SDL_TLSSet(SDL_TLSID id, const void *value, void (*destructor)(void *))
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    52
{
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    53
    SDL_TLSData *storage;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    54
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    55
    if (id == 0) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    56
        return SDL_InvalidParamError("id");
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    57
    }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    58
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    59
    storage = SDL_SYS_GetTLSData();
7482
249d8ecbbb7d Fixed some compiler warnings that Visual Studio reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 7393
diff changeset
    60
    if (!storage || (id > storage->limit)) {
249d8ecbbb7d Fixed some compiler warnings that Visual Studio reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 7393
diff changeset
    61
        unsigned int i, oldlimit, newlimit;
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    62
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    63
        oldlimit = storage ? storage->limit : 0;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    64
        newlimit = (id + TLS_ALLOC_CHUNKSIZE);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    65
        storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage)+(newlimit-1)*sizeof(storage->array[0]));
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    66
        if (!storage) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    67
            return SDL_OutOfMemory();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    68
        }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    69
        storage->limit = newlimit;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    70
        for (i = oldlimit; i < newlimit; ++i) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    71
            storage->array[i].data = NULL;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    72
            storage->array[i].destructor = NULL;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    73
        }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    74
        if (SDL_SYS_SetTLSData(storage) != 0) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    75
            return -1;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    76
        }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    77
    }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    78
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    79
    storage->array[id-1].data = SDL_const_cast(void*, value);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    80
    storage->array[id-1].destructor = destructor;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    81
    return 0;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    82
}
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    83
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    84
static void
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    85
SDL_TLSCleanup()
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    86
{
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    87
    SDL_TLSData *storage;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    88
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    89
    storage = SDL_SYS_GetTLSData();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    90
    if (storage) {
7484
c6c4f8719af6 One more compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 7482
diff changeset
    91
        unsigned int i;
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    92
        for (i = 0; i < storage->limit; ++i) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    93
            if (storage->array[i].destructor) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    94
                storage->array[i].destructor(storage->array[i].data);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    95
            }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    96
        }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    97
        SDL_SYS_SetTLSData(NULL);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    98
        SDL_free(storage);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
    99
    }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   100
}
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   101
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   102
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   103
/* This is a generic implementation of thread-local storage which doesn't
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   104
   require additional OS support.
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   105
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   106
   It is not especially efficient and doesn't clean up thread-local storage
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   107
   as threads exit.  If there is a real OS that doesn't support thread-local
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   108
   storage this implementation should be improved to be production quality.
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   109
*/
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   110
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   111
typedef struct SDL_TLSEntry {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   112
    SDL_threadID thread;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   113
    SDL_TLSData *storage;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   114
    struct SDL_TLSEntry *next;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   115
} SDL_TLSEntry;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   116
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   117
static SDL_mutex *SDL_generic_TLS_mutex;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   118
static SDL_TLSEntry *SDL_generic_TLS;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   119
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   120
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   121
SDL_TLSData *
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   122
SDL_Generic_GetTLSData()
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   123
{
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   124
    SDL_threadID thread = SDL_ThreadID();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   125
    SDL_TLSEntry *entry;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   126
    SDL_TLSData *storage = NULL;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   127
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   128
    if (!SDL_generic_TLS_mutex) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   129
        static SDL_SpinLock tls_lock;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   130
        SDL_AtomicLock(&tls_lock);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   131
        if (!SDL_generic_TLS_mutex) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   132
            SDL_mutex *mutex = SDL_CreateMutex();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   133
            SDL_MemoryBarrierRelease();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   134
            SDL_generic_TLS_mutex = mutex;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   135
            if (!SDL_generic_TLS_mutex) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   136
                SDL_AtomicUnlock(&tls_lock);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   137
                return NULL;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   138
            }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   139
        }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   140
        SDL_AtomicUnlock(&tls_lock);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   141
    }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   142
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   143
    SDL_MemoryBarrierAcquire();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   144
    SDL_LockMutex(SDL_generic_TLS_mutex);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   145
    for (entry = SDL_generic_TLS; entry; entry = entry->next) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   146
        if (entry->thread == thread) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   147
            storage = entry->storage;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   148
            break;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   149
        }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   150
    }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   151
    SDL_UnlockMutex(SDL_generic_TLS_mutex);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   152
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   153
    return storage;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   154
}
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   155
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   156
int
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   157
SDL_Generic_SetTLSData(SDL_TLSData *storage)
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   158
{
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   159
    SDL_threadID thread = SDL_ThreadID();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   160
    SDL_TLSEntry *prev, *entry;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   161
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   162
    /* SDL_Generic_GetTLSData() is always called first, so we can assume SDL_generic_TLS_mutex */
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   163
    SDL_LockMutex(SDL_generic_TLS_mutex);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   164
    prev = NULL;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   165
    for (entry = SDL_generic_TLS; entry; entry = entry->next) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   166
        if (entry->thread == thread) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   167
            if (storage) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   168
                entry->storage = storage;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   169
            } else {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   170
                if (prev) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   171
                    prev->next = entry->next;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   172
                } else {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   173
                    SDL_generic_TLS = entry->next;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   174
                }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   175
                SDL_free(entry);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   176
            }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   177
            break;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   178
        }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   179
        prev = entry;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   180
    }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   181
    if (!entry) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   182
        entry = (SDL_TLSEntry *)SDL_malloc(sizeof(*entry));
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   183
        if (entry) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   184
            entry->thread = thread;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   185
            entry->storage = storage;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   186
            entry->next = SDL_generic_TLS;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   187
            SDL_generic_TLS = entry;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   188
        }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   189
    }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   190
    SDL_UnlockMutex(SDL_generic_TLS_mutex);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   191
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   192
    if (!entry) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   193
        return SDL_OutOfMemory();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   194
    }
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   195
    return 0;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   196
}
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   197
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   198
/* Routine to get the thread-specific error variable */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   199
SDL_error *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   200
SDL_GetErrBuf(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   201
{
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   202
    static SDL_SpinLock tls_lock;
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   203
    static SDL_bool tls_being_created;
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   204
    static SDL_TLSID tls_errbuf;
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   205
    static SDL_error SDL_global_errbuf;
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   206
    const SDL_error *ALLOCATION_IN_PROGRESS = (SDL_error *)-1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   207
    SDL_error *errbuf;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   208
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   209
    /* tls_being_created is there simply to prevent recursion if SDL_TLSCreate() fails.
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   210
       It also means it's possible for another thread to also use SDL_global_errbuf,
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   211
       but that's very unlikely and hopefully won't cause issues.
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   212
     */
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   213
    if (!tls_errbuf && !tls_being_created) {
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   214
        SDL_AtomicLock(&tls_lock);
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   215
        if (!tls_errbuf) {
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   216
            SDL_TLSID slot;
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   217
            tls_being_created = SDL_TRUE;
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   218
            slot = SDL_TLSCreate();
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   219
            tls_being_created = SDL_FALSE;
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   220
            SDL_MemoryBarrierRelease();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   221
            tls_errbuf = slot;
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   222
        }
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   223
        SDL_AtomicUnlock(&tls_lock);
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   224
    }
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   225
    if (!tls_errbuf) {
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   226
        return &SDL_global_errbuf;
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   227
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   228
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   229
    SDL_MemoryBarrierAcquire();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   230
    errbuf = (SDL_error *)SDL_TLSGet(tls_errbuf);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   231
    if (errbuf == ALLOCATION_IN_PROGRESS) {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   232
        return &SDL_global_errbuf;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   233
    }
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   234
    if (!errbuf) {
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   235
        /* Mark that we're in the middle of allocating our buffer */
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   236
        SDL_TLSSet(tls_errbuf, ALLOCATION_IN_PROGRESS, NULL);
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   237
        errbuf = (SDL_error *)SDL_malloc(sizeof(*errbuf));
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   238
        if (!errbuf) {
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   239
            SDL_TLSSet(tls_errbuf, NULL, NULL);
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   240
            return &SDL_global_errbuf;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   241
        }
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   242
        SDL_zerop(errbuf);
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   243
        SDL_TLSSet(tls_errbuf, errbuf, SDL_free);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   244
    }
7391
a29895dc5e9a Implemented an API for thread-local storage: SDL_TLSCreate(), SDL_TLSSet(), SDL_TLSGet()
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   245
    return errbuf;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   246
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   247
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   248
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   249
/* Arguments and callback to setup and run the user thread function */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   250
typedef struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   251
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   252
    int (SDLCALL * func) (void *);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   253
    void *data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   254
    SDL_Thread *info;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   255
    SDL_sem *wait;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   256
} thread_args;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   257
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   258
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   259
SDL_RunThread(void *data)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   260
{
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   261
    thread_args *args = (thread_args *) data;
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   262
    int (SDLCALL * userfunc) (void *) = args->func;
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   263
    void *userdata = args->data;
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   264
    int *statusloc = &args->info->status;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   265
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   266
    /* Perform any system-dependent setup - this function may not fail */
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   267
    SDL_SYS_SetupThread(args->info->name);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   268
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   269
    /* Get the thread id */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   270
    args->info->threadid = SDL_ThreadID();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   271
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   272
    /* Wake up the parent thread */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   273
    SDL_SemPost(args->wait);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   274
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   275
    /* Run the function */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   276
    *statusloc = userfunc(userdata);
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   277
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   278
    /* Clean up thread-local storage */
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7391
diff changeset
   279
    SDL_TLSCleanup();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   280
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   281
1471
9fb0eee04dd9 Enabled libc support on Win32, so we don't break binary compatibility in 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   282
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   283
#undef SDL_CreateThread
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   284
DECLSPEC SDL_Thread *SDLCALL
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   285
SDL_CreateThread(int (SDLCALL * fn) (void *),
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   286
                 const char *name, void *data,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   287
                 pfnSDL_CurrentBeginThread pfnBeginThread,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   288
                 pfnSDL_CurrentEndThread pfnEndThread)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   289
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   290
DECLSPEC SDL_Thread *SDLCALL
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   291
SDL_CreateThread(int (SDLCALL * fn) (void *),
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   292
                 const char *name, void *data)
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   293
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   294
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   295
    SDL_Thread *thread;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   296
    thread_args *args;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   297
    int ret;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   298
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   299
    /* Allocate memory for the thread info structure */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   300
    thread = (SDL_Thread *) SDL_malloc(sizeof(*thread));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   301
    if (thread == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   302
        SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   303
        return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   304
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   305
    SDL_memset(thread, 0, (sizeof *thread));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   306
    thread->status = -1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   307
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   308
    /* Set up the arguments for the thread */
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   309
    if (name != NULL) {
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   310
        thread->name = SDL_strdup(name);
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   311
        if (thread->name == NULL) {
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   312
            SDL_OutOfMemory();
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   313
            SDL_free(thread);
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   314
            return (NULL);
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   315
        }
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   316
    }
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   317
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   318
    /* Set up the arguments for the thread */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   319
    args = (thread_args *) SDL_malloc(sizeof(*args));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   320
    if (args == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   321
        SDL_OutOfMemory();
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   322
        SDL_free(thread->name);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   323
        SDL_free(thread);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   324
        return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   325
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   326
    args->func = fn;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   327
    args->data = data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   328
    args->info = thread;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   329
    args->wait = SDL_CreateSemaphore(0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   330
    if (args->wait == NULL) {
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   331
        SDL_free(thread->name);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   332
        SDL_free(thread);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   333
        SDL_free(args);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   334
        return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   335
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   336
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   337
    /* Create the thread and go! */
1471
9fb0eee04dd9 Enabled libc support on Win32, so we don't break binary compatibility in 1.2
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   338
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   339
    ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   340
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   341
    ret = SDL_SYS_CreateThread(thread, args);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   342
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   343
    if (ret >= 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   344
        /* Wait for the thread function to use arguments */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   345
        SDL_SemWait(args->wait);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   346
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   347
        /* Oops, failed.  Gotta free everything */
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   348
        SDL_free(thread->name);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   349
        SDL_free(thread);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   350
        thread = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   351
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   352
    SDL_DestroySemaphore(args->wait);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   353
    SDL_free(args);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   354
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   355
    /* Everything is running now */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   356
    return (thread);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   357
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   358
5506
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   359
SDL_threadID
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   360
SDL_GetThreadID(SDL_Thread * thread)
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   361
{
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   362
    SDL_threadID id;
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   363
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   364
    if (thread) {
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   365
        id = thread->threadid;
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   366
    } else {
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   367
        id = SDL_ThreadID();
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   368
    }
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   369
    return id;
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   370
}
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   371
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   372
const char *
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   373
SDL_GetThreadName(SDL_Thread * thread)
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   374
{
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   375
    return thread->name;
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   376
}
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   377
5506
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   378
int
5509
5b1b4d820d10 The API sets the priority for the current thread, not an arbitrary thread.
Sam Lantinga <slouken@libsdl.org>
parents: 5506
diff changeset
   379
SDL_SetThreadPriority(SDL_ThreadPriority priority)
5506
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   380
{
5509
5b1b4d820d10 The API sets the priority for the current thread, not an arbitrary thread.
Sam Lantinga <slouken@libsdl.org>
parents: 5506
diff changeset
   381
    return SDL_SYS_SetThreadPriority(priority);
5506
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   382
}
82a09d5d0f07 Implemented SDL_SetThreadPriority()
Sam Lantinga <slouken@libsdl.org>
parents: 5425
diff changeset
   383
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   384
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   385
SDL_WaitThread(SDL_Thread * thread, int *status)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   386
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   387
    if (thread) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   388
        SDL_SYS_WaitThread(thread);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   389
        if (status) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   390
            *status = thread->status;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   391
        }
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   392
        SDL_free(thread->name);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   393
        SDL_free(thread);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   394
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   395
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   396
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   397
/* vi: set ts=4 sw=4 expandtab: */