-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NativeThreadInfo and blend in Message #3333
Open
osmeest
wants to merge
2
commits into
pocoproject:main
Choose a base branch
from
osmeest:feature-NativeThreadInfo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// NativeThreadInfo.h | ||
// | ||
// Library: Foundation | ||
// Package: Threading | ||
// Module: NativeThreadInfo | ||
// | ||
// Definition of the NativeThreadInfo class. | ||
// | ||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. | ||
// and Contributors. | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// | ||
|
||
|
||
#ifndef Foundation_NativeThreadInfo_INCLUDED | ||
#define Foundation_NativeThreadInfo_INCLUDED | ||
|
||
#include "Poco/Foundation.h" | ||
|
||
#if defined(POCO_OS_FAMILY_WINDOWS) | ||
#if defined(_WIN32_WCE) | ||
#include "Poco/NativeThreadInfo_WINCE.h" | ||
#else | ||
#include "Poco/NativeThreadInfo_WIN32.h" | ||
#endif | ||
#elif defined(POCO_VXWORKS) | ||
#include "Poco/NativeThreadInfo_VX.h" | ||
#else | ||
#include "Poco/NativeThreadInfo_POSIX.h" | ||
#endif | ||
|
||
namespace Poco { | ||
|
||
class Foundation_API NativeThreadInfo: private NativeThreadInfoImpl | ||
/// This class implements a platform independent API to query information about a native thread. | ||
{ | ||
public: | ||
typedef NativeThreadInfoImpl::ThreadIdImpl ThreadId; | ||
typedef NativeThreadInfoImpl::HandleImpl Handle; | ||
|
||
NativeThreadInfo(); | ||
/// Creates a thread info for the current thread. | ||
|
||
NativeThreadInfo(Handle handle); | ||
/// Creates a thread info for a specific thread id. | ||
|
||
std::string name() const; | ||
/// Returns the name of the thread. | ||
|
||
ThreadId id() const; | ||
}; | ||
|
||
// | ||
// inlines | ||
// | ||
inline std::string NativeThreadInfo::name() const | ||
{ | ||
return nameImpl(); | ||
} | ||
|
||
inline NativeThreadInfo::ThreadId NativeThreadInfo::id() const | ||
{ | ||
return idImpl(); | ||
} | ||
|
||
} // namespace Poco | ||
|
||
#endif // Foundation_NativeThreadInfo_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// NativeThreadInfo_POSIX.h | ||
// | ||
// Library: Foundation | ||
// Package: Threading | ||
// Module: NativeThreadInfo | ||
// | ||
// Definition of the NativeThreadInfoImpl class for POSIX NativeThreadInfos. | ||
// | ||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH. | ||
// and Contributors. | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// | ||
|
||
|
||
#ifndef Foundation_NativeThreadInfo_POSIX_INCLUDED | ||
#define Foundation_NativeThreadInfo_POSIX_INCLUDED | ||
|
||
|
||
#include "Poco/Foundation.h" | ||
#include <string> | ||
#include <pthread.h> | ||
#include <sys/types.h> | ||
|
||
namespace Poco { | ||
|
||
class Foundation_API NativeThreadInfoImpl | ||
{ | ||
public: | ||
#if (POCO_OS == POCO_OS_MAC_OS_X) | ||
typedef uint64_t ThreadIdImpl; | ||
#else | ||
typedef pid_t ThreadIdImpl; | ||
#endif | ||
typedef pthread_t HandleImpl; | ||
|
||
NativeThreadInfoImpl(HandleImpl handle); | ||
|
||
std::string nameImpl() const; | ||
ThreadIdImpl idImpl() const; | ||
|
||
static HandleImpl currentThreadHandleImpl(); | ||
|
||
private: | ||
HandleImpl _thread; | ||
}; | ||
|
||
} // namespace Poco | ||
|
||
#endif // Foundation_NativeThreadInfo_POSIX_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// NativeThreadInfo_VX.h | ||
// | ||
// Library: Foundation | ||
// Package: Threading | ||
// Module: NativeThreadInfo | ||
// | ||
// Definition of the NativeThreadInfoImpl class for VX NativeThreadInfos. | ||
// | ||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH. | ||
// and Contributors. | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// | ||
|
||
|
||
#ifndef Foundation_NativeThreadInfo_VX_INCLUDED | ||
#define Foundation_NativeThreadInfo_VX_INCLUDED | ||
|
||
|
||
#include "Poco/Foundation.h" | ||
#include <string> | ||
#include <taskLib.h> | ||
|
||
namespace Poco { | ||
|
||
class Foundation_API NativeThreadInfoImpl | ||
{ | ||
public: | ||
typedef int ThreadIdImpl; | ||
typedef int HandleImpl; | ||
|
||
NativeThreadInfoImpl(HandleImpl handle); | ||
|
||
std::string nameImpl() const; | ||
ThreadIdImpl idImpl() const; | ||
|
||
static HandleImpl currentThreadHandleImpl(); | ||
|
||
private: | ||
HandleImpl _thread; | ||
}; | ||
|
||
} // namespace Poco | ||
|
||
#endif // Foundation_NativeThreadInfo_VX_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// NativeThreadInfo_WIN32.h | ||
// | ||
// Library: Foundation | ||
// Package: Threading | ||
// Module: NativeThreadInfo | ||
// | ||
// Definition of the NativeThreadInfoImpl class for WIN32 NativeThreadInfos. | ||
// | ||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH. | ||
// and Contributors. | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// | ||
|
||
|
||
#ifndef Foundation_NativeThreadInfo_WIN32_INCLUDED | ||
#define Foundation_NativeThreadInfo_WIN32_INCLUDED | ||
|
||
|
||
#include "Poco/Foundation.h" | ||
#include <string> | ||
#include "Poco/UnWindows.h" | ||
|
||
namespace Poco { | ||
|
||
class Foundation_API NativeThreadInfoImpl | ||
{ | ||
public: | ||
typedef DWORD ThreadIdImpl; | ||
typedef HANDLE HandleImpl; | ||
|
||
NativeThreadInfoImpl(HandleImpl handle); | ||
|
||
std::string nameImpl() const; | ||
ThreadIdImpl idImpl() const; | ||
|
||
static HandleImpl currentThreadHandleImpl(); | ||
|
||
private: | ||
HandleImpl _thread; | ||
}; | ||
|
||
} // namespace Poco | ||
|
||
#endif // Foundation_NativeThreadInfo_WIN32_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// NativeThreadInfo_WINCE.h | ||
// | ||
// Library: Foundation | ||
// Package: Threading | ||
// Module: NativeThreadInfo | ||
// | ||
// Definition of the NativeThreadInfoImpl class for WINCE NativeThreadInfos. | ||
// | ||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH. | ||
// and Contributors. | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// | ||
|
||
|
||
#ifndef Foundation_NativeThreadInfo_WINCE_INCLUDED | ||
#define Foundation_NativeThreadInfo_WINCE_INCLUDED | ||
|
||
|
||
#include "Poco/Foundation.h" | ||
#include <string> | ||
#include "Poco/UnWindows.h" | ||
|
||
namespace Poco { | ||
|
||
class Foundation_API NativeThreadInfoImpl | ||
{ | ||
public: | ||
typedef DWORD ThreadIdImpl; | ||
typedef DWORD HandleImpl; | ||
|
||
NativeThreadInfoImpl(HandleImpl handle); | ||
|
||
std::string nameImpl() const; | ||
ThreadIdImpl idImpl() const; | ||
|
||
static HandleImpl currentThreadHandleImpl(); | ||
|
||
private: | ||
HandleImpl _thread; | ||
}; | ||
|
||
} // namespace Poco | ||
|
||
#endif // Foundation_NativeThreadInfo_WINCE_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// NativeThreadInfo.cpp | ||
// | ||
// Library: Foundation | ||
// Package: Threading | ||
// Module: NativeThreadInfo | ||
// | ||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. | ||
// and Contributors. | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// | ||
|
||
|
||
#include "Poco/NativeThreadInfo.h" | ||
|
||
#if defined(POCO_OS_FAMILY_WINDOWS) | ||
#if defined(_WIN32_WCE) | ||
#include "NativeThreadInfo_WINCE.cpp" | ||
#else | ||
#include "NativeThreadInfo_WIN32.cpp" | ||
#endif | ||
#elif defined(POCO_VXWORKS) | ||
#include "NativeThreadInfo_VX.cpp" | ||
#else | ||
#include "NativeThreadInfo_POSIX.cpp" | ||
|
||
#endif | ||
|
||
|
||
namespace Poco { | ||
|
||
NativeThreadInfo::NativeThreadInfo(Handle handle): | ||
NativeThreadInfoImpl{handle} | ||
{ } | ||
|
||
NativeThreadInfo::NativeThreadInfo(): | ||
NativeThreadInfo{ NativeThreadInfoImpl::currentThreadHandleImpl() } | ||
{ } | ||
|
||
} // namespace Poco |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// NativeThreadInfo_POSIX.cpp | ||
// | ||
// Library: Foundation | ||
// Package: Threading | ||
// Module: NativeThreadInfoImpl | ||
// | ||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH. | ||
// and Contributors. | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// | ||
|
||
|
||
#include "Poco/NativeThreadInfo_POSIX.h" | ||
#include <cstring> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
|
||
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 | ||
#include <sys/syscall.h> | ||
#ifdef SYS_gettid | ||
#define gettid() syscall(SYS_gettid) | ||
#else | ||
#define gettid() (0) | ||
#endif | ||
#endif | ||
|
||
namespace Poco { | ||
|
||
NativeThreadInfoImpl::NativeThreadInfoImpl(NativeThreadInfoImpl::HandleImpl handle): | ||
_thread(handle) | ||
{ | ||
} | ||
|
||
std::string NativeThreadInfoImpl::nameImpl() const | ||
{ | ||
std::string result(128, '\0'); | ||
int rc = pthread_getname_np(_thread, &result[0], result.size()); | ||
if (rc < 0) { | ||
return {}; | ||
} | ||
result.resize(std::strlen(result.data())); | ||
return result; | ||
} | ||
|
||
NativeThreadInfoImpl::ThreadIdImpl NativeThreadInfoImpl::idImpl() const | ||
{ | ||
ThreadIdImpl tid; | ||
#if (POCO_OS == POCO_OS_MAC_OS_X) | ||
pthread_threadid_np(_thread, &tid); | ||
#else | ||
tid = gettid(); | ||
#endif | ||
return tid; | ||
} | ||
|
||
NativeThreadInfoImpl::HandleImpl NativeThreadInfoImpl::currentThreadHandleImpl() | ||
{ | ||
return pthread_self(); | ||
} | ||
|
||
} // namespace Poco |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be formatted as
} else {