blob: 6d0c5b9b1d6b912e256d7a689040984631d438e2 [file] [log] [blame]
Zonr Changc09dee62012-04-12 17:15:30 +08001/*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "BCCContext.h"
18
19#include <new>
20
21#include "BCCContextImpl.h"
22#include "DebugHelper.h"
23
24using namespace bcc;
25
26static BCCContext *GlobalContext = NULL;
27
28BCCContext *BCCContext::GetOrCreateGlobalContext() {
29 if (GlobalContext == NULL) {
30 GlobalContext = new (std::nothrow) BCCContext();
31 if (GlobalContext == NULL) {
32 ALOGE("Out of memory when allocate global BCCContext!");
33 }
34 }
35 return GlobalContext;
36}
37
38void BCCContext::DestroyGlobalContext() {
39 delete GlobalContext;
40 GlobalContext = NULL;
41}
42
43BCCContext::BCCContext() : mImpl(new BCCContextImpl(*this)) { }
44
45BCCContext::~BCCContext() {
46 delete mImpl;
47 if (this == GlobalContext) {
48 // We're deleting the context returned from GetOrCreateGlobalContext().
49 // Reset the GlobalContext.
50 GlobalContext = NULL;
51 }
52 return;
53}
54
55llvm::LLVMContext &BCCContext::getLLVMContext()
56{ return mImpl->mLLVMContext; }
57
58const llvm::LLVMContext &BCCContext::getLLVMContext() const
59{ return mImpl->mLLVMContext; }