Skip to content

Commit

Permalink
JSON type added for ThunderId
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Sep 4, 2024
1 parent b7826cd commit 9a2d314
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Source/Thunder/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace Plugin {

static Core::ProxyPoolType<Web::TextBody> jsonBodyTextFactory(2);

void Controller::Callstack(const ThreadId id, Core::JSON::ArrayType<PluginHost::CallstackData>& response) const {
void Controller::Callstack(const ::thread_id id, Core::JSON::ArrayType<PluginHost::CallstackData>& response) const {
std::list<Core::callstack_info> stackList;

::DumpCallStack(id, stackList);
Expand Down
2 changes: 1 addition & 1 deletion Source/Thunder/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ namespace Plugin {
void WorkerPoolMetadata(PluginHost::Metadata::Server& data) const {
_pluginServer->WorkerPool().Snapshot(data);
}
void Callstack(const ThreadId id, Core::JSON::ArrayType<PluginHost::CallstackData>& response) const;
void Callstack(const ::thread_id id, Core::JSON::ArrayType<PluginHost::CallstackData>& response) const;
void SubSystems();
uint32_t Clone(const string& basecallsign, const string& newcallsign);
void Proxies(Core::JSON::ArrayType<PluginHost::Metadata::COMRPC>& info) const;
Expand Down
25 changes: 18 additions & 7 deletions Source/Thunder/PluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@ POP_WARNING()
return deviceId;
}

template <typename TYPE>
inline typename std::enable_if<(std::is_same<TYPE, void*>::value), void>::type
PrintMetaData(const uint8_t index, const TYPE& workerId, const uint32_t runs)
{
printf(" Thread%02d|0x%16" PRIxPTR ": %10d", (index), reinterpret_cast<uintptr_t>(workerId), runs);
}

template <typename TYPE>
inline typename std::enable_if<(!std::is_same<TYPE, void*>::value), void>::type
PrintMetaData(const uint8_t index, const TYPE workerId, const uint32_t runs)
{
printf(" Thread%02d|0x%16" PRIu64 ": %10d", (index), static_cast<uint64_t>(workerId), runs);
}


extern "C" {

#ifndef __WINDOWS__
Expand Down Expand Up @@ -891,11 +906,7 @@ POP_WARNING()
printf("Pending: %d\n", static_cast<uint32_t>(metaData.Pending.size()));
printf("Poolruns:\n");
for (uint8_t index = 0; index < metaData.Slots; index++) {
#ifdef __APPLE__
printf(" Thread%02d|0x%16" PRIxPTR ": %10d", (index), reinterpret_cast<uintptr_t>(metaData.Slot[index].WorkerId), metaData.Slot[index].Runs);
#else
printf(" Thread%02d|0x%16lX: %10d", (index), metaData.Slot[index].WorkerId, metaData.Slot[index].Runs);
#endif
PrintMetaData(index, metaData.Slot[index].WorkerId, metaData.Slot[index].Runs);
if (metaData.Slot[index].Job.IsSet() == false) {
printf("\n");
}
Expand Down Expand Up @@ -985,10 +996,10 @@ POP_WARNING()
case '7':
case '8':
case '9': {
ThreadId threadId = _dispatcher->WorkerPool().Id(keyPress - '0');
::thread_id threadId = _dispatcher->WorkerPool().Id(keyPress - '0');
printf("\nThreadPool thread[%c] callstack:\n", keyPress);
printf("============================================================\n");
if (threadId != (ThreadId)(~0)) {
if (threadId != (::thread_id)(~0)) {
uint8_t counter = 0;
std::list<Core::callstack_info> stackList;
::DumpCallStack(threadId, stackList);
Expand Down
4 changes: 2 additions & 2 deletions Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4563,9 +4563,9 @@ namespace PluginHost {
std::list<Core::callstack_info> stackList;

#ifdef __APPLE__
::DumpCallStack(reinterpret_cast<ThreadId>(index.Current().Id.Value()), stackList);
::DumpCallStack(reinterpret_cast<::thread_id>(index.Current().Id.Value()), stackList);
#else
::DumpCallStack(static_cast<ThreadId>(index.Current().Id.Value()), stackList);
::DumpCallStack(static_cast<::thread_id>(index.Current().Id.Value()), stackList);
#endif

PostMortemData::Callstack dump;
Expand Down
4 changes: 2 additions & 2 deletions Source/Thunder/PostMortem.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace PluginHost {
Add(_T("module"), &Module);
Add(_T("line"), &Line);

Address = reinterpret_cast<Core::instance_id>(source.address);
Address = reinterpret_cast<::thread_id>(source.address);
Function = source.function;
if (source.module.empty() == false) {
Module = source.module;
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace PluginHost {

Callstack()
: Core::JSON::Container()
, Id(0)
, Id()
, Data() {
Add(_T("id"), &Id);
Add(_T("stack"), &Data);
Expand Down
109 changes: 108 additions & 1 deletion Source/core/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ namespace Core {
typedef NumberType<int64_t, true, BASE_OCTAL> OctSInt64;

typedef NumberType<Core::instance_id, false, BASE_HEXADECIMAL> InstanceId;
typedef InstanceId Pointer;

template <class TYPE>
class FloatType : public IElement, public IMessagePack {
Expand Down Expand Up @@ -4980,6 +4979,114 @@ namespace Core {
char _buffer[SIZE];
};

class EXTERNAL ThreadId : public JSON::String {
public:
ThreadId()
: JSON::String(false)
{
JSON::String::operator=(Core::NumberType<uint8_t, false, NumberBase::BASE_HEXADECIMAL>(0));
}

template <typename TYPE, typename std::enable_if<(std::is_same<TYPE, void*>::value)>::type>
ThreadId(const TYPE& id)
: JSON::String(false)
{
String::operator=(Core::NumberType<uintptr_t, false, NumberBase::BASE_HEXADECIMAL>(reinterpret_cast<uintptr_t>(id)).Text());
}

template <typename TYPE, typename std::enable_if<!(std::is_same<TYPE, void*>::value)>::type>
ThreadId(const TYPE id)
: JSON::String(false)
{
String::operator=(Core::NumberType<TYPE, false, NumberBase::BASE_HEXADECIMAL>(id).Text());
}

ThreadId(const ThreadId&& move)
: String(std::move(move))
{
}

ThreadId(const ThreadId& copy)
: String(copy)
{
}

~ThreadId() override = default;

ThreadId& operator=(const ThreadId&& move)
{
JSON::String::operator=(std::move(move));
return (*this);
}

ThreadId& operator=(const ThreadId& RHS)
{
JSON::String::operator=(RHS);
return (*this);
}

template <typename TYPE>
inline typename std::enable_if<(std::is_same<TYPE, void*>::value), ThreadId&>::type
operator=(const TYPE& RHS)
{
String::operator=(Core::NumberType<uintptr_t, false, NumberBase::BASE_HEXADECIMAL>(reinterpret_cast<uintptr_t>(RHS)).Text());
return (*this);
}

template <typename TYPE>
inline typename std::enable_if<(!std::is_same<TYPE, void*>::value), ThreadId&>::type
operator=(const TYPE RHS)
{
String::operator=(Core::NumberType<TYPE, false, NumberBase::BASE_HEXADECIMAL>(RHS).Text());
return (*this);
}

template <typename TYPE>
inline typename std::enable_if<(std::is_same<TYPE, void*>::value), thread_id>::type
Default() const
{
return reinterpret_cast<thread_id>(Core::NumberType<uintptr_t, false, NumberBase::BASE_HEXADECIMAL>(String::Default().c_str(), static_cast<uint32_t>(String::Default().length())).Value());
}

template <typename TYPE>
inline typename std::enable_if<!(std::is_same<TYPE, void*>::value), thread_id>::type
Default() const
{
return static_cast<thread_id>(Core::NumberType<uint64_t, false, NumberBase::BASE_HEXADECIMAL>(String::Default().c_str(), static_cast<uint32_t>(String::Default().length())).Value());
}

inline thread_id Default() const
{
return Default<thread_id>();
}

template <typename TYPE>
inline typename std::enable_if<(std::is_same<TYPE, void*>::value), thread_id>::type
Value() const
{
return reinterpret_cast<thread_id>(Core::NumberType<uintptr_t, false, NumberBase::BASE_HEXADECIMAL>(String::Value().c_str(), static_cast<uint32_t>(String::Value().length())).Value());
}

template <typename TYPE>
inline typename std::enable_if<!(std::is_same<TYPE, void*>::value), thread_id>::type
Value() const
{
return static_cast<thread_id>(Core::NumberType<uint64_t, false, NumberBase::BASE_HEXADECIMAL>(String::Value().c_str(), static_cast<uint32_t>(String::Value().length())).Value());
}

inline thread_id Value() const
{
return Value<thread_id>();
}

inline operator thread_id() const
{
return Value();
}
};

typedef ThreadId Pointer;

template <typename JSONOBJECT>
class LabelType : public JSONOBJECT {
public:
Expand Down
6 changes: 3 additions & 3 deletions Source/core/Portability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static void CallstackSignalHandler(int signr VARIABLE_IS_NOT_USED, siginfo_t* in
}
}

uint32_t GetCallStack(const ThreadId threadId, void* addresses[], const uint32_t bufferSize)
uint32_t GetCallStack(const ::thread_id threadId, void* addresses[], const uint32_t bufferSize)
{
uint32_t result = 0;

Expand All @@ -159,7 +159,7 @@ uint32_t GetCallStack(const ThreadId threadId, void* addresses[], const uint32_t
}
--result;
}
} else if (threadId != (::ThreadId)(~0)) {
} else if (threadId != (::thread_id)(~0)) {
while (std::atomic_exchange_explicit(&g_lock, true, std::memory_order_acquire))
; // spin until acquired

Expand Down Expand Up @@ -196,7 +196,7 @@ uint32_t GetCallStack(const ThreadId threadId, void* addresses[], const uint32_t

extern "C" {

void DumpCallStack(const ThreadId threadId VARIABLE_IS_NOT_USED, std::list<Thunder::Core::callstack_info>& stackList VARIABLE_IS_NOT_USED)
void DumpCallStack(const ::thread_id threadId VARIABLE_IS_NOT_USED, std::list<Thunder::Core::callstack_info>& stackList VARIABLE_IS_NOT_USED)
{
#if defined(THUNDER_BACKTRACE)
void* callstack[32];
Expand Down
8 changes: 4 additions & 4 deletions Source/core/Portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@ typedef std::string string;
#define EMPTY_STRING _T("")

#ifdef __LINUX__
typedef pthread_t ThreadId;
typedef pthread_t thread_id;
#else
typedef DWORD ThreadId;
typedef DWORD thread_id;
#endif

#define QUOTE(str) #str
Expand Down Expand Up @@ -985,8 +985,8 @@ extern int EXTERNAL inet_aton(const char* cp, struct in_addr* inp);
extern void EXTERNAL usleep(const uint32_t value);
#endif

void EXTERNAL DumpCallStack(const ThreadId threadId, std::list<Thunder::Core::callstack_info>& stack);
uint32_t EXTERNAL GetCallStack(const ThreadId threadId, void* addresses[], const uint32_t bufferSize);
void EXTERNAL DumpCallStack(const ::thread_id threadId, std::list<Thunder::Core::callstack_info>& stack);
uint32_t EXTERNAL GetCallStack(const ::thread_id threadId, void* addresses[], const uint32_t bufferSize);

}

Expand Down
12 changes: 6 additions & 6 deletions Source/core/ProcessInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,30 +686,30 @@ namespace Core {
EnumerateChildProcesses(processInfo, _processes);
}

bool ProcessTree::ContainsProcess(ThreadId pid) const
bool ProcessTree::ContainsProcess(::thread_id pid) const
{
PUSH_WARNING(DISABLE_WARNING_CONVERSION_TO_GREATERSIZE)
auto comparator = [pid](const ProcessInfo& processInfo) { return ((ThreadId)(processInfo.Id()) == pid); };
auto comparator = [pid](const ProcessInfo& processInfo) { return ((::thread_id)(processInfo.Id()) == pid); };
POP_WARNING()
std::list<ProcessInfo>::const_iterator i = std::find_if(_processes.cbegin(), _processes.cend(), comparator);
return (i != _processes.cend());
}

void ProcessTree::GetProcessIds(std::list<ThreadId>& processIds) const
void ProcessTree::GetProcessIds(std::list<::thread_id>& processIds) const
{
processIds.clear();

for (const ProcessInfo& process : _processes) {
PUSH_WARNING(DISABLE_WARNING_CONVERSION_TO_GREATERSIZE)
processIds.push_back((ThreadId)(process.Id()));
processIds.push_back((::thread_id)(process.Id()));
POP_WARNING()
}
}

ThreadId ProcessTree::RootId() const
::thread_id ProcessTree::RootId() const
{
PUSH_WARNING(DISABLE_WARNING_CONVERSION_TO_GREATERSIZE)
return (ThreadId)(_processes.front().Id());
return (::thread_id)(_processes.front().Id());
POP_WARNING()
}

Expand Down
6 changes: 3 additions & 3 deletions Source/core/ProcessInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ namespace Core {
public:
explicit ProcessTree(const ProcessInfo& processInfo);

bool ContainsProcess(ThreadId pid) const;
void GetProcessIds(std::list<ThreadId>& processIds) const;
ThreadId RootId() const;
bool ContainsProcess(::thread_id pid) const;
void GetProcessIds(std::list<::thread_id>& processIds) const;
::thread_id RootId() const;

private:
std::list<ProcessInfo> _processes;
Expand Down
2 changes: 1 addition & 1 deletion Source/core/ResourceMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace Core {
{
return (_monitorRuns);
}
::ThreadId Id() const
::thread_id Id() const
{
return (_monitor != nullptr ? _monitor->Id() : 0);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/core/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ namespace Core {
#endif
}

::ThreadId Thread::ThreadId()
thread_id Thread::ThreadId()
{
#ifdef __WINDOWS__
PUSH_WARNING(DISABLE_WARNING_CONVERSION_TO_GREATERSIZE)
return (::GetCurrentThreadId());
POP_WARNING()
#else
return static_cast<::ThreadId>(pthread_self());
return static_cast<thread_id>(pthread_self());
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions Source/core/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ namespace Core {
int PriorityMin() const;
int PriorityMax() const;
bool Priority(int priority);
inline ::ThreadId Id() const
inline ::thread_id Id() const
{
return (m_ThreadId);
}
static ::ThreadId ThreadId();
static ::thread_id ThreadId();

template <typename STORAGETYPE>
static STORAGETYPE& GetContext()
Expand Down Expand Up @@ -288,7 +288,7 @@ namespace Core {
HANDLE m_hThreadInstance;
#endif

::ThreadId m_ThreadId;
::thread_id m_ThreadId;
static uint32_t _defaultStackSize;
#ifdef __POSIX__
string m_threadName;
Expand Down
6 changes: 3 additions & 3 deletions Source/core/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ namespace Core {
virtual void Dispatch(IDispatch*) = 0;
};
struct EXTERNAL Metadata {
::ThreadId WorkerId;
::thread_id WorkerId;
uint32_t Runs;
Core::OptionalType<string> Job;
};

#ifdef __CORE_WARNING_REPORTING__
struct EXTERNAL DispatchedJobMetaData {
::ThreadId WorkerId;
::thread_id WorkerId;
string CallSign;
uint64_t DispatchedTime;
uint32_t ReportRunCount;
Expand Down Expand Up @@ -597,7 +597,7 @@ POP_WARNING()

_queue.Unlock();
}
::ThreadId Id(const uint8_t index) const
::thread_id Id(const uint8_t index) const
{
uint8_t count = 0;
std::list<Executor>::const_iterator ptr = _units.cbegin();
Expand Down
Loading

0 comments on commit 9a2d314

Please sign in to comment.