本文整理汇总了C++中pthread_set_name_np函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_set_name_np函数的具体用法?C++ pthread_set_name_np怎么用?C++ pthread_set_name_np使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_set_name_np函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Sys_SetThreadName
static int Sys_SetThreadName( pthread_t handle, const char* name )
{
int ret = 0;
#ifdef __linux__
// NOTE: linux only supports threadnames up to 16chars *including* terminating NULL
// http://man7.org/linux/man-pages/man3/pthread_setname_np.3.html
// on my machine a longer name (eg "JobListProcessor_0") caused an ENOENT error (instead of ERANGE)
assert( strlen( name ) < 16 );
ret = pthread_setname_np( handle, name );
if( ret != 0 )
idLib::common->Printf( "Setting threadname \"%s\" failed, reason: %s (%i)\n", name, strerror( errno ), errno );
#elif defined(__FreeBSD__)
// according to http://www.freebsd.org/cgi/man.cgi?query=pthread_set_name_np&sektion=3
// the interface is void pthread_set_name_np(pthread_t tid, const char *name);
pthread_set_name_np( handle, name ); // doesn't return anything
#endif
/* TODO: OSX:
// according to http://stackoverflow.com/a/7989973
// this needs to be called in the thread to be named!
ret = pthread_setname_np(name);
// so we'd have to wrap the xthread_t function in Sys_CreateThread and set the name in the wrapping function...
*/
return ret;
}
示例2: pthread_self
Error ThreadPosix::set_name_func_posix(const String& p_name) {
pthread_t running_thread = pthread_self();
#ifdef PTHREAD_NO_RENAME
return ERR_UNAVAILABLE;
#else
#ifdef PTHREAD_RENAME_SELF
// check if thread is the same as caller
int err = pthread_setname_np(p_name.utf8().get_data());
#else
#ifdef PTHREAD_BSD_SET_NAME
pthread_set_name_np(running_thread, p_name.utf8().get_data());
int err = 0; // Open/FreeBSD ignore errors in this function
#else
int err = pthread_setname_np(running_thread, p_name.utf8().get_data());
#endif // PTHREAD_BSD_SET_NAME
#endif // PTHREAD_RENAME_SELF
return err == 0 ? OK : ERR_INVALID_PARAMETER;
#endif // PTHREAD_NO_RENAME
};
示例3: MOZ_RELEASE_ASSERT
void
js::ThisThread::SetName(const char* name)
{
MOZ_RELEASE_ASSERT(name);
#if (defined(__APPLE__) && defined(__MACH__)) || defined(__linux__)
// On linux and OS X the name may not be longer than 16 bytes, including
// the null terminator. Truncate the name to 15 characters.
char nameBuf[16];
strncpy(nameBuf, name, sizeof nameBuf - 1);
nameBuf[sizeof nameBuf - 1] = '\0';
name = nameBuf;
#endif
int rv;
#ifdef XP_DARWIN
rv = pthread_setname_np(name);
#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
pthread_set_name_np(pthread_self(), name);
rv = 0;
#elif defined(__NetBSD__)
rv = pthread_setname_np(pthread_self(), "%s", (void*)name);
#else
rv = pthread_setname_np(pthread_self(), name);
#endif
MOZ_RELEASE_ASSERT(!rv);
}
示例4: library_init
/* Thread: main */
int
library_init(void)
{
int i;
int ret;
scan_exit = false;
scanning = false;
CHECK_NULL(L_LIB, evbase_lib = event_base_new());
CHECK_NULL(L_LIB, updateev = evtimer_new(evbase_lib, update_trigger_cb, NULL));
for (i = 0; sources[i]; i++)
{
if (!sources[i]->init)
continue;
ret = sources[i]->init();
if (ret < 0)
sources[i]->disabled = 1;
}
CHECK_NULL(L_LIB, cmdbase = commands_base_new(evbase_lib, NULL));
CHECK_ERR(L_LIB, pthread_create(&tid_library, NULL, library, NULL));
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_library, "library");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_library, "library");
#endif
return 0;
}
示例5: SDL_SYS_SetupThread
void
SDL_SYS_SetupThread(const char *name)
{
int i;
sigset_t mask;
if (name != NULL) {
#if ( (__MACOSX__ && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)) || \
(__IPHONEOS__ && (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)) )
if (pthread_setname_np != NULL) {
pthread_setname_np(name);
}
#elif HAVE_PTHREAD_SETNAME_NP
pthread_setname_np(pthread_self(), name);
#elif HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name);
#endif
}
/* Mask asynchronous signals for this thread */
sigemptyset(&mask);
for (i = 0; sig_list[i]; ++i) {
sigaddset(&mask, sig_list[i]);
}
pthread_sigmask(SIG_BLOCK, &mask, 0);
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
/* Allow ourselves to be asynchronously cancelled */
{
int oldstate;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
}
#endif
}
示例6: thread_wrapper
static void *
thread_wrapper ( void *p )
{
struct thread_state *ts = p;
sigset_t set;
#if defined(PLATFORM_LINUX)
/* Set name */
prctl(PR_SET_NAME, ts->name);
#elif defined(PLATFORM_FREEBSD)
/* Set name of thread */
pthread_set_name_np(pthread_self(), ts->name);
#elif defined(PLATFORM_DARWIN)
pthread_setname_np(ts->name);
#endif
sigemptyset(&set);
sigaddset(&set, SIGTERM);
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
signal(SIGTERM, doexit);
/* Run */
tvhtrace("thread", "created thread %ld [%s / %p(%p)]",
(long)pthread_self(), ts->name, ts->run, ts->arg);
void *r = ts->run(ts->arg);
free(ts);
return r;
}
示例7: pthread_setname_np
void * Thread::entryPoint(void * param) {
Thread & thread = *((Thread *)param);
// Set the thread name.
#if ARX_HAVE_PTHREAD_SETNAME_NP && ARX_PLATFORM != ARX_PLATFORM_MACOSX
// Linux
pthread_setname_np(thread.thread, thread.threadName.c_str());
#elif ARX_HAVE_PTHREAD_SETNAME_NP && ARX_PLATFORM == ARX_PLATFORM_MACOSX
// Mac OS X
pthread_setname_np(thread.threadName.c_str());
#elif ARX_HAVE_PTHREAD_SET_NAME_NP
// FreeBSD & OpenBSD
pthread_set_name_np(thread.thread, thread.threadName.c_str());
#elif ARX_HAVE_PRCTL && defined(PR_SET_NAME)
// Linux
prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread.threadName.c_str()), 0, 0, 0);
#else
// This is non-fatal, but let's print a warning so future ports will be
// reminded to implement it.
#pragma message ( "No function available to set thread names!" )
#endif
CrashHandler::registerThreadCrashHandlers();
profiler::registerThread(thread.threadName);
thread.run();
profiler::unregisterThread();
CrashHandler::unregisterThreadCrashHandlers();
return NULL;
}
示例8: defined
void zmq::thread_t::setThreadName(const char *name_)
{
/* The thread name is a cosmetic string, added to ease debugging of
* multi-threaded applications. It is not a big issue if this value
* can not be set for any reason (such as Permission denied in some
* cases where the application changes its EUID, etc.) The value of
* "int rc" is retained where available, to help debuggers stepping
* through code to see its value - but otherwise it is ignored.
*/
if (!name_)
return;
#if defined(ZMQ_HAVE_PTHREAD_SETNAME_1)
int rc = pthread_setname_np(name_);
if(rc) return;
#elif defined(ZMQ_HAVE_PTHREAD_SETNAME_2)
int rc = pthread_setname_np(descriptor, name_);
if(rc) return;
#elif defined(ZMQ_HAVE_PTHREAD_SETNAME_3)
int rc = pthread_setname_np(descriptor, name_, NULL);
if(rc) return;
#elif defined(ZMQ_HAVE_PTHREAD_SET_NAME)
pthread_set_name_np(descriptor, name_);
#endif
}
示例9: r_th_setname
R_API bool r_th_setname(RThread *th, const char *name) {
#if defined(HAVE_PTHREAD_NP) && HAVE_PTHREAD_NP
#if __linux__
if (pthread_setname_np (th->tid, name) != 0) {
eprintf ("Failed to set thread name\n");
return false;
}
return true;
#elif __FreeBSD__ || __OpenBSD__ || __DragonFly__
pthread_set_name_np (th->tid, name);
return true;
#elif __NetBSD__
if (pthread_setname_np (th->tid, "%s", (void *)name) != 0) {
eprintf ("Failed to set thread name\n");
return false;
}
return true;
#else
#pragma message("warning r_th_setname not implemented")
#endif
#else
return true;
#endif
}
示例10: SetThisProcessName
void SetThisProcessName(const char *aName)
{
#if defined(OS_NETBSD)
pthread_setname_np(pthread_self(), "%s", (void *)aName);
#else
pthread_set_name_np(pthread_self(), aName);
#endif
}
示例11: THR_SetName
void
THR_SetName(const char *name)
{
AZ(pthread_setspecific(name_key, name));
#ifdef HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name);
#endif
}
示例12: thr_self
void CThread::SetThreadInfo()
{
#ifdef TARGET_FREEBSD
#if __FreeBSD_version < 900031
long lwpid;
thr_self(&lwpid);
m_ThreadOpaque.LwpId = lwpid;
#else
m_ThreadOpaque.LwpId = pthread_getthreadid_np();
#endif
#elif defined(TARGET_ANDROID)
m_ThreadOpaque.LwpId = gettid();
#else
m_ThreadOpaque.LwpId = syscall(SYS_gettid);
#endif
#if defined(HAVE_PTHREAD_SETNAME_NP)
#ifdef TARGET_DARWIN
#if(__MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 30200)
pthread_setname_np(m_ThreadName.c_str());
#endif
#else
pthread_setname_np(m_ThreadId, m_ThreadName.c_str());
#endif
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(m_ThreadId, m_ThreadName.c_str());
#endif
#ifdef RLIMIT_NICE
// get user max prio
struct rlimit limit;
int userMaxPrio;
if (getrlimit(RLIMIT_NICE, &limit) == 0)
{
userMaxPrio = limit.rlim_cur - 20;
if (userMaxPrio < 0)
userMaxPrio = 0;
}
else
userMaxPrio = 0;
if (geteuid() == 0)
userMaxPrio = GetMaxPriority();
// if the user does not have an entry in limits.conf the following
// call will fail
if (userMaxPrio > 0)
{
// start thread with nice level of appication
int appNice = getpriority(PRIO_PROCESS, getpid());
if (setpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId, appNice) != 0)
if (logger) logger->Log(LOGERROR, "%s: error %s", __FUNCTION__, strerror(errno));
}
#endif
}
示例13: SDL_SYS_SetupThread
void
SDL_SYS_SetupThread(const char *name)
{
#if !defined(__ANDROID__) && !defined(__NACL__)
int i;
sigset_t mask;
#endif /* !__ANDROID__ && !__NACL__ */
if (name != NULL) {
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
SDL_assert(checked_setname);
if (ppthread_setname_np != NULL) {
#if defined(__MACOSX__) || defined(__IPHONEOS__)
ppthread_setname_np(name);
#elif defined(__LINUX__)
ppthread_setname_np(pthread_self(), name);
#endif
}
#elif HAVE_PTHREAD_SETNAME_NP
#if defined(__NETBSD__)
pthread_setname_np(pthread_self(), "%s", name);
#else
pthread_setname_np(pthread_self(), name);
#endif
#elif HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name);
#elif defined(__HAIKU__)
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
char namebuf[B_OS_NAME_LENGTH];
SDL_snprintf(namebuf, sizeof (namebuf), "%s", name);
namebuf[sizeof (namebuf) - 1] = '\0';
rename_thread(find_thread(NULL), namebuf);
#endif
}
/* NativeClient does not yet support signals.*/
#if !defined(__ANDROID__) && !defined(__NACL__)
/* Mask asynchronous signals for this thread */
sigemptyset(&mask);
for (i = 0; sig_list[i]; ++i) {
sigaddset(&mask, sig_list[i]);
}
pthread_sigmask(SIG_BLOCK, &mask, 0);
#endif /* !__ANDROID__ && !__NACL__ */
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
/* Allow ourselves to be asynchronously cancelled */
{
int oldstate;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
}
#endif
}
示例14: setCurrentThreadName
void setCurrentThreadName(const std::string &name) {
#if defined (__linux__) && !defined(ANDROID)
prctl(PR_SET_NAME, name.c_str(), 0, 0, 0);
#elif defined (__APPLE__)
pthread_setname_np(name.c_str());
#elif defined (ANDROID)
//no implementation under Android
#else
//BSD, whatever...
pthread_set_name_np(pthread_self(), name.c_str());
#endif
}
示例15: sctp_userspace_set_threadname
void
sctp_userspace_set_threadname(const char *name)
{
#if defined(__Userspace_os_Darwin)
pthread_setname_np(name);
#endif
#if defined(__Userspace_os_Linux)
prctl(PR_SET_NAME, name);
#endif
#if defined(__Userspace_os_FreeBSD)
pthread_set_name_np(pthread_self(), name);
#endif
}