misc/winutils/include/SDL_thread.h
author koda
Tue, 21 Jan 2014 22:43:06 +0100
changeset 10017 de822cd3df3a
parent 7809 7d4fb2f35f4f
permissions -rw-r--r--
fixwhitespace and dos2unix
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
7809
7d4fb2f35f4f update SDL headers for winutils
koda
parents: 6560
diff changeset
     3
    Copyright (C) 1997-2012 Sam Lantinga
6560
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
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7809
diff changeset
    27
 *  Header for the SDL thread management routines
6560
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__
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7809
diff changeset
    69
typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void *arg);
6560
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
#else
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    72
typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7809
diff changeset
    73
        unsigned (__stdcall *func)(void *), void *arg,
6560
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
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    77
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    78
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
    79
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    80
#ifdef __OS2__
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    81
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthread, _endthread)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    82
#elif defined(_WIN32_WCE)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    83
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    84
#else
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    85
#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    86
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    87
#else
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    88
extern DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    89
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    90
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    91
/** Get the 32-bit thread identifier for the current thread */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    92
extern DECLSPEC Uint32 SDLCALL SDL_ThreadID(void);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    93
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    94
/** Get the 32-bit thread identifier for the specified thread,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    95
 *  equivalent to SDL_ThreadID() if the specified thread is NULL.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    96
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    97
extern DECLSPEC Uint32 SDLCALL SDL_GetThreadID(SDL_Thread *thread);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    98
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    99
/** Wait for a thread to finish.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   100
 *  The return code for the thread function is placed in the area
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   101
 *  pointed to by 'status', if 'status' is not NULL.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   102
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   103
extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   104
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   105
/** Forcefully kill a thread without worrying about its state */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   106
extern DECLSPEC void SDLCALL SDL_KillThread(SDL_Thread *thread);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   107
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   108
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   109
/* Ends C function definitions when using C++ */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   110
#ifdef __cplusplus
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   111
}
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   112
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   113
#include "close_code.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   114
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   115
#endif /* _SDL_thread_h */