Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
c00ed9da
Commit
c00ed9da
authored
11 years ago
by
ShadowNinja
Browse files
Options
Downloads
Patches
Plain Diff
Add support for threadnames on BSD, Windows (MSVC-only), and OSX
parent
4977b736
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/porting.h
+41
-15
41 additions, 15 deletions
src/porting.h
with
41 additions
and
15 deletions
src/porting.h
+
41
−
15
View file @
c00ed9da
...
...
@@ -271,25 +271,51 @@ inline u32 getTime(TimePrecision prec)
return
0
;
}
#if (defined(linux) || defined(__linux))
#if defined(linux) || defined(__linux)
#include
<sys/prctl.h>
inline
void
setThreadName
(
const
char
*
name
)
{
/* It would be cleaner to do this with pthread_setname_np,
* which was added to glibc in version 2.12, but some major
* distributions are still runing 2.11 and previous versions.
*/
prctl
(
PR_SET_NAME
,
name
);
}
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include
<pthread.h>
#include
<sys/prctl.h>
inline
void
setThreadName
(
const
char
*
name
)
{
pthread_set_name_np
(
pthread_self
(),
name
);
}
#elif defined(_MSC_VER)
typedef
struct
tagTHREADNAME_INFO
{
DWORD
dwType
;
// must be 0x1000
LPCSTR
szName
;
// pointer to name (in user addr space)
DWORD
dwThreadID
;
// thread ID (-1=caller thread)
DWORD
dwFlags
;
// reserved for future use, must be zero
}
THREADNAME_INFO
;
inline
void
setThreadName
(
const
char
*
name
)
{
THREADNAME_INFO
info
;
info
.
dwType
=
0x1000
;
info
.
szName
=
name
;
info
.
dwThreadID
=
-
1
;
info
.
dwFlags
=
0
;
__try
{
RaiseException
(
0x406D1388
,
0
,
sizeof
(
info
)
/
sizeof
(
DWORD
),
(
DWORD
*
)
&
info
);
}
__except
(
EXCEPTION_CONTINUE_EXECUTION
)
{}
}
#elif defined(__APPLE__)
#include
<pthread.h>
inline
void
setThreadName
(
const
char
*
name
)
{
prctl
(
PR_SET_NAME
,
name
);
}
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
/* BSD doesn't seem to support thread names. If you know about a way
* to add this feature please create a pull request.
* "setproctitle" doesn't work for threadnames.
*/
inline
void
setThreadName
(
const
char
*
name
)
{}
inline
void
setThreadName
(
const
char
*
name
)
{
pthread_setname_np
(
name
);
}
#elif defined(_WIN32)
// threadnames are not supported on windows
inline
void
setThreadName
(
const
char
*
name
)
{}
inline
void
setThreadName
(
const
char
*
name
)
{}
#else
#warning "Un
known platform for setT
hread
N
ame
support, you wont have threadname support
."
inline
void
setThreadName
(
const
char
*
name
)
{}
#warning "Un
recognized platform, t
hread
n
ame
s will not be available
."
inline
void
setThreadName
(
const
char
*
name
)
{}
#endif
}
// namespace porting
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment