X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FThreadName.h;h=d78e2fa17a5430e52ca67664dcb3b676210aef2d;hb=55af3d190b31e6b09943bb6456dc1085688fc007;hp=dbcdc84ed2ed55f8b67677f957e46d3d21b9d426;hpb=e892dc54738ff07c2827775a208767b2018a6b13;p=folly.git diff --git a/folly/ThreadName.h b/folly/ThreadName.h index dbcdc84e..d78e2fa1 100644 --- a/folly/ThreadName.h +++ b/folly/ThreadName.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,21 +16,33 @@ #pragma once -#include +#include +#include + +#include #include +#include +#include namespace folly { +/** + * This returns true if the current platform supports setting the name of the + * current thread. + */ +bool canSetCurrentThreadName(); +/** + * This returns true if the current platform supports setting the name of + * threads other than the one currently executing. + */ +bool canSetOtherThreadName(); +/** + * Get the name of the current string, or nothing if an error occurs. + */ +Optional getCurrentThreadName(); -inline bool setThreadName(pthread_t id, StringPiece name) { -#if (defined(__GLIBC__) && __GLIBC_PREREQ(2, 12)) - return 0 == pthread_setname_np(id, name.fbstr().substr(0, 15).c_str()); -#else - return false; +bool setThreadName(std::thread::id tid, StringPiece name); +#if FOLLY_HAVE_PTHREAD +bool setThreadName(pthread_t pid, StringPiece name); #endif -} - -inline bool setThreadName(StringPiece name) { - return setThreadName(pthread_self(), name); -} - +bool setThreadName(StringPiece name); }