Apart from just really cleaning things up and moving everything into one class regarding thread IDs (ie, is_main_thread(), comparing ID's etc), this also fixes an obscure bug where LL was casting thread ID's to U32 and then compared those to find out if it the same thread. It's theoretically possible that such fails on a 64bit OS. By generalizing the interface, I adopted the use of a thread-local cache for the current thread ID as used by LLMutex et al, so now all code benefits from that. The idea was even extended to now also be used for is_main_thread() tests and even resetting a thread ID to the ID of the current thread.
71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
/**
|
|
* @file aithreadid.cpp
|
|
*
|
|
* Copyright (c) 2012, Aleric Inglewood.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* There are special exceptions to the terms and conditions of the GPL as
|
|
* it is applied to this Source Code. View the full text of the exception
|
|
* in the file doc/FLOSS-exception.txt in this software distribution.
|
|
*
|
|
* CHANGELOG
|
|
* and additional copyright holders.
|
|
*
|
|
* 08/08/2012
|
|
* - Initial version, written by Aleric Inglewood @ SL
|
|
*/
|
|
|
|
#include "sys.h"
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include "aithreadid.h"
|
|
|
|
AIThreadID const AIThreadID::sNone(AIThreadID::none);
|
|
apr_os_thread_t AIThreadID::sMainThreadID;
|
|
#ifndef LL_DARWIN
|
|
apr_os_thread_t ll_thread_local AIThreadID::lCurrentThread = AIThreadID::undefinedID;
|
|
#endif
|
|
|
|
void AIThreadID::set_main_thread_id(void)
|
|
{
|
|
sMainThreadID = apr_os_thread_current();
|
|
}
|
|
|
|
void AIThreadID::set_current_thread_id(void)
|
|
{
|
|
#ifndef LL_DARWIN
|
|
lCurrentThread = apr_os_thread_current();
|
|
#endif
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, AIThreadID const& id)
|
|
{
|
|
return os << id.mID;
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, AIThreadID::dout_print_t)
|
|
{
|
|
if (!AIThreadID::in_main_thread())
|
|
{
|
|
#ifdef LL_DARWIN
|
|
os << std::hex << (size_t)apr_os_thread_current() << std::dec << ' ';
|
|
#else
|
|
os << std::hex << (size_t)AIThreadID::lCurrentThread << std::dec << ' ';
|
|
#endif
|
|
}
|
|
return os;
|
|
}
|
|
|