/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
#include"base/platform_thread.h"
#include <errno.h> #include <sched.h>
#ifdefined(XP_DARWIN) # include <mach/mach.h> #elifdefined(XP_NETBSD) # include <lwp.h> #elifdefined(XP_LINUX) # include <sys/syscall.h> # include <sys/prctl.h> #endif
#if !defined(XP_DARWIN) # include <unistd.h> #endif
// static
PlatformThreadId PlatformThread::CurrentId() { // Pthreads doesn't have the concept of a thread ID, so we have to reach down // into the kernel. #ifdefined(XP_DARWIN)
mach_port_t port = mach_thread_self();
mach_port_deallocate(mach_task_self(), port); return port; #elifdefined(XP_LINUX) return syscall(__NR_gettid); #elifdefined(XP_OPENBSD) || defined(XP_SOLARIS) || defined(__GLIBC__) return (intptr_t)(pthread_self()); #elifdefined(XP_NETBSD) return _lwp_self(); #elifdefined(__DragonFly__) return lwp_gettid(); #elifdefined(XP_FREEBSD) return pthread_getthreadid_np(); #endif
}
#ifndef XP_DARWIN // Mac is implemented in platform_thread_mac.mm.
// static void PlatformThread::SetName(constchar* name) { // On linux we can get the thread names to show up in the debugger by setting // the process name for the LWP. We don't want to do this for the main // thread because that would rename the process, causing tools like killall // to stop working. if (PlatformThread::CurrentId() == getpid()) return;
// Using NS_SetCurrentThreadName, as opposed to using platform APIs directly, // also sets the thread name on the PRThread wrapper, and allows us to // retrieve it using PR_GetThreadName.
NS_SetCurrentThreadName(name);
} #endif// !XP_DARWIN
// Pthreads are joinable by default, so only specify the detached attribute if // the thread should be non-joinable. if (!joinable) {
pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
}
if (stack_size == 0) stack_size = nsIThreadManager::DEFAULT_STACK_SIZE;
pthread_attr_setstacksize(&attributes, stack_size);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.