| 114 | } |
| 115 | |
| 116 | explicit ThreadNameImpl(const std::string& name) |
| 117 | : reset(false) |
| 118 | { |
| 119 | tid = pthread_self(); |
| 120 | |
| 121 | if (!get(old_name)) |
| 122 | return; |
| 123 | |
| 124 | reset = set(name.c_str()); |
| 125 | if (reset) |
| 126 | return; |
| 127 | |
| 128 | // Try with a shorter name. 15 is the upper limit supported by Linux, |
| 129 | // other platforms should support a larger value. So 15 should works |
| 130 | // on all platforms. |
| 131 | const size_t max_len = 15; |
| 132 | if (name.size() > max_len) |
| 133 | reset = set(name.substr(0, max_len).c_str()); |
| 134 | } |
| 135 | |
| 136 | ~ThreadNameImpl() |
| 137 | { |