Skip to content

Commit

Permalink
Handle thunder id based on platform type (#1766)
Browse files Browse the repository at this point in the history
* Use JSON::InstanceID, instead Json::ThreadId thread conversion places

* Review comments addressed

---------

Co-authored-by: Pierre Wielders <[email protected]>
  • Loading branch information
HaseenaSainul and pwielders authored Oct 9, 2024
1 parent f6ebe63 commit 61fe958
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 68 deletions.
4 changes: 2 additions & 2 deletions 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 Core::thread_id id, Core::JSON::ArrayType<PluginHost::CallstackData>& response) const {
std::list<Core::callstack_info> stackList;

::DumpCallStack(id, stackList);
Expand Down Expand Up @@ -1256,7 +1256,7 @@ namespace Plugin {

while (it.Next() == true) {
auto const& entry = it.Current();
threads.push_back({ entry.Id.Value(), entry.Job.Value(), entry.Runs.Value() });
threads.push_back({ PluginHost::Metadata::InstanceId(entry.Id.Value()), entry.Job.Value(), entry.Runs.Value() });
}

using Iterator = IMetadata::Data::IThreadsIterator;
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 Core::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
11 changes: 4 additions & 7 deletions Source/Thunder/PluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,8 @@ 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
printf(" Thread%02d|0x%16" PRIu64 ": %10d", (index), static_cast<uint64_t>(Metadata::InstanceId(metaData.Slot[index].WorkerId)), metaData.Slot[index].Runs);

if (metaData.Slot[index].Job.IsSet() == false) {
printf("\n");
}
Expand Down Expand Up @@ -983,10 +980,10 @@ POP_WARNING()
case '7':
case '8':
case '9': {
ThreadId threadId = _dispatcher->WorkerPool().Id(keyPress - '0');
Core::thread_id threadId = _dispatcher->WorkerPool().Id(keyPress - '0');
printf("\nThreadPool thread[%c] callstack:\n", keyPress);
printf("============================================================\n");
if (threadId != (ThreadId)(~0)) {
if (threadId != (Core::thread_id)(~0)) {
uint8_t counter = 0;
std::list<Core::callstack_info> stackList;
::DumpCallStack(threadId, stackList);
Expand Down
7 changes: 1 addition & 6 deletions Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4600,12 +4600,7 @@ namespace PluginHost {
while (index.Next() == true) {

std::list<Core::callstack_info> stackList;

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

PostMortemData::Callstack dump;
dump.Id = index.Current().Id.Value();
Expand Down
12 changes: 6 additions & 6 deletions Source/Thunder/PostMortem.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ namespace PluginHost {
}

public:
Core::JSON::Pointer Address;
Core::JSON::String Function;
Core::JSON::String Module;
Core::JSON::DecUInt32 Line;
Core::JSON::InstanceId Address;
Core::JSON::String Function;
Core::JSON::String Module;
Core::JSON::DecUInt32 Line;
};


Expand All @@ -123,7 +123,7 @@ namespace PluginHost {

Callstack()
: Core::JSON::Container()
, Id(0)
, Id()
, Data() {
Add(_T("id"), &Id);
Add(_T("stack"), &Data);
Expand All @@ -145,7 +145,7 @@ namespace PluginHost {
~Callstack() override = default;

public:
Core::JSON::Pointer Id;
Core::JSON::InstanceId Id;
Core::JSON::ArrayType<CallstackData> Data;
};

Expand Down
1 change: 0 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
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 Thunder::Core::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 != (Thunder::Core::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 Thunder::Core::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
17 changes: 9 additions & 8 deletions Source/core/Portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,6 @@ typedef std::string string;
#define STRLEN(STATIC_TEXT) ((sizeof(STATIC_TEXT) / sizeof(TCHAR)) - 1)
#define EMPTY_STRING _T("")

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

#define QUOTE(str) #str
#define EXPAND_AND_QUOTE(str) QUOTE(str)

Expand Down Expand Up @@ -717,6 +711,12 @@ namespace Core {
#endif
#endif

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

typedef uint32_t hresult;

struct callstack_info {
Expand Down Expand Up @@ -990,8 +990,9 @@ EXTERNAL extern int inet_aton(const char* cp, struct in_addr* inp);
EXTERNAL extern void usleep(const uint32_t value);
#endif

EXTERNAL void DumpCallStack(const ThreadId threadId, std::list<Thunder::Core::callstack_info>& stack);
EXTERNAL uint32_t GetCallStack(const ThreadId threadId, void* addresses[], const uint32_t bufferSize);
void EXTERNAL DumpCallStack(const Thunder::Core::thread_id threadId, std::list<Thunder::Core::callstack_info>& stack);
uint32_t EXTERNAL GetCallStack(const Thunder::Core::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
2 changes: 1 addition & 1 deletion Source/core/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ namespace Core {
return (static_cast<uint32_t>(_pendingQueue.size()));
}

::ThreadId ThreadId() const
thread_id ThreadId() const
{
return (_timerThread.Id());
}
Expand Down
8 changes: 4 additions & 4 deletions Source/core/WorkerPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace Core {
static IWorkerPool& Instance();
static bool IsAvailable();

virtual ::ThreadId Id(const uint8_t index) const = 0;
virtual thread_id Id(const uint8_t index) const = 0;
virtual void Submit(const Core::ProxyType<IDispatch>& job) = 0;
virtual void Schedule(const Core::Time& time, const Core::ProxyType<IDispatch>& job) = 0;
virtual bool Reschedule(const Core::Time& time, const Core::ProxyType<IDispatch>& job) = 0;
Expand Down Expand Up @@ -384,9 +384,9 @@ POP_WARNING()
_external.Process();
_joined = 0;
}
::ThreadId Id(const uint8_t index) const override
thread_id Id(const uint8_t index) const override
{
::ThreadId result = (::ThreadId)(~0);
thread_id result = (thread_id)(~0);

if (index == 0) {
result = _timer.ThreadId();
Expand Down Expand Up @@ -431,7 +431,7 @@ POP_WARNING()
ThreadPool::Minion _external;
Core::TimerType<Timer> _timer;
mutable Metadata _metadata;
::ThreadId _joined;
thread_id _joined;
#ifdef __CORE_WARNING_REPORTING__
DispatchedJobMonitor _dispatchedJobMonitor;
#endif
Expand Down
4 changes: 2 additions & 2 deletions Source/plugins/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ namespace PluginHost

Metadata::Server::Minion::Minion()
: Core::JSON::Container()
, Id(0)
, Id()
, Job()
, Runs(0) {
Add(_T("id"), &Id);
Expand All @@ -241,7 +241,7 @@ namespace PluginHost
Add(_T("runs"), &Runs);
}
Metadata::Server::Minion& Metadata::Server::Minion::operator=(const Core::ThreadPool::Metadata& info) {
Id = (Core::instance_id)info.WorkerId;
Id = Metadata::InstanceId(info.WorkerId);

Runs = info.Runs;
if (info.Job.IsSet() == false) {
Expand Down
30 changes: 28 additions & 2 deletions Source/plugins/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ namespace PluginHost {

public:
Core::JSON::InstanceId Id;
Core::JSON::String Job;
Core::JSON::DecUInt32 Runs;
Core::JSON::String Job;
Core::JSON::DecUInt32 Runs;
};

public:
Expand Down Expand Up @@ -255,6 +255,32 @@ namespace PluginHost {
AppVersion.Clear();
}

template <typename TYPE>
static typename std::enable_if<(std::is_same<TYPE, void*>::value), Core::instance_id>::type
InstanceId(TYPE id)
{
return reinterpret_cast<Core::instance_id>(reinterpret_cast<uintptr_t>(id));
}
template <typename TYPE>
static typename std::enable_if<!(std::is_same<TYPE, void*>::value), Core::instance_id>::type
InstanceId(TYPE id)
{
return static_cast<Core::instance_id>(id);
}

template <typename TYPE = Core::thread_id>
static typename std::enable_if<(std::is_same<TYPE, void*>::value), Core::thread_id>::type
ThreadId(Core::instance_id id)
{
return reinterpret_cast<TYPE>(id);
}
template <typename TYPE = Core::thread_id>
static typename std::enable_if<!(std::is_same<TYPE, void*>::value), Core::thread_id>::type
ThreadId(Core::instance_id id)
{
return static_cast<TYPE>(id);
}

public:
SubSystem SubSystems;
Core::JSON::ArrayType<Service> Plugins;
Expand Down
Loading

0 comments on commit 61fe958

Please sign in to comment.