nim_duilib/base/thread/thread_local_posix.cpp
jiajia_deng 4933d1f2bc Remove dependency on shared
Signed-off-by: jiajia_deng <2894220@gmail.com>
2019-09-20 16:27:58 +08:00

49 lines
933 B
C++

// Copyright (c) 2011, NetEase Inc. All rights reserved.
//
// Author: wrt(guangguang)
// Date: 2011/6/14
//
// This file implements some useful thread local template data structures for Posix
#include "base/thread/thread_local.h"
#if defined(OS_POSIX)
#include <assert.h>
#include <pthread.h>
namespace nbase {
namespace internal {
// static
void ThreadLocalPlatform::AllocateSlot(SlotType &slot)
{
int error = pthread_key_create(&slot, NULL);
assert(error == 0);
}
// static
void ThreadLocalPlatform::FreeSlot(SlotType &slot)
{
int error = pthread_key_delete(slot);
assert(error == 0);
}
// static
void* ThreadLocalPlatform::GetValueFromSlot(SlotType &slot)
{
return pthread_getspecific(slot);
}
// static
void ThreadLocalPlatform::SetValueInSlot(SlotType &slot, void *value)
{
int error = pthread_setspecific(slot, value);
assert(error == 0);
}
} // namespace internal
} // namespace base
#endif // OS_POSIX