Skip to content

Commit c594e97

Browse files
thrimborJayFoxRox
authored andcommitted
xbox: Add C++11 thread support
1 parent 37ed430 commit c594e97

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

Makefile.nxdk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ LIBCXX_SRCS += $(LIBCXX_DIR)/src/valarray.cpp
3434
LIBCXX_SRCS += $(LIBCXX_DIR)/src/variant.cpp
3535
LIBCXX_SRCS += $(LIBCXX_DIR)/src/vector.cpp
3636
LIBCXX_SRCS += $(LIBCXX_DIR)/src/support/win32/support.cpp
37+
LIBCXX_SRCS += $(LIBCXX_DIR)/src/support/win32/thread_win32.cpp
3738
LIBCXX_OBJS = $(addsuffix .obj, $(basename $(LIBCXX_SRCS)))
3839

3940
$(NXDK_DIR)/lib/libc++.lib: $(LIBCXX_OBJS)

include/__config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define _LIBCPP_NO_AUTO_LINK
1515
#define _LIBCPP_NO_EXCEPTIONS
1616
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
17-
#define _LIBCPP_HAS_NO_THREADS
1817
#define _LIBCPP_BUILDING_LIBRARY
1918
#define _LIBCPP_HAS_NO_STDIN
2019
#define _LIBCPP_HAS_NO_STDOUT

include/__threading_support

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ typedef pthread_key_t __libcpp_tls_key;
8484
typedef void* __libcpp_mutex_t;
8585
#define _LIBCPP_MUTEX_INITIALIZER 0
8686

87-
#if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
87+
#if defined(NXDK)
88+
// Size of CRITICAL_SECTION is different in nxdk
89+
typedef void* __libcpp_recursive_mutex_t[7];
90+
#elif defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
8891
typedef void* __libcpp_recursive_mutex_t[6];
8992
#elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__)
9093
typedef void* __libcpp_recursive_mutex_t[5];
@@ -93,8 +96,16 @@ typedef void* __libcpp_recursive_mutex_t[5];
9396
#endif
9497

9598
// Condition Variable
99+
#if defined(NXDK)
100+
// Size and content of CONDITION_VARIABLE are different in nxdk
101+
static_assert(sizeof(int) == sizeof(void*));
102+
typedef int __libcpp_condvar_t[4];
103+
// Set it to INIT_ONCE_STATIC_INIT, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0 (same as CONDITION_VARIABLE_INIT)
104+
#define _LIBCPP_CONDVAR_INITIALIZER {0, -1, -1, 0}
105+
#else
96106
typedef void* __libcpp_condvar_t;
97107
#define _LIBCPP_CONDVAR_INITIALIZER 0
108+
#endif
98109

99110
// Execute Once
100111
typedef void* __libcpp_exec_once_flag;

src/support/win32/thread_win32.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
132132

133133
int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
134134
{
135+
#if defined(NXDK)
136+
// Condition variables in nxdk use events, so they need to be uninitialized
137+
// to release the event handles.
138+
UninitializeConditionVariable(reinterpret_cast<PCONDITION_VARIABLE>(__cv));
139+
#else
135140
static_cast<void>(__cv);
141+
#endif
136142
return 0;
137143
}
138144

src/system_error.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#define __STDC_WANT_LIB_EXT1__ 1
910
#include "__config"
1011

1112
#include "system_error"

src/thread.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include "vector"
1515
#include "future"
1616
#include "limits"
17+
#ifndef NXDK
1718
#include <sys/types.h>
19+
#endif
1820

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

0 commit comments

Comments
 (0)