| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //
- // ThreadLocal.cpp
- //
- // $Id: //poco/1.4/Foundation/src/ThreadLocal.cpp#1 $
- //
- // Library: Foundation
- // Package: Threading
- // Module: Thread
- //
- // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
- // and Contributors.
- //
- // SPDX-License-Identifier: BSL-1.0
- //
- #include "Poco/ThreadLocal.h"
- #include "Poco/SingletonHolder.h"
- #include "Poco/Thread.h"
- namespace Poco {
- TLSAbstractSlot::TLSAbstractSlot()
- {
- }
- TLSAbstractSlot::~TLSAbstractSlot()
- {
- }
- ThreadLocalStorage::ThreadLocalStorage()
- {
- }
- ThreadLocalStorage::~ThreadLocalStorage()
- {
- for (TLSMap::iterator it = _map.begin(); it != _map.end(); ++it)
- {
- delete it->second;
- }
- }
- TLSAbstractSlot*& ThreadLocalStorage::get(const void* key)
- {
- TLSMap::iterator it = _map.find(key);
- if (it == _map.end())
- return _map.insert(TLSMap::value_type(key, reinterpret_cast<Poco::TLSAbstractSlot*>(0))).first->second;
- else
- return it->second;
- }
- namespace
- {
- static SingletonHolder<ThreadLocalStorage> sh;
- }
- ThreadLocalStorage& ThreadLocalStorage::current()
- {
- Thread* pThread = Thread::current();
- if (pThread)
- {
- return pThread->tls();
- }
- else
- {
- return *sh.get();
- }
- }
- void ThreadLocalStorage::clear()
- {
- Thread* pThread = Thread::current();
- if (pThread)
- pThread->clearTLS();
- }
- } // namespace Poco
|