src/thread/stdcpp/SDL_systhread.cpp
author David Ludwig <dludwig@pobox.com>
Tue, 20 Aug 2013 22:16:09 -0400
changeset 8487 3c1f0d357a1a
parent 8486 ba33d06f80cd
child 8544 356878e614e2
permissions -rw-r--r--
WinRT: made a note that WinRT doesn't appear to support modifying a thread's priority
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     1
/*
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     2
  Simple DirectMedia Layer
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     4
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     7
  arising from the use of this software.
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     8
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    12
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    14
     claim that you wrote the original software. If you use this software
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    16
     appreciated but is not required.
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    18
     misrepresented as being the original software.
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    20
*/
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    21
#include "SDL_config.h"
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    22
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    23
/* Thread management routines for SDL */
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    24
8357
8d788bb003f2 WinRT: made the skeleton C++11 thread implementation use .cpp files, not .c
David Ludwig <dludwig@pobox.com>
parents: 8356
diff changeset
    25
extern "C" {
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    26
#include "SDL_thread.h"
8478
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
    27
#include "../SDL_thread_c.h"
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    28
#include "../SDL_systhread.h"
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    29
#include "SDL_log.h"
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    30
}
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    31
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    32
#include <mutex>
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    33
#include <thread>
8484
7258989352eb WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    34
#include <system_error>
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    35
8486
ba33d06f80cd WinRT: made SDL_ThreadID() return the native thread ID, rather than a fake one
David Ludwig <dludwig@pobox.com>
parents: 8484
diff changeset
    36
#ifdef __WINRT__
ba33d06f80cd WinRT: made SDL_ThreadID() return the native thread ID, rather than a fake one
David Ludwig <dludwig@pobox.com>
parents: 8484
diff changeset
    37
#include <Windows.h>
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    38
#endif
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    39
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    40
static void
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    41
RunThread(void *args)
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    42
{
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    43
    SDL_RunThread(args);
8357
8d788bb003f2 WinRT: made the skeleton C++11 thread implementation use .cpp files, not .c
David Ludwig <dludwig@pobox.com>
parents: 8356
diff changeset
    44
}
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    45
8357
8d788bb003f2 WinRT: made the skeleton C++11 thread implementation use .cpp files, not .c
David Ludwig <dludwig@pobox.com>
parents: 8356
diff changeset
    46
extern "C"
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    47
int
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    48
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    49
{
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    50
    try {
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    51
        std::thread cpp_thread(RunThread, args);
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    52
        thread->handle = (void *) new std::thread(std::move(cpp_thread));
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    53
        return 0;
8484
7258989352eb WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    54
    } catch (std::system_error & ex) {
7258989352eb WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    55
        SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what());
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    56
        return -1;
8484
7258989352eb WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    57
    } catch (std::bad_alloc &) {
7258989352eb WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
    58
        SDL_OutOfMemory();
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    59
        return -1;
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    60
    }
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    61
}
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    62
8357
8d788bb003f2 WinRT: made the skeleton C++11 thread implementation use .cpp files, not .c
David Ludwig <dludwig@pobox.com>
parents: 8356
diff changeset
    63
extern "C"
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    64
void
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    65
SDL_SYS_SetupThread(const char *name)
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    66
{
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    67
    // Make sure a thread ID gets assigned ASAP, for debugging purposes:
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    68
    SDL_ThreadID();
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    69
    return;
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    70
}
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    71
8357
8d788bb003f2 WinRT: made the skeleton C++11 thread implementation use .cpp files, not .c
David Ludwig <dludwig@pobox.com>
parents: 8356
diff changeset
    72
extern "C"
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    73
SDL_threadID
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    74
SDL_ThreadID(void)
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    75
{
8486
ba33d06f80cd WinRT: made SDL_ThreadID() return the native thread ID, rather than a fake one
David Ludwig <dludwig@pobox.com>
parents: 8484
diff changeset
    76
#ifdef __WINRT__
ba33d06f80cd WinRT: made SDL_ThreadID() return the native thread ID, rather than a fake one
David Ludwig <dludwig@pobox.com>
parents: 8484
diff changeset
    77
    return GetCurrentThreadId();
ba33d06f80cd WinRT: made SDL_ThreadID() return the native thread ID, rather than a fake one
David Ludwig <dludwig@pobox.com>
parents: 8484
diff changeset
    78
#else
ba33d06f80cd WinRT: made SDL_ThreadID() return the native thread ID, rather than a fake one
David Ludwig <dludwig@pobox.com>
parents: 8484
diff changeset
    79
    // HACK: Mimick a thread ID, if one isn't otherwise available.
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    80
    static thread_local SDL_threadID current_thread_id = 0;
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    81
    static SDL_threadID next_thread_id = 1;
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    82
    static std::mutex next_thread_id_mutex;
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    83
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    84
    if (current_thread_id == 0) {
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    85
        std::lock_guard<std::mutex> lock(next_thread_id_mutex);
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    86
        current_thread_id = next_thread_id;
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    87
        ++next_thread_id;
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    88
    }
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    89
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    90
    return current_thread_id;
8486
ba33d06f80cd WinRT: made SDL_ThreadID() return the native thread ID, rather than a fake one
David Ludwig <dludwig@pobox.com>
parents: 8484
diff changeset
    91
#endif
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    92
}
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    93
8357
8d788bb003f2 WinRT: made the skeleton C++11 thread implementation use .cpp files, not .c
David Ludwig <dludwig@pobox.com>
parents: 8356
diff changeset
    94
extern "C"
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    95
int
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    96
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    97
{
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    98
    // Thread priorities do not look to be settable via C++11's thread
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
    99
    // interface, at least as of this writing (Nov 2012).  std::thread does
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   100
    // provide access to the OS' native handle, however, and some form of
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   101
    // priority-setting could, in theory, be done through this interface.
8487
3c1f0d357a1a WinRT: made a note that WinRT doesn't appear to support modifying a thread's priority
David Ludwig <dludwig@pobox.com>
parents: 8486
diff changeset
   102
    //
3c1f0d357a1a WinRT: made a note that WinRT doesn't appear to support modifying a thread's priority
David Ludwig <dludwig@pobox.com>
parents: 8486
diff changeset
   103
    // WinRT: UPDATE (Aug 20, 2013): thread priorities cannot be changed
3c1f0d357a1a WinRT: made a note that WinRT doesn't appear to support modifying a thread's priority
David Ludwig <dludwig@pobox.com>
parents: 8486
diff changeset
   104
    // on WinRT, at least not for any thread that's already been created.
3c1f0d357a1a WinRT: made a note that WinRT doesn't appear to support modifying a thread's priority
David Ludwig <dludwig@pobox.com>
parents: 8486
diff changeset
   105
    // WinRT threads appear to be based off of the WinRT class,
3c1f0d357a1a WinRT: made a note that WinRT doesn't appear to support modifying a thread's priority
David Ludwig <dludwig@pobox.com>
parents: 8486
diff changeset
   106
    // ThreadPool, more info on which can be found at:
3c1f0d357a1a WinRT: made a note that WinRT doesn't appear to support modifying a thread's priority
David Ludwig <dludwig@pobox.com>
parents: 8486
diff changeset
   107
    // http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool.aspx
3c1f0d357a1a WinRT: made a note that WinRT doesn't appear to support modifying a thread's priority
David Ludwig <dludwig@pobox.com>
parents: 8486
diff changeset
   108
    //
3c1f0d357a1a WinRT: made a note that WinRT doesn't appear to support modifying a thread's priority
David Ludwig <dludwig@pobox.com>
parents: 8486
diff changeset
   109
    // For compatibility sake, 0 will be returned here.
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   110
    return (0);
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   111
}
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   112
8357
8d788bb003f2 WinRT: made the skeleton C++11 thread implementation use .cpp files, not .c
David Ludwig <dludwig@pobox.com>
parents: 8356
diff changeset
   113
extern "C"
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   114
void
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   115
SDL_SYS_WaitThread(SDL_Thread * thread)
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   116
{
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   117
    if ( ! thread) {
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   118
        return;
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   119
    }
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   120
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   121
    try {
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   122
        std::thread * cpp_thread = (std::thread *) thread->handle;
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   123
        if (cpp_thread->joinable()) {
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   124
            cpp_thread->join();
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   125
        }
8484
7258989352eb WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   126
    } catch (std::system_error &) {
7258989352eb WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   127
        // An error occurred when joining the thread.  SDL_WaitThread does not,
7258989352eb WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   128
        // however, seem to provide a means to report errors to its callers
7258989352eb WinRT: made the C++11-based threading backend only try to catch exceptions that it knows it (the threading APIs) might throw, rather than all exceptions
David Ludwig <dludwig@pobox.com>
parents: 8478
diff changeset
   129
        // though!
8360
7f1bc00e59fc WinRT: added a functional threading backend using C++11 apis
David Ludwig <dludwig@pobox.com>
parents: 8357
diff changeset
   130
    }
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   131
}
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   132
8478
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   133
extern "C"
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   134
SDL_TLSData *
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   135
SDL_SYS_GetTLSData()
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   136
{
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   137
    return SDL_Generic_GetTLSData();
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   138
}
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   139
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   140
extern "C"
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   141
int
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   142
SDL_SYS_SetTLSData(SDL_TLSData *data)
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   143
{
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   144
    return SDL_Generic_SetTLSData(data);
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   145
}
337b5dc0797b WinRT: build fixes and additional WinRT-related integrations with SDL 2.0.0
David Ludwig <dludwig@pobox.com>
parents: 8360
diff changeset
   146
8356
4d85eba58f0a WinRT: added a skeleton SDL backend for C++11-based threads
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   147
/* vi: set ts=4 sw=4 expandtab: */