コード例 #1
0
ファイル: ThreadImpl.cpp プロジェクト: IchabodFletchman/xbmc
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
}
コード例 #2
0
ファイル: gcenv.unix.cpp プロジェクト: A-And/corert
// Get numeric id of the current thread if possible on the
// current platform. It is indended for logging purposes only.
// Return:
//  Numeric id of the current thread, as best we can retrieve it.
uint64_t GCToOSInterface::GetCurrentThreadIdForLogging()
{
#if defined(__linux__)
    return (uint64_t)syscall(SYS_gettid);
#elif HAVE_PTHREAD_GETTHREADID_NP
    return (uint64_t)pthread_getthreadid_np();
#elif HAVE_PTHREAD_THREADID_NP
    unsigned long long tid;
    pthread_threadid_np(pthread_self(), &tid);
    return (uint64_t)tid;
#else
    // Fallback in case we don't know how to get integer thread id on the current platform
    return (uint64_t)pthread_self();
#endif
}
コード例 #3
0
ファイル: common.c プロジェクト: tvieira/netdata
pid_t gettid(void) {
#ifdef __FreeBSD__
    return (pid_t)pthread_getthreadid_np();
#elif defined(__APPLE__)
#if (defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
    uint64_t curthreadid;
    pthread_threadid_np(NULL, &curthreadid);
    return (pid_t)curthreadid;
#else /* __MAC_OS_X_VERSION_MIN_REQUIRED */
    return (pid_t)pthread_self;
#endif /* __MAC_OS_X_VERSION_MIN_REQUIRED */
#else /* __APPLE__*/
    return (pid_t)syscall(SYS_gettid);
#endif /* __FreeBSD__, __APPLE__*/
}
コード例 #4
0
ファイル: ThreadImpl.cpp プロジェクト: Schischu/xbmc
void CThread::SetThreadInfo()
{
#ifdef __FreeBSD__
#if __FreeBSD_version < 900031
  long lwpid;
  thr_self(&lwpid);
  m_ThreadOpaque.LwpId = lwpid;
#else
  m_ThreadOpaque.LwpId = pthread_getthreadid_np();
#endif
#else
  m_ThreadOpaque.LwpId = syscall(SYS_gettid);
#endif

  // 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));
}
コード例 #5
0
ファイル: OSThreads.c プロジェクト: Morabbin/ghc
KernelThreadId kernelThreadId (void)
{
#if defined(linux_HOST_OS)
    pid_t tid = syscall(SYS_gettid); // no really, see man gettid
    return (KernelThreadId) tid;

/* FreeBSD 9.0+ */
#elif defined(freebsd_HOST_OS) && (__FreeBSD_version >= 900031)
    return pthread_getthreadid_np();

// Check for OS X >= 10.6 (see #7356)
#elif defined(darwin_HOST_OS) && !(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
    uint64_t ktid;
    pthread_threadid_np(NULL, &ktid);
    return ktid;

#else
    // unsupported
    return 0;
#endif
}
コード例 #6
0
ファイル: thread-utils.c プロジェクト: alf239/opendylan
uint64_t dylan_current_thread_id(void)
{
#if defined(OPEN_DYLAN_PLATFORM_LINUX)
  return syscall(SYS_gettid);
#elif defined(OPEN_DYLAN_PLATFORM_DARWIN)
  uint64_t tid;
  pthread_threadid_np(pthread_self(), &tid);
  return tid;
#elif defined(OPEN_DYLAN_PLATFORM_FREEBSD)
  return pthread_getthreadid_np();
#elif defined(OPEN_DYLAN_PLATFORM_NETBSD)
  return _lwp_self();
#elif defined(OPEN_DYLAN_PLATFORM_OPENBSD)
  return syscall(SYS_getthrid);
#elif defined(OPEN_DYLAN_PLATFORM_WINDOWS)
  return GetCurrentThreadId();
#else
  #error dylan_current_thread_id is not yet implemented.
#endif
  return 0;
}
コード例 #7
0
/***********************************************************************
 *           get_unix_tid
 *
 * Retrieve the Unix tid to use on the server side for the current thread.
 */
static int get_unix_tid(void)
{
    int ret = -1;
#ifdef HAVE_PTHREAD_GETTHREADID_NP
    ret = pthread_getthreadid_np();
#elif defined(linux)
    ret = syscall( __NR_gettid );
#elif defined(__sun)
    ret = pthread_self();
#elif defined(__APPLE__)
    ret = mach_thread_self();
    mach_port_deallocate(mach_task_self(), ret);
#elif defined(__NetBSD__)
    ret = _lwp_self();
#elif defined(__FreeBSD__)
    long lwpid;
    thr_self( &lwpid );
    ret = lwpid;
#elif defined(__DragonFly__)
    ret = lwp_gettid();
#endif
    return ret;
}
コード例 #8
0
ファイル: rthreads.c プロジェクト: ieei/rlib
          sizeof (THREADNAME_INFO) / sizeof (ULONG_PTR), (ULONG_PTR*)&info);
    } __except(EXCEPTION_EXECUTE_HANDLER) {
    }
#elif defined (HAVE_PTHREAD_SETNAME_NP_WITH_TID)
    pthread_setname_np (thread->thread, thread->name);
#elif defined (HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
    pthread_setname_np (thread->name);
#elif defined (HAVE_SYS_PRCTL_H) && defined (PR_SET_NAME)
    prctl (PR_SET_NAME, thread->name, 0, 0, 0, 0);
#else
#warning set thread name not supported
#endif
  }

#if defined (HAVE_PTHREAD_GETTHREADID_NP)
  thread->thread_id = (ruint)pthread_getthreadid_np ();
#elif defined (HAVE_PTHREAD_THREADID_NP)
  {
    __uint64_t ktid;
    pthread_threadid_np (NULL, &ktid);
    thread->thread_id = (ruint)ktid;
  }
#elif defined (HAVE_GETTID)
  thread->thread_id = (ruint)gettid ();
#endif

  R_LOG_INFO ("Thread %s [%u] starting", thread->name, thread->thread_id);
  thread->retval = thread->func (thread->data);
  R_LOG_TRACE ("Thread %s [%u] ending", thread->name, thread->thread_id);

#if defined (R_OS_WIN32)
コード例 #9
0
ファイル: arena_mt.c プロジェクト: mantyr/small
#endif
#include "unit.h"

struct slab_arena arena;
struct quota quota;

int THREADS = 8;
int ITERATIONS = 1009 /* 100003 */;
int OSCILLATION = 137;
int FILL = SLAB_MIN_SIZE/sizeof(pthread_t);

void *
run(void *p __attribute__((unused)))
{
#ifdef __FreeBSD__
	unsigned int seed = pthread_getthreadid_np();
#else
	unsigned int seed = (unsigned int) pthread_self();
#endif
	int iterations = rand_r(&seed) % ITERATIONS;
	pthread_t **slabs = slab_map(&arena);
	for (int i = 0; i < iterations; i++) {
		int oscillation = rand_r(&seed) % OSCILLATION;
		for (int osc = 0; osc  < oscillation; osc++) {
			slabs[osc] = (pthread_t *) slab_map(&arena);
			for (int fill = 0; fill < FILL; fill += 100) {
				slabs[osc][fill] = pthread_self();
			}
		}
		sched_yield();
		for (int osc = 0; osc  < oscillation; osc++) {