Skip to content

Commit

Permalink
Minor style tweaks to tls
Browse files Browse the repository at this point in the history
This is only style changes, no functional change.

BUG=none
TEST=none
R=darin@chromium.org

Review URL: https://codereview.chromium.org/105563002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238854 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sky@chromium.org committed Dec 5, 2013
1 parent fe3a88c commit e0808e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
15 changes: 7 additions & 8 deletions base/threading/thread_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#endif

namespace base {

namespace internal {

// Helper functions that abstract the cross-platform APIs. Do not use directly.
Expand All @@ -67,10 +66,10 @@ struct BASE_EXPORT ThreadLocalPlatform {
typedef pthread_key_t SlotType;
#endif

static void AllocateSlot(SlotType& slot);
static void FreeSlot(SlotType& slot);
static void* GetValueFromSlot(SlotType& slot);
static void SetValueInSlot(SlotType& slot, void* value);
static void AllocateSlot(SlotType* slot);
static void FreeSlot(SlotType slot);
static void* GetValueFromSlot(SlotType slot);
static void SetValueInSlot(SlotType slot, void* value);
};

} // namespace internal
Expand All @@ -79,7 +78,7 @@ template <typename Type>
class ThreadLocalPointer {
public:
ThreadLocalPointer() : slot_() {
internal::ThreadLocalPlatform::AllocateSlot(slot_);
internal::ThreadLocalPlatform::AllocateSlot(&slot_);
}

~ThreadLocalPointer() {
Expand All @@ -106,8 +105,8 @@ class ThreadLocalPointer {

class ThreadLocalBoolean {
public:
ThreadLocalBoolean() { }
~ThreadLocalBoolean() { }
ThreadLocalBoolean() {}
~ThreadLocalBoolean() {}

bool Get() {
return tlp_.Get() != NULL;
Expand Down
12 changes: 5 additions & 7 deletions base/threading/thread_local_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,30 @@
#include "base/logging.h"

namespace base {

namespace internal {

// static
void ThreadLocalPlatform::AllocateSlot(SlotType& slot) {
int error = pthread_key_create(&slot, NULL);
void ThreadLocalPlatform::AllocateSlot(SlotType* slot) {
int error = pthread_key_create(slot, NULL);
CHECK_EQ(error, 0);
}

// static
void ThreadLocalPlatform::FreeSlot(SlotType& slot) {
void ThreadLocalPlatform::FreeSlot(SlotType slot) {
int error = pthread_key_delete(slot);
DCHECK_EQ(0, error);
}

// static
void* ThreadLocalPlatform::GetValueFromSlot(SlotType& slot) {
void* ThreadLocalPlatform::GetValueFromSlot(SlotType slot) {
return pthread_getspecific(slot);
}

// static
void ThreadLocalPlatform::SetValueInSlot(SlotType& slot, void* value) {
void ThreadLocalPlatform::SetValueInSlot(SlotType slot, void* value) {
int error = pthread_setspecific(slot, value);
DCHECK_EQ(error, 0);
}

} // namespace internal

} // namespace base
14 changes: 6 additions & 8 deletions base/threading/thread_local_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,32 @@
#include "base/logging.h"

namespace base {

namespace internal {

// static
void ThreadLocalPlatform::AllocateSlot(SlotType& slot) {
slot = TlsAlloc();
CHECK_NE(slot, TLS_OUT_OF_INDEXES);
void ThreadLocalPlatform::AllocateSlot(SlotType* slot) {
*slot = TlsAlloc();
CHECK_NE(*slot, TLS_OUT_OF_INDEXES);
}

// static
void ThreadLocalPlatform::FreeSlot(SlotType& slot) {
void ThreadLocalPlatform::FreeSlot(SlotType slot) {
if (!TlsFree(slot)) {
NOTREACHED() << "Failed to deallocate tls slot with TlsFree().";
}
}

// static
void* ThreadLocalPlatform::GetValueFromSlot(SlotType& slot) {
void* ThreadLocalPlatform::GetValueFromSlot(SlotType slot) {
return TlsGetValue(slot);
}

// static
void ThreadLocalPlatform::SetValueInSlot(SlotType& slot, void* value) {
void ThreadLocalPlatform::SetValueInSlot(SlotType slot, void* value) {
if (!TlsSetValue(slot, value)) {
LOG(FATAL) << "Failed to TlsSetValue().";
}
}

} // namespace internal

} // namespace base

0 comments on commit e0808e5

Please sign in to comment.