mirror of
https://github.com/netease-im/NIM_Duilib_Framework.git
synced 2026-10-18 22:51:09 +08:00
cf3c9a7bc0
Signed-off-by: Dylan <2894220@gmail.com>
49 lines
930 B
C++
49 lines
930 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
|