security/sandbox/chromium/base/threading/thread_id_name_manager.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/chromium/base/threading/thread_id_name_manager.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
     1.9 +#define BASE_THREADING_THREAD_ID_NAME_MANAGER_H_
    1.10 +
    1.11 +#include <map>
    1.12 +#include <string>
    1.13 +
    1.14 +#include "base/base_export.h"
    1.15 +#include "base/basictypes.h"
    1.16 +#include "base/synchronization/lock.h"
    1.17 +#include "base/threading/platform_thread.h"
    1.18 +
    1.19 +template <typename T> struct DefaultSingletonTraits;
    1.20 +
    1.21 +namespace base {
    1.22 +
    1.23 +class BASE_EXPORT ThreadIdNameManager {
    1.24 + public:
    1.25 +  static ThreadIdNameManager* GetInstance();
    1.26 +
    1.27 +  static const char* GetDefaultInternedString();
    1.28 +
    1.29 +  // Register the mapping between a thread |id| and |handle|.
    1.30 +  void RegisterThread(PlatformThreadHandle::Handle handle, PlatformThreadId id);
    1.31 +
    1.32 +  // Set the name for the given id.
    1.33 +  void SetName(PlatformThreadId id, const char* name);
    1.34 +
    1.35 +  // Get the name for the given id.
    1.36 +  const char* GetName(PlatformThreadId id);
    1.37 +
    1.38 +  // Remove the name for the given id.
    1.39 +  void RemoveName(PlatformThreadHandle::Handle handle, PlatformThreadId id);
    1.40 +
    1.41 + private:
    1.42 +  friend struct DefaultSingletonTraits<ThreadIdNameManager>;
    1.43 +
    1.44 +  typedef std::map<PlatformThreadId, PlatformThreadHandle::Handle>
    1.45 +      ThreadIdToHandleMap;
    1.46 +  typedef std::map<PlatformThreadHandle::Handle, std::string*>
    1.47 +      ThreadHandleToInternedNameMap;
    1.48 +  typedef std::map<std::string, std::string*> NameToInternedNameMap;
    1.49 +
    1.50 +  ThreadIdNameManager();
    1.51 +  ~ThreadIdNameManager();
    1.52 +
    1.53 +  // lock_ protects the name_to_interned_name_, thread_id_to_handle_ and
    1.54 +  // thread_handle_to_interned_name_ maps.
    1.55 +  Lock lock_;
    1.56 +
    1.57 +  NameToInternedNameMap name_to_interned_name_;
    1.58 +  ThreadIdToHandleMap thread_id_to_handle_;
    1.59 +  ThreadHandleToInternedNameMap thread_handle_to_interned_name_;
    1.60 +
    1.61 +  // Treat the main process specially as there is no PlatformThreadHandle.
    1.62 +  std::string* main_process_name_;
    1.63 +  PlatformThreadId main_process_id_;
    1.64 +
    1.65 +  DISALLOW_COPY_AND_ASSIGN(ThreadIdNameManager);
    1.66 +};
    1.67 +
    1.68 +}  // namespace base
    1.69 +
    1.70 +#endif  // BASE_THREADING_THREAD_ID_NAME_MANAGER_H_

mercurial