1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CRAZY_LINKER_GLOBALS_H
6#define CRAZY_LINKER_GLOBALS_H
7
8#include <pthread.h>
9
10#include "crazy_linker_library_list.h"
11#include "crazy_linker_rdebug.h"
12#include "crazy_linker_search_path_list.h"
13#include "crazy_linker_util.h"
14
15// All crazy linker globals are declared in this header.
16
17namespace crazy {
18
19class Globals {
20 public:
21  Globals();
22  ~Globals();
23
24  void Lock() { pthread_mutex_lock(&lock_); }
25
26  void Unlock() { pthread_mutex_unlock(&lock_); }
27
28  static Globals* Get();
29
30  static LibraryList* GetLibraries() { return &Get()->libraries_; }
31
32  static SearchPathList* GetSearchPaths() { return &Get()->search_paths_; }
33
34  static RDebug* GetRDebug() { return &Get()->rdebug_; }
35
36 private:
37  pthread_mutex_t lock_;
38  LibraryList libraries_;
39  SearchPathList search_paths_;
40  RDebug rdebug_;
41};
42
43// Helper class to access the globals with scoped locking.
44class ScopedGlobalLock {
45 public:
46  ScopedGlobalLock() { Globals::Get()->Lock(); }
47
48  ~ScopedGlobalLock() { Globals::Get()->Unlock(); }
49};
50
51}  // namespace crazy
52
53#endif  // CRAZY_LINKER_GLOBALS_H
54