• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pthread_set_name_np函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pthread_set_name_np函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_set_name_np函数的具体用法?C++ pthread_set_name_np怎么用?C++ pthread_set_name_np使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pthread_set_name_np函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:cdotstout,项目名称:RBDOOM-3-BFG,代码行数:27,代码来源:posix_thread.cpp


示例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
};
开发者ID:AM7000000,项目名称:godot,代码行数:29,代码来源:thread_posix.cpp


示例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);
}
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:28,代码来源:Thread.cpp


示例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;
}
开发者ID:couteau,项目名称:forked-daapd,代码行数:35,代码来源:library.c


示例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
}
开发者ID:IronYan,项目名称:kudou-player,代码行数:34,代码来源:SDL_systhread.c


示例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;
}
开发者ID:c0mm0n,项目名称:tvheadend,代码行数:30,代码来源:wrappers.c


示例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;
}
开发者ID:Drakesinger,项目名称:ArxLibertatis,代码行数:30,代码来源:Thread.cpp


示例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
}
开发者ID:arsenm,项目名称:libzmq,代码行数:25,代码来源:thread.cpp


示例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
}
开发者ID:hewittc,项目名称:radare2,代码行数:26,代码来源:thread.c


示例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
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:8,代码来源:ProcessUtils_bsd.cpp


示例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
}
开发者ID:gauthier-delacroix,项目名称:varnish-cache,代码行数:9,代码来源:cache_main.c


示例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
}
开发者ID:IchabodFletchman,项目名称:xbmc,代码行数:55,代码来源:ThreadImpl.cpp


示例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
}
开发者ID:MichalWolodkiewicz,项目名称:wizznic-android,代码行数:54,代码来源:SDL_systhread.c


示例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
 }
开发者ID:gnatali,项目名称:libqi,代码行数:12,代码来源:os_posix.cpp


示例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
}
开发者ID:BillTheBest,项目名称:usrsctp,代码行数:13,代码来源:sctp_userspace.c


示例16: SetThreadName

//! Set the thread's name at the process level. Does not affect the
//! internal name.
static void SetThreadName(const char* name)
{
#if defined(PR_SET_NAME)
    // Only the first 15 characters are used (16 - NUL terminator)
    ::prctl(PR_SET_NAME, name, 0, 0, 0);
#elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
    pthread_set_name_np(pthread_self(), name);
#elif defined(MAC_OSX)
    pthread_setname_np(name);
#else
    // Prevent warnings for unused parameters...
    (void)name;
#endif
}
开发者ID:dgenr8,项目名称:bitcoin,代码行数:16,代码来源:threadnames.cpp


示例17: set_subprogram_name

/* Sets 'subprogram_name' as the name of the currently running thread or
 * process.  (This appears in log messages and may also be visible in system
 * process listings and debuggers.) */
void
set_subprogram_name(const char *subprogram_name)
{
    char *pname = xstrdup(subprogram_name ? subprogram_name : program_name);
    free(subprogram_name_set(pname));

#if HAVE_GLIBC_PTHREAD_SETNAME_NP
    pthread_setname_np(pthread_self(), pname);
#elif HAVE_NETBSD_PTHREAD_SETNAME_NP
    pthread_setname_np(pthread_self(), "%s", pname);
#elif HAVE_PTHREAD_SET_NAME_NP
    pthread_set_name_np(pthread_self(), pname);
#endif
}
开发者ID:wenxueliu,项目名称:code_clips,代码行数:17,代码来源:daemon-unix.c


示例18: fm_fft_thread_start

int
fm_fft_thread_start(struct fm_fft_thread *ft)
{
	int r;

	r = pthread_create(&ft->ft_thr, NULL, fm_fft_thread_thr, ft);
	if (r != 0) {
		warn("%s: pthread_create", __func__);
		return (-1);
	}

	pthread_set_name_np(ft->ft_thr, "fft_thread");

	return (0);
}
开发者ID:erikarn,项目名称:rtl-sdr-hacking,代码行数:15,代码来源:fm_fft_thread.c


示例19: return

/**
 * First pthread child -- pull stuff apart and re-exec user's first function
 *
 * Also, disable cancellation, disable signals, install tracking list cleanup
 * handler, make detached, start user processing
 *
 * THREADS: MT-SAFE
 *
 * @param opaque Data from pthread which is hopefully my tcomm
 * @return stuff from user function which is then ignored
 */
static void *bk_thread_continue(void *opaque)
{
  struct bk_threadcomm *tcomm = opaque;
  bk_s B;
  void *subopaque;
  void *(*start)(bk_s, void *);
  sigset_t mask;

  if (!tcomm)
  {
    return(NULL);

    // <TRICKY>Work around gcc bug</TRICKY>
    subopaque = &subopaque;
  }

  // Block all signals except SIGCONT (to allow interrupting select calls)
  sigfillset(&mask);
  sigdelset(&mask, SIGCONT);
  pthread_sigmask(SIG_BLOCK, &mask, NULL);

  // Defer cancel until cancel point (per POSIX, this is default - be paranoid)
  pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);

  // Turn on cacellability
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

  B = tcomm->btc_B;
  subopaque = tcomm->btc_opaque;
  start = tcomm->btc_start;
  setitimer(ITIMER_PROF, &tcomm->btc_itimer, NULL);

  pthread_getcpuclockid(pthread_self(), &(BK_BT_CPU_CLOCK(B)));

  free(opaque);

#ifdef HAVE_PTHREAD_SET_NAME_NP
  // what the hell, might as well...
  pthread_set_name_np(pthread_self(), (char *)BK_BT_THREADNAME(B));
#endif

  pthread_cleanup_push(bk_thread_cleanup, B);
  subopaque = (*start)(B, subopaque);
  bk_thread_cancel(B, pthread_self(), 0);
  pthread_cleanup_pop(1);

  return subopaque;
}
开发者ID:SethRobertson,项目名称:libbk,代码行数:59,代码来源:b_thread.c


示例20: dylan_set_current_thread_name

void dylan_set_current_thread_name(const char *name) {
#ifdef OPEN_DYLAN_PLATFORM_LINUX
  /* gdb shows this, so set it too */
  prctl(PR_SET_NAME, (unsigned long)name, 0, 0, 0);
  extern int pthread_setname_np(pthread_t, const char*) __attribute__((weak));
  if (pthread_setname_np) {
    pthread_setname_np(pthread_self(), name);
  }
#endif
#ifdef OPEN_DYLAN_PLATFORM_FREEBSD
  pthread_set_name_np(pthread_self(), name);
#endif
#ifdef OPEN_DYLAN_PLATFORM_DARWIN
  pthread_setname_np(name);
#endif
}
开发者ID:alf239,项目名称:opendylan,代码行数:16,代码来源:thread-utils.c



注:本文中的pthread_set_name_np函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pthread_setaffinity_np函数代码示例发布时间:2022-05-30
下一篇:
C++ pthread_self函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap