1/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7    http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#include "tensorflow/compiler/xla/service/cpu/orc_jit_memory_mapper.h"
17#include "tensorflow/core/platform/logging.h"
18#include "tensorflow/core/platform/mutex.h"
19
20namespace xla {
21namespace cpu {
22namespace orc_jit_memory_mapper {
23
24static tensorflow::mutex mapper_instance_mutex(tensorflow::LINKER_INITIALIZED);
25static llvm::SectionMemoryManager::MemoryMapper* mapper_instance
26    GUARDED_BY(mapper_instance_mutex) = nullptr;
27
28llvm::SectionMemoryManager::MemoryMapper* GetInstance() {
29  tensorflow::mutex_lock lock(mapper_instance_mutex);
30  return mapper_instance;
31}
32
33Registrar::Registrar(
34    std::unique_ptr<llvm::SectionMemoryManager::MemoryMapper> mapper) {
35  tensorflow::mutex_lock lock(mapper_instance_mutex);
36  mapper_instance = mapper.release();
37}
38}  // namespace orc_jit_memory_mapper
39}  // namespace cpu
40}  // namespace xla
41