misc/winutils/include/SDL_thread.h
author nemo
Wed, 22 Aug 2012 12:35:46 -0400
changeset 7577 bdbb072b38b9
parent 6560 ca07e6be08d0
child 7809 7d4fb2f35f4f
permissions -rw-r--r--
initModule really not needed for uRandom
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6560
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     1
/*
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     3
    Copyright (C) 1997-2009 Sam Lantinga
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     4
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     9
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    13
    Lesser General Public License for more details.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    14
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    18
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    19
    Sam Lantinga
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    20
    slouken@libsdl.org
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    21
*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    22
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    23
#ifndef _SDL_thread_h
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    24
#define _SDL_thread_h
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    25
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    26
/** @file SDL_thread.h
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    27
 *  Header for the SDL thread management routines 
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    28
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    29
 *  @note These are independent of the other SDL routines.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    30
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    31
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    32
#include "SDL_stdinc.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    33
#include "SDL_error.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    34
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    35
/* Thread synchronization primitives */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    36
#include "SDL_mutex.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    37
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    38
#include "begin_code.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    39
/* Set up for C function definitions, even when using C++ */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    40
#ifdef __cplusplus
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    41
extern "C" {
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    42
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    43
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    44
/** The SDL thread structure, defined in SDL_thread.c */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    45
struct SDL_Thread;
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    46
typedef struct SDL_Thread SDL_Thread;
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    47
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    48
/** Create a thread */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    49
#if ((defined(__WIN32__) && !defined(HAVE_LIBC)) || defined(__OS2__)) &&  !defined(__SYMBIAN32__)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    50
/**
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    51
 *  We compile SDL into a DLL on OS/2. This means, that it's the DLL which
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    52
 *  creates a new thread for the calling process with the SDL_CreateThread()
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    53
 *  API. There is a problem with this, that only the RTL of the SDL.DLL will
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    54
 *  be initialized for those threads, and not the RTL of the calling application!
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    55
 *  To solve this, we make a little hack here.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    56
 *  We'll always use the caller's _beginthread() and _endthread() APIs to
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    57
 *  start a new thread. This way, if it's the SDL.DLL which uses this API,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    58
 *  then the RTL of SDL.DLL will be used to create the new thread, and if it's
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    59
 *  the application, then the RTL of the application will be used.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    60
 *  So, in short:
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    61
 *  Always use the _beginthread() and _endthread() of the calling runtime library!
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    62
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    63
#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    64
#ifndef _WIN32_WCE
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    65
#include <process.h> /* This has _beginthread() and _endthread() defined! */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    66
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    67
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    68
#ifdef __OS2__
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    69
typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg); 
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    70
typedef void (*pfnSDL_CurrentEndThread)(void);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    71
#elif __GNUC__
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    72
typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    73
        unsigned (__stdcall *func)(void *), void *arg, 
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    74
        unsigned, unsigned *threadID);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    75
typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    76
#else
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    77
typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    78
        unsigned (__stdcall *func)(void *), void *arg, 
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    79
        unsigned, unsigned *threadID);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    80
typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    81
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    82
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    83
extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    84
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    85
#ifdef __OS2__
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    86
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthread, _endthread)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    87
#elif defined(_WIN32_WCE)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    88
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    89
#else
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    90
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    91
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    92
#else
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    93
extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    94
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    95
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    96
/** Get the 32-bit thread identifier for the current thread */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    97
extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    98
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    99
/** Get the 32-bit thread identifier for the specified thread,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   100
 *  equivalent to SDL_ThreadID() if the specified thread is NULL.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   101
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   102
extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread *thread);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   103
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   104
/** Wait for a thread to finish.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   105
 *  The return code for the thread function is placed in the area
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   106
 *  pointed to by 'status', if 'status' is not NULL.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   107
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   108
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   109
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   110
/** Forcefully kill a thread without worrying about its state */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   111
extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread *thread);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   112
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   113
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   114
/* Ends C function definitions when using C++ */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   115
#ifdef __cplusplus
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   116
}
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   117
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   118
#include "close_code.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   119
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   120
#endif /* _SDL_thread_h */