This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding real std thread implementation and moving pthreads to its own …
…file. pthreads is still used everywhere but WIN32 right now and will need to remain around as iOS doesn't support thread_local. This also picked up an internal change or two that hadn't been mirrored.
- Loading branch information
Ben Vanik
committed
Jun 20, 2016
1 parent
dfda82f
commit e08860e
Showing
10 changed files
with
133 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include <algorithm> | ||
#include <cstdio> | ||
#include <cstring> | ||
#include <iterator> | ||
|
||
namespace wtf { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
bindings/cpp/include/wtf/platform/platform_aux_pthreads_threaded_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef TRACING_FRAMEWORK_BINDINGS_CPP_INCLUDE_WTF_PLATFORM_AUX_PTHREADS_THREADED_IMPL_H_ | ||
#define TRACING_FRAMEWORK_BINDINGS_CPP_INCLUDE_WTF_PLATFORM_AUX_PTHREADS_THREADED_IMPL_H_ | ||
|
||
#include "wtf/buffer.h" | ||
|
||
namespace wtf { | ||
|
||
namespace internal { | ||
pthread_key_t event_buffer_key; | ||
pthread_once_t initialize_threading_once = PTHREAD_ONCE_INIT; | ||
|
||
void EventBufferDtor(void* event_buffer) { | ||
static_cast<EventBuffer*>(event_buffer)->MarkOutOfScope(); | ||
} | ||
|
||
void InitializeThreadingOnce() { | ||
pthread_key_create(&event_buffer_key, EventBufferDtor); | ||
PlatformInitialize(); | ||
} | ||
} // namespace internal | ||
|
||
void PlatformInitializeThreading() { | ||
pthread_once(&internal::initialize_threading_once, | ||
internal::InitializeThreadingOnce); | ||
} | ||
|
||
void PlatformSetThreadLocalEventBuffer(EventBuffer* event_buffer) { | ||
pthread_once(&internal::initialize_threading_once, | ||
internal::InitializeThreadingOnce); | ||
pthread_setspecific(internal::event_buffer_key, event_buffer); | ||
} | ||
|
||
} // namespace wtf | ||
|
||
#endif // TRACING_FRAMEWORK_BINDINGS_CPP_INCLUDE_WTF_PLATFORM_AUX_PTHREADS_THREADED_IMPL_H_ |
51 changes: 51 additions & 0 deletions
51
bindings/cpp/include/wtf/platform/platform_aux_pthreads_threaded_inl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Provides the PlatformGetThreadLocalEventBuffer() function by using | ||
// pthread keys. This should work for all POSIX platforms. | ||
#ifndef TRACING_FRAMEWORK_BINDINGS_CPP_INCLUDE_WTF_PLATFORM_AUX_PTHREADS_THREADED_INL_H_ | ||
#define TRACING_FRAMEWORK_BINDINGS_CPP_INCLUDE_WTF_PLATFORM_AUX_PTHREADS_THREADED_INL_H_ | ||
|
||
#include <pthread.h> | ||
|
||
#include <atomic> | ||
#include <mutex> | ||
|
||
namespace wtf { | ||
|
||
// On this platform, use the standard-library versions of atomics and mutexes. | ||
namespace platform { | ||
using mutex = std::mutex; | ||
|
||
template <typename T> | ||
using lock_guard = std::lock_guard<T>; | ||
|
||
template <typename T> | ||
using atomic = std::atomic<T>; | ||
|
||
// Since memory_order is an old-school enum, it needs to be imported | ||
// individually. | ||
using std::memory_order; | ||
using std::memory_order_relaxed; | ||
using std::memory_order_consume; | ||
using std::memory_order_acquire; | ||
using std::memory_order_release; | ||
using std::memory_order_acq_rel; | ||
using std::memory_order_seq_cst; | ||
} // namespace platform | ||
|
||
namespace internal { | ||
extern pthread_key_t event_buffer_key; | ||
extern pthread_once_t initialize_threading_once; | ||
|
||
void InitializeThreadingOnce(); | ||
|
||
} // namespace internal | ||
|
||
inline EventBuffer* PlatformGetThreadLocalEventBuffer() { | ||
pthread_once(&internal::initialize_threading_once, | ||
internal::InitializeThreadingOnce); | ||
return static_cast<EventBuffer*>( | ||
pthread_getspecific(internal::event_buffer_key)); | ||
} | ||
|
||
} // namespace wtf | ||
|
||
#endif // TRACING_FRAMEWORK_BINDINGS_CPP_INCLUDE_WTF_PLATFORM_AUX_PTHREADS_THREADED_INL_H_ |
33 changes: 18 additions & 15 deletions
33
bindings/cpp/include/wtf/platform/platform_aux_std_threaded_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters