src/thread/SDL_thread_c.h
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Fri, 24 Jun 2016 19:06:06 +0200
changeset 10182 4980c48b8dbe
parent 10146 471eb08040ce
permissions -rw-r--r--
Mac: Updated availability macro in build script.
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: 5262
diff changeset
     2
  Simple DirectMedia Layer
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
     3
  Copyright (C) 1997-2016 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: 5262
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: 5262
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: 5262
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: 5262
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: 5262
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: 5262
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: 5262
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: 5262
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: 5262
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: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
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: 5262
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: 5262
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
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7978
diff changeset
    21
#include "../SDL_internal.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
#ifndef _SDL_thread_c_h
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
#define _SDL_thread_c_h
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
7730
e928464b98ec Fixed bug 2076 - OpenGL doesn't work with --disable-threads
Sam Lantinga <slouken@libsdl.org>
parents: 7482
diff changeset
    26
#include "SDL_thread.h"
e928464b98ec Fixed bug 2076 - OpenGL doesn't work with --disable-threads
Sam Lantinga <slouken@libsdl.org>
parents: 7482
diff changeset
    27
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    28
/* Need the definitions of SYS_ThreadHandle */
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    29
#if SDL_THREADS_DISABLED
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    30
#include "generic/SDL_systhread_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    31
#elif SDL_THREAD_PTHREAD
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    32
#include "pthread/SDL_systhread_c.h"
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    33
#elif SDL_THREAD_WINDOWS
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    34
#include "windows/SDL_systhread_c.h"
7009
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6885
diff changeset
    35
#elif SDL_THREAD_PSP
161b7b6a5303 Add PSP support
Captain Lex <kimonline@126.com>
parents: 6885
diff changeset
    36
#include "psp/SDL_systhread_c.h"
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents: 6138
diff changeset
    37
#elif SDL_THREAD_STDCPP
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents: 6138
diff changeset
    38
#include "stdcpp/SDL_systhread_c.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    39
#else
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    40
#error Need thread implementation for this platform
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    41
#include "generic/SDL_systhread_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    42
#endif
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    43
#include "../SDL_error_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    44
7978
70ac84e49797 Added SDL_DetachThread() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 7977
diff changeset
    45
typedef enum SDL_ThreadState
70ac84e49797 Added SDL_DetachThread() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 7977
diff changeset
    46
{
70ac84e49797 Added SDL_DetachThread() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 7977
diff changeset
    47
    SDL_THREAD_STATE_ALIVE,
70ac84e49797 Added SDL_DetachThread() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 7977
diff changeset
    48
    SDL_THREAD_STATE_DETACHED,
70ac84e49797 Added SDL_DetachThread() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 7977
diff changeset
    49
    SDL_THREAD_STATE_ZOMBIE,
70ac84e49797 Added SDL_DetachThread() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 7977
diff changeset
    50
    SDL_THREAD_STATE_CLEANED,
70ac84e49797 Added SDL_DetachThread() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 7977
diff changeset
    51
} SDL_ThreadState;
70ac84e49797 Added SDL_DetachThread() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 7977
diff changeset
    52
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    53
/* This is the system-independent thread info structure */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    54
struct SDL_Thread
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    55
{
3578
0d1b16ee0bca Fixed bug #741
Sam Lantinga <slouken@libsdl.org>
parents: 3272
diff changeset
    56
    SDL_threadID threadid;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    57
    SYS_ThreadHandle handle;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    58
    int status;
7978
70ac84e49797 Added SDL_DetachThread() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 7977
diff changeset
    59
    SDL_atomic_t state;  /* SDL_THREAD_STATE_* */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    60
    SDL_error errbuf;
5969
3a041d215edc 1.3 API CHANGE: Add support for naming threads.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
    61
    char *name;
10145
cd87106d1d47 threads: Handle SDL_HINT_THREAD_STACK_SIZE at top level, implement elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    62
    size_t stacksize;  /* 0 for default, >0 for user-specified stack size. */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    63
    void *data;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    64
};
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    65
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    66
/* This is the function called to run a thread */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    67
extern void SDL_RunThread(void *data);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    68
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    69
/* This is the system-independent thread local storage structure */
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    70
typedef struct {
7482
249d8ecbbb7d Fixed some compiler warnings that Visual Studio reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 7393
diff changeset
    71
    unsigned int limit;
7393
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    72
    struct {
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    73
        void *data;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    74
        void (*destructor)(void*);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    75
    } array[1];
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    76
} SDL_TLSData;
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    77
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    78
/* This is how many TLS entries we allocate at once */
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    79
#define TLS_ALLOC_CHUNKSIZE 4
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    80
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    81
/* Get cross-platform, slow, thread local storage for this thread.
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    82
   This is only intended as a fallback if getting real thread-local
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    83
   storage fails or isn't supported on this platform.
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    84
 */
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    85
extern SDL_TLSData *SDL_Generic_GetTLSData();
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    86
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    87
/* Set cross-platform, slow, thread local storage for this thread.
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    88
   This is only intended as a fallback if getting real thread-local
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    89
   storage fails or isn't supported on this platform.
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    90
 */
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    91
extern int SDL_Generic_SetTLSData(SDL_TLSData *data);
358696c354a8 Added release/acquire memory barriers to the atomic API
Sam Lantinga <slouken@libsdl.org>
parents: 7011
diff changeset
    92
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    93
#endif /* _SDL_thread_c_h */
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5969
diff changeset
    94
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    95
/* vi: set ts=4 sw=4 expandtab: */