зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1296878 - Implement js::ThisThread::GetName for limited set of platforms, r=fitzgen
--HG-- extra : rebase_source : 43c3a5efd7e73e7b32728a58648f8606463b0147
This commit is contained in:
Родитель
6d99bf51ce
Коммит
843bd9aad4
|
@ -185,6 +185,12 @@ Thread::Id GetId();
|
|||
// nothing.
|
||||
void SetName(const char* name);
|
||||
|
||||
// Get the current thread name. As with SetName, not available on all
|
||||
// platforms. On these platforms getName() will give back an empty string (by
|
||||
// storing NUL in nameBuffer[0]). 'len' is the bytes available to be written in
|
||||
// 'nameBuffer', including the terminating NUL.
|
||||
void GetName(char* nameBuffer, size_t len);
|
||||
|
||||
} // namespace ThisThread
|
||||
|
||||
namespace detail {
|
||||
|
|
|
@ -164,3 +164,25 @@ js::ThisThread::SetName(const char* name)
|
|||
#endif
|
||||
MOZ_RELEASE_ASSERT(!rv);
|
||||
}
|
||||
|
||||
void
|
||||
js::ThisThread::GetName(char* nameBuffer, size_t len)
|
||||
{
|
||||
// Using http://stackoverflow.com/questions/2369738/can-i-set-the-name-of-a-thread-in-pthreads-linux as a reference.
|
||||
|
||||
int rv;
|
||||
#ifdef XP_DARWIN
|
||||
rv = pthread_getname_np(pthread_self(), nameBuffer, len);
|
||||
#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||
pthread_get_name_np(pthread_self(), nameBuffer, len);
|
||||
rv = 0;
|
||||
#elif defined(__NetBSD__)
|
||||
rv = pthread_getname_np(pthread_self(), nameBuffer, len);
|
||||
#else
|
||||
rv = pthread_getname_np(pthread_self(), nameBuffer, len);
|
||||
#endif
|
||||
|
||||
MOZ_RELEASE_ASSERT(len > 0);
|
||||
if (rv)
|
||||
nameBuffer[0] = '\0';
|
||||
}
|
||||
|
|
|
@ -155,3 +155,10 @@ js::ThisThread::SetName(const char* name)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
js::ThisThread::GetName(char* nameBuffer, size_t len)
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(len > 0);
|
||||
*nameBuffer = '\0';
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче