Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move static initialization of InitRunLoopTLSKey as it fails on the stor... #25

Merged
merged 1 commit into from
Oct 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Platform/WinRT/Readium/Readium/ThreadEmulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

namespace ThreadEmulation
{
#ifndef TLS_OUT_OF_INDEXES
# define TLS_OUT_OF_INDEXES ((DWORD)0xffffffff)
#endif

#ifndef CREATE_SUSPENDED
#define CREATE_SUSPENDED 0x00000004
#endif
Expand Down
4 changes: 4 additions & 0 deletions Platform/WinRT/Readium/Readium/WinInitialization.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include "WinInitialization.h"
#include "run_loop.h"

BEGIN_READIUM_API

void Initialization::InitializeSdk()
{
#if EPUB_PLATFORM(WINRT)
ePub3::RunLoop::InitRunLoopTLSKey();
#endif
ePub3::InitializeSdk();
}

Expand Down
10 changes: 2 additions & 8 deletions Platform/WinRT/Readium/Readium/WinInitialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ public ref class Initialization sealed
{

public:

static void InitializeSdk();

static void PopulateFilterManager();

private:
Initialization() {}

void InitializeSdk();
void PopulateFilterManager();
};


Expand Down
3 changes: 2 additions & 1 deletion ePub3/_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ typedef signed long ssize_t;
# endif
#endif

#if !EPUB_PLATFORM(WINRT)
#if EPUB_COMPILER(MSVC)
# pragma section(".CRT$XCU",read)
# define INITIALIZER(f) \
Expand All @@ -163,7 +164,7 @@ typedef signed long ssize_t;
static void f(void) __attribute__((constructor)); \
static void f(void)
#endif

#endif
// MSVC doesn't have this macro
#ifndef __PRETTY_FUNCTION__
# define __PRETTY_FUNCTION__ __FUNCTION__
Expand Down
13 changes: 11 additions & 2 deletions ePub3/utilities/run_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,21 @@ class RunLoop : public PointerType<RunLoop>
EPUB3_EXPORT
void WakeUp();

# if EPUB_OS(WINDOWS) && EPUB_PLATFORM(WINRT)
static void InitRunLoopTLSKey();
static void KillRunLoopTLSKey();
# endif

protected:
///
/// Internal Run function which takes an explicit timeout duration type.
EPUB3_EXPORT
ExitReason RunInternal(bool returnAfterSourceHandled, std::chrono::nanoseconds& timeout);


///
/// Obtains the run loop for the current thread.
EPUB3_EXPORT RunLoop();

private:
///
/// No copy constructor
Expand Down Expand Up @@ -579,6 +583,11 @@ class RunLoop : public PointerType<RunLoop>
std::atomic<bool> _stop;
std::atomic<bool> _resetHandles;
Observer::Activity _observerMask;


# if EPUB_PLATFORM(WINRT)
static DWORD RunLoopTLSKey;
# endif
#else
shared_list<Timer> _timers;
shared_list<Observer> _observers;
Expand Down
13 changes: 9 additions & 4 deletions ePub3/utilities/run_loop_common.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ using namespace ThreadEmulation;
#endif

EPUB3_BEGIN_NAMESPACE

#if EPUB_OS(WINDOWS)
#ifndef TLS_OUT_OF_INDEXES
#if EPUB_OS(WINDOWS)
# if !EPUB_PLATFORM(WINRT)
# ifndef TLS_OUT_OF_INDEXES
# define TLS_OUT_OF_INDEXES ((DWORD)0xffffffff)
#endif
# endif
DWORD RunLoopTLSKey = TLS_OUT_OF_INDEXES;
# endif
#else
static pthread_key_t RunLoopTLSKey;
#endif
Expand All @@ -58,6 +59,8 @@ static void _DestroyTLSRunLoop(void* data)
delete p;
}
#endif

# if !EPUB_PLATFORM(WINRT)
static void KillRunLoopTLSKey()
{
#if EPUB_OS(WINDOWS)
Expand All @@ -67,6 +70,7 @@ static void KillRunLoopTLSKey()
pthread_key_delete(RunLoopTLSKey);
#endif
}

INITIALIZER(InitRunLoopTLSKey)
{
#if EPUB_OS(WINDOWS)
Expand All @@ -81,6 +85,7 @@ INITIALIZER(InitRunLoopTLSKey)
pthread_key_create(&RunLoopTLSKey, _DestroyTLSRunLoop);
#endif
}
#endif

RunLoopPtr RunLoop::CurrentRunLoop()
{
Expand Down
22 changes: 22 additions & 0 deletions ePub3/utilities/run_loop_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,4 +794,26 @@ void RunLoop::Timer::SetNextFireDateDuration(Clock::duration& when)
#endif
}

#if EPUB_PLATFORM(WINRT)

DWORD RunLoop::RunLoopTLSKey = TLS_OUT_OF_INDEXES;

void RunLoop::KillRunLoopTLSKey() {
if (RunLoop::RunLoopTLSKey != TLS_OUT_OF_INDEXES) {
TlsFree(RunLoop::RunLoopTLSKey);
}
}

void RunLoop::InitRunLoopTLSKey() {
RunLoopTLSKey = TlsAlloc();
if (RunLoopTLSKey == TLS_OUT_OF_INDEXES)
{
OutputDebugString(L"No TLS Indexes for RunLoop!\n");
std::terminate();
}
atexit(RunLoop::KillRunLoopTLSKey);
}

#endif

EPUB3_END_NAMESPACE