Пример #1
0
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
0
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
0
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
0
/* 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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
0
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
}
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
0
 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
0
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
}
Пример #16
0
//! 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
}
Пример #17
0
/* 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
}
Пример #18
0
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);
}
Пример #19
0
/**
 * 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;
}
Пример #20
0
/* Thread: main */
int
filescanner_init(void)
{
  int ret;

  scan_exit = 0;
  scanning = 0;

  evbase_scan = event_base_new();
  if (!evbase_scan)
    {
      DPRINTF(E_FATAL, L_SCAN, "Could not create an event base\n");

      return -1;
    }

  ret = inofd_event_set();
  if (ret < 0)
    {
      goto ino_fail;
    }

  cmdbase = commands_base_new(evbase_scan, NULL);

  ret = pthread_create(&tid_scan, NULL, filescanner, NULL);
  if (ret != 0)
    {
      DPRINTF(E_FATAL, L_SCAN, "Could not spawn filescanner thread: %s\n", strerror(errno));

      goto thread_fail;
    }

#if defined(HAVE_PTHREAD_SETNAME_NP)
  pthread_setname_np(tid_scan, "filescanner");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
  pthread_set_name_np(tid_scan, "filescanner");
#endif

  return 0;

 thread_fail:
  commands_base_free(cmdbase);
  close(inofd);
 ino_fail:
  event_base_free(evbase_scan);

  return -1;
}
Пример #21
0
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
}
Пример #22
0
void althrd_setname(althrd_t thr, const char *name)
{
#if defined(HAVE_PTHREAD_SETNAME_NP)
#if defined(__GNUC__)
    pthread_setname_np(thr, name);
#elif defined(__APPLE__)
    if(althrd_equal(thr, althrd_current())
        pthread_setname_np(name);
#endif
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
    pthread_set_name_np(thr, name);
#else
    (void)thr;
    (void)name;
#endif
}
Пример #23
0
void Thread::setName(const std::string &name)
{
#if defined(linux) || defined(__linux)

	// 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.c_str());

#elif defined(__FreeBSD__) || defined(__OpenBSD__)

	pthread_set_name_np(pthread_self(), name.c_str());

#elif defined(__NetBSD__)

	pthread_setname_np(pthread_self(), name.c_str());

#elif defined(__APPLE__)

	pthread_setname_np(name.c_str());

#elif defined(_MSC_VER)

	// Windows itself doesn't support thread names,
	// but the MSVC debugger does...
	THREADNAME_INFO info;

	info.dwType = 0x1000;
	info.szName = name.c_str();
	info.dwThreadID = -1;
	info.dwFlags = 0;

	__try {
		RaiseException(0x406D1388, 0,
			sizeof(info) / sizeof(DWORD), (ULONG_PTR *)&info);
	} __except (EXCEPTION_CONTINUE_EXECUTION) {
	}

#elif defined(_WIN32) || defined(__GNU__)

	// These platforms are known to not support thread names.
	// Silently ignore the request.

#else
	#warning "Unrecognized platform, thread names will not be available."
#endif
}
Пример #24
0
void
THR_SetName(const char *name)
{

	AZ(pthread_setspecific(name_key, name));
#if defined(HAVE_PTHREAD_SET_NAME_NP)
	pthread_set_name_np(pthread_self(), name);
#elif defined(HAVE_PTHREAD_SETNAME_NP)
#if defined(__APPLE__)
	pthread_setname_np(name);
#elif defined(__NetBSD__)
	pthread_setname_np(pthread_self(), "%s", (char *)(uintptr_t)name);
#else
	pthread_setname_np(pthread_self(), name);
#endif
#endif
}
Пример #25
0
PRStatus
PR_SetCurrentThreadName(const char* name)
{
    int result;
#ifdef XP_MACOSX
    result = pthread_setname_np(name);
#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
    pthread_set_name_np(pthread_self(), name);
    result = 0;
#elif defined(__NetBSD__)
    result = pthread_setname_np(pthread_self(), "%s", (void*)name);
#else
    result = pthread_setname_np(pthread_self(), name);
#endif
    if (result)
        return PR_FAILURE;
    return PR_SUCCESS;
}
Пример #26
0
void althrd_setname(althrd_t thr, const char *name)
{
#if defined(HAVE_PTHREAD_SETNAME_NP)
#if defined(PTHREAD_SETNAME_NP_ONE_PARAM)
    if(althrd_equal(thr, althrd_current()))
        pthread_setname_np(name);
#elif defined(PTHREAD_SETNAME_NP_THREE_PARAMS)
    pthread_setname_np(thr, "%s", (void*)name);
#else
    pthread_setname_np(thr, name);
#endif
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
    pthread_set_name_np(thr, name);
#else
    (void)thr;
    (void)name;
#endif
}
Пример #27
0
static void *
fbsdrun_start_thread(void *param)
{
	char tname[MAXCOMLEN + 1];
	struct mt_vmm_info *mtp;
	int vcpu;

	mtp = param;
	vcpu = mtp->mt_vcpu;

	snprintf(tname, sizeof(tname), "vcpu %d", vcpu);
	pthread_set_name_np(mtp->mt_thr, tname);

	vm_loop(mtp->mt_ctx, vcpu, vmexit[vcpu].rip);

	/* not reached */
	exit(1);
	return (NULL);
}
Пример #28
0
static void __create_thread(pthread_t *tid, const char *name, int seq)
{
	struct sched_param param;
	pthread_attr_t attr;
	int ret;

	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
	pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
	pthread_attr_setschedparam(&attr, &param);
	pthread_attr_setstacksize(&attr, 64*1024);
	ret = pthread_create(tid, &attr, thread_body, (void *)(long)seq);
	if (ret)
		error(1, ret, "pthread_create");

	pthread_attr_destroy(&attr);
	pthread_set_name_np(*tid, name);
}
Пример #29
0
/* Start a new thread. */
ILIAS_NET2_LOCAL struct net2_thread*
net2_thread_new(void *(*fn)(void*), void *arg, const char *name)
{
	struct net2_thread	*t;

	if ((t = net2_malloc(sizeof(*t))) == NULL)
		return NULL;
	t->fn = fn;
	t->arg = arg;
	if (pthread_create(&t->n2t_impl, NULL, &thread_wrapper, t)) {
		warn("pthread_create");
		net2_free(t);
		return NULL;
	}

#ifdef HAS_PTHREAD_SET_NAME_NP
	if (name != NULL)
		pthread_set_name_np(t->n2t_impl, name);
#endif /* HAS_PTHREAD_SET_NAME_NP */
	return t;
}
Пример #30
0
static void *
thread_wrapper ( void *p )
{
  struct thread_state *ts = p;

#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);
#endif

  /* Run */
  tvhdebug("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;
}