blob: 62995ed8686624216633008c7f9442dadc2deaeb [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"
Shih-wei Liao4ce024b2012-04-25 03:40:50 -070023#include "Source.h"
Zonr Changc09dee62012-04-12 17:15:30 +080024
25using namespace bcc;
26
27static BCCContext *GlobalContext = NULL;
28
29BCCContext *BCCContext::GetOrCreateGlobalContext() {
30 if (GlobalContext == NULL) {
31 GlobalContext = new (std::nothrow) BCCContext();
32 if (GlobalContext == NULL) {
33 ALOGE("Out of memory when allocate global BCCContext!");
34 }
35 }
36 return GlobalContext;
37}
38
39void BCCContext::DestroyGlobalContext() {
40 delete GlobalContext;
41 GlobalContext = NULL;
42}
43
Zonr Changfef9a1b2012-04-13 15:58:24 +080044BCCContext::BCCContext() : mImpl(new BCCContextImpl(*this)) { }
Zonr Changc09dee62012-04-12 17:15:30 +080045
46BCCContext::~BCCContext() {
47 delete mImpl;
48 if (this == GlobalContext) {
49 // We're deleting the context returned from GetOrCreateGlobalContext().
50 // Reset the GlobalContext.
51 GlobalContext = NULL;
52 }
Zonr Changc09dee62012-04-12 17:15:30 +080053}
54
Shih-wei Liao4ce024b2012-04-25 03:40:50 -070055void BCCContext::addSource(Source &pSource)
56{ mImpl->mOwnSources.insert(&pSource); }
57
58void BCCContext::removeSource(Source &pSource)
59{ mImpl->mOwnSources.erase(&pSource); }
60
Zonr Changc09dee62012-04-12 17:15:30 +080061llvm::LLVMContext &BCCContext::getLLVMContext()
62{ return mImpl->mLLVMContext; }
63
64const llvm::LLVMContext &BCCContext::getLLVMContext() const
65{ return mImpl->mLLVMContext; }