Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_THREADING_THREAD_ID_NAME_MANAGER_H_ |
michael@0 | 6 | #define BASE_THREADING_THREAD_ID_NAME_MANAGER_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <map> |
michael@0 | 9 | #include <string> |
michael@0 | 10 | |
michael@0 | 11 | #include "base/base_export.h" |
michael@0 | 12 | #include "base/basictypes.h" |
michael@0 | 13 | #include "base/synchronization/lock.h" |
michael@0 | 14 | #include "base/threading/platform_thread.h" |
michael@0 | 15 | |
michael@0 | 16 | template <typename T> struct DefaultSingletonTraits; |
michael@0 | 17 | |
michael@0 | 18 | namespace base { |
michael@0 | 19 | |
michael@0 | 20 | class BASE_EXPORT ThreadIdNameManager { |
michael@0 | 21 | public: |
michael@0 | 22 | static ThreadIdNameManager* GetInstance(); |
michael@0 | 23 | |
michael@0 | 24 | static const char* GetDefaultInternedString(); |
michael@0 | 25 | |
michael@0 | 26 | // Register the mapping between a thread |id| and |handle|. |
michael@0 | 27 | void RegisterThread(PlatformThreadHandle::Handle handle, PlatformThreadId id); |
michael@0 | 28 | |
michael@0 | 29 | // Set the name for the given id. |
michael@0 | 30 | void SetName(PlatformThreadId id, const char* name); |
michael@0 | 31 | |
michael@0 | 32 | // Get the name for the given id. |
michael@0 | 33 | const char* GetName(PlatformThreadId id); |
michael@0 | 34 | |
michael@0 | 35 | // Remove the name for the given id. |
michael@0 | 36 | void RemoveName(PlatformThreadHandle::Handle handle, PlatformThreadId id); |
michael@0 | 37 | |
michael@0 | 38 | private: |
michael@0 | 39 | friend struct DefaultSingletonTraits<ThreadIdNameManager>; |
michael@0 | 40 | |
michael@0 | 41 | typedef std::map<PlatformThreadId, PlatformThreadHandle::Handle> |
michael@0 | 42 | ThreadIdToHandleMap; |
michael@0 | 43 | typedef std::map<PlatformThreadHandle::Handle, std::string*> |
michael@0 | 44 | ThreadHandleToInternedNameMap; |
michael@0 | 45 | typedef std::map<std::string, std::string*> NameToInternedNameMap; |
michael@0 | 46 | |
michael@0 | 47 | ThreadIdNameManager(); |
michael@0 | 48 | ~ThreadIdNameManager(); |
michael@0 | 49 | |
michael@0 | 50 | // lock_ protects the name_to_interned_name_, thread_id_to_handle_ and |
michael@0 | 51 | // thread_handle_to_interned_name_ maps. |
michael@0 | 52 | Lock lock_; |
michael@0 | 53 | |
michael@0 | 54 | NameToInternedNameMap name_to_interned_name_; |
michael@0 | 55 | ThreadIdToHandleMap thread_id_to_handle_; |
michael@0 | 56 | ThreadHandleToInternedNameMap thread_handle_to_interned_name_; |
michael@0 | 57 | |
michael@0 | 58 | // Treat the main process specially as there is no PlatformThreadHandle. |
michael@0 | 59 | std::string* main_process_name_; |
michael@0 | 60 | PlatformThreadId main_process_id_; |
michael@0 | 61 | |
michael@0 | 62 | DISALLOW_COPY_AND_ASSIGN(ThreadIdNameManager); |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | } // namespace base |
michael@0 | 66 | |
michael@0 | 67 | #endif // BASE_THREADING_THREAD_ID_NAME_MANAGER_H_ |