include/SDL_thread.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 19 Oct 2009 13:31:58 +0000
changeset 3407 d3baf5ac4e37
parent 3269 a67a961e2171
child 3578 0d1b16ee0bca
permissions -rw-r--r--
Partial fix for bug #859

Header file update from Ken for improved doxygen output
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@251
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifndef _SDL_thread_h
slouken@0
    24
#define _SDL_thread_h
slouken@0
    25
slouken@1895
    26
/**
slouken@3407
    27
 *  \file SDL_thread.h
slouken@3407
    28
 *  
slouken@3407
    29
 *  Header for the SDL thread management routines.
slouken@1895
    30
 */
slouken@0
    31
slouken@1356
    32
#include "SDL_stdinc.h"
slouken@1358
    33
#include "SDL_error.h"
slouken@0
    34
slouken@0
    35
/* Thread synchronization primitives */
slouken@0
    36
#include "SDL_mutex.h"
slouken@0
    37
slouken@0
    38
#include "begin_code.h"
slouken@0
    39
/* Set up for C function definitions, even when using C++ */
slouken@0
    40
#ifdef __cplusplus
slouken@1895
    41
/* *INDENT-OFF* */
slouken@0
    42
extern "C" {
slouken@1895
    43
/* *INDENT-ON* */
slouken@0
    44
#endif
slouken@0
    45
slouken@0
    46
/* The SDL thread structure, defined in SDL_thread.c */
slouken@0
    47
struct SDL_Thread;
slouken@0
    48
typedef struct SDL_Thread SDL_Thread;
slouken@0
    49
slouken@3269
    50
#if defined(__WIN32__) && !defined(HAVE_LIBC)
slouken@3407
    51
/**
slouken@3407
    52
 *  \file SDL_thread.h
slouken@3407
    53
 *  
slouken@3407
    54
 *  We compile SDL into a DLL. This means, that it's the DLL which
slouken@3407
    55
 *  creates a new thread for the calling process with the SDL_CreateThread()
slouken@3407
    56
 *  API. There is a problem with this, that only the RTL of the SDL.DLL will
slouken@3407
    57
 *  be initialized for those threads, and not the RTL of the calling 
slouken@3407
    58
 *  application!
slouken@3407
    59
 *  
slouken@3407
    60
 *  To solve this, we make a little hack here.
slouken@3407
    61
 *  
slouken@3407
    62
 *  We'll always use the caller's _beginthread() and _endthread() APIs to
slouken@3407
    63
 *  start a new thread. This way, if it's the SDL.DLL which uses this API,
slouken@3407
    64
 *  then the RTL of SDL.DLL will be used to create the new thread, and if it's
slouken@3407
    65
 *  the application, then the RTL of the application will be used.
slouken@3407
    66
 *  
slouken@3407
    67
 *  So, in short:
slouken@3407
    68
 *  Always use the _beginthread() and _endthread() of the calling runtime 
slouken@3407
    69
 *  library!
slouken@3407
    70
 */
slouken@1471
    71
#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
slouken@1465
    72
#ifndef _WIN32_WCE
slouken@1895
    73
#include <process.h>            /* This has _beginthread() and _endthread() defined! */
icculus@1190
    74
#endif
icculus@1190
    75
slouken@3269
    76
#ifdef __GNUC__
slouken@1895
    77
typedef unsigned long (__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
slouken@1895
    78
                                                             unsigned
slouken@1895
    79
                                                             (__stdcall *
slouken@1895
    80
                                                              func) (void *),
slouken@1895
    81
                                                             void *arg,
slouken@1895
    82
                                                             unsigned,
slouken@1895
    83
                                                             unsigned
slouken@1895
    84
                                                             *threadID);
slouken@1895
    85
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
slouken@1330
    86
#else
slouken@1895
    87
typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
slouken@1895
    88
                                                        unsigned (__stdcall *
slouken@1895
    89
                                                                  func) (void
slouken@1895
    90
                                                                         *),
slouken@1895
    91
                                                        void *arg, unsigned,
slouken@1895
    92
                                                        unsigned *threadID);
