Skip to content

Commit

Permalink
xbox: Add C++11 thread support
Browse files Browse the repository at this point in the history
  • Loading branch information
thrimbor authored and JayFoxRox committed Aug 10, 2020
1 parent 37ed430 commit c594e97
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile.nxdk
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ LIBCXX_SRCS += $(LIBCXX_DIR)/src/valarray.cpp
LIBCXX_SRCS += $(LIBCXX_DIR)/src/variant.cpp
LIBCXX_SRCS += $(LIBCXX_DIR)/src/vector.cpp
LIBCXX_SRCS += $(LIBCXX_DIR)/src/support/win32/support.cpp
LIBCXX_SRCS += $(LIBCXX_DIR)/src/support/win32/thread_win32.cpp
LIBCXX_OBJS = $(addsuffix .obj, $(basename $(LIBCXX_SRCS)))

$(NXDK_DIR)/lib/libc++.lib: $(LIBCXX_OBJS)
Expand Down
1 change: 0 additions & 1 deletion include/__config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define _LIBCPP_NO_AUTO_LINK
#define _LIBCPP_NO_EXCEPTIONS
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
#define _LIBCPP_HAS_NO_THREADS
#define _LIBCPP_BUILDING_LIBRARY
#define _LIBCPP_HAS_NO_STDIN
#define _LIBCPP_HAS_NO_STDOUT
Expand Down
13 changes: 12 additions & 1 deletion include/__threading_support
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ typedef pthread_key_t __libcpp_tls_key;
typedef void* __libcpp_mutex_t;
#define _LIBCPP_MUTEX_INITIALIZER 0

#if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
#if defined(NXDK)
// Size of CRITICAL_SECTION is different in nxdk
typedef void* __libcpp_recursive_mutex_t[7];
#elif defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
typedef void* __libcpp_recursive_mutex_t[6];
#elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__)
typedef void* __libcpp_recursive_mutex_t[5];
Expand All @@ -93,8 +96,16 @@ typedef void* __libcpp_recursive_mutex_t[5];
#endif

// Condition Variable
#if defined(NXDK)
// Size and content of CONDITION_VARIABLE are different in nxdk
static_assert(sizeof(int) == sizeof(void*));
typedef int __libcpp_condvar_t[4];
// Set it to INIT_ONCE_STATIC_INIT, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0 (same as CONDITION_VARIABLE_INIT)
#define _LIBCPP_CONDVAR_INITIALIZER {0, -1, -1, 0}
#else
typedef void* __libcpp_condvar_t;
#define _LIBCPP_CONDVAR_INITIALIZER 0
#endif

// Execute Once
typedef void* __libcpp_exec_once_flag;
Expand Down
6 changes: 6 additions & 0 deletions src/support/win32/thread_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,

int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
{
#if defined(NXDK)
// Condition variables in nxdk use events, so they need to be uninitialized
// to release the event handles.
UninitializeConditionVariable(reinterpret_cast<PCONDITION_VARIABLE>(__cv));
#else
static_cast<void>(__cv);
#endif
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/system_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

#define __STDC_WANT_LIB_EXT1__ 1
#include "__config"

#include "system_error"
Expand Down
2 changes: 2 additions & 0 deletions src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#include "vector"
#include "future"
#include "limits"
#ifndef NXDK
#include <sys/types.h>
#endif

#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
# include <sys/param.h>
Expand Down

0 comments on commit c594e97

Please sign in to comment.