Bug 1296878 - Implement js::ThisThread::GetName for limited set of platforms, r=fitzgen

--HG--
extra : rebase_source : 43c3a5efd7e73e7b32728a58648f8606463b0147
This commit is contained in:
Steve Fink 2016-08-20 11:55:37 -07:00
Родитель 6d99bf51ce
Коммит 843bd9aad4
3 изменённых файлов: 35 добавлений и 0 удалений

Просмотреть файл

@ -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';
}