slouken@1895
    93
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
slouken@1330
    94
#endif
icculus@1190
    95
slouken@3407
    96
/**
slouken@3407
    97
 *  Create a thread.
slouken@3407
    98
 */
slouken@2060
    99
extern DECLSPEC SDL_Thread *SDLCALL
slouken@2060
   100
SDL_CreateThread(int (SDLCALL * f) (void *), void *data,
slouken@2060
   101
                 pfnSDL_CurrentBeginThread pfnBeginThread,
slouken@2060
   102
                 pfnSDL_CurrentEndThread pfnEndThread);
icculus@1190
   103
slouken@3269
   104
#if defined(_WIN32_WCE)
slouken@3407
   105
slouken@3407
   106
/**
slouken@3407
   107
 *  Create a thread.
slouken@3407
   108
 */
slouken@1330
   109
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL)
slouken@3407
   110
slouken@1330
   111
#else
slouken@3407
   112
slouken@3407
   113
/**
slouken@3407
   114
 *  Create a thread.
slouken@3407
   115
 */
slouken@1330
   116
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
slouken@3407
   117
slouken@1330
   118
#endif
icculus@1190
   119
#else
slouken@3407
   120
slouken@3407
   121
/**
slouken@3407
   122
 *  Create a thread.
slouken@3407
   123
 */
slouken@1895
   124
extern DECLSPEC SDL_Thread *SDLCALL
slouken@1895
   125
SDL_CreateThread(int (SDLCALL * fn) (void *), void *data);
slouken@3407
   126
icculus@1190
   127
#endif
slouken@0
   128
slouken@3407
   129
/**
slouken@3407
   130
 *  Get the 32-bit thread identifier for the current thread.
slouken@3407
   131
 */
slouken@337
   132
extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void);
slouken@0
   133
slouken@3407
   134
/**
slouken@3407
   135
 *  Get the 32-bit thread identifier for the specified thread.
slouken@3407
   136
 *  
slouken@3407
   137
 *  Equivalent to SDL_ThreadID() if the specified thread is NULL.
slouken@0
   138
 */
slouken@1895
   139
extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread * thread);
slouken@0
   140
slouken@3407
   141
/**
slouken@3407
   142
 *  Wait for a thread to finish.
slouken@3407
   143
 *  
slouken@3407
   144
 *  The return code for the thread function is placed in the area
slouken@3407
   145
 *  pointed to by \c status, if \c status is not NULL.
slouken@0
   146
 */
slouken@1895
   147
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
slouken@0
   148
slouken@3407
   149
/**
slouken@3407
   150
 *  \deprecated This function is here for binary compatibility with legacy apps,
slouken@3407
   151
 *              but in SDL 1.3 and later, it's a no-op.
slouken@3407
   152
 *  
slouken@3407
   153
 *  You cannot forcibly kill a thread in a safe manner on many platforms. You 
slouken@3407
   154
 *  should instead find a way to alert your thread that it is time to terminate,
slouken@3407
   155
 *  and then have it gracefully exit on its own. Do not ever call this function!
slouken@2779
   156
 */
slouken@1895
   157
extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread * thread);
slouken@0
   158
slouken@0
   159
slouken@0
   160
/* Ends C function definitions when using C++ */
slouken@0
   161
#ifdef __cplusplus
slouken@1895
   162
/* *INDENT-OFF* */
slouken@0
   163
}
slouken@1895
   164
/* *INDENT-ON* */
slouken@0
   165
#endif
slouken@0
   166
#include "close_code.h"
slouken@0
   167
slouken@0
   168
#endif /* _SDL_thread_h */
slouken@1895
   169
slouken@1895
   170
/* vi: set ts=4 sw=4 expandtab: */