blob: 0654b29f13d60ede9d219d7a12a5ecf3e3e98220 [file] [log] [blame]
Janis Danisevskisa75e2082020-10-07 16:44:26 -07001// Copyright 2020, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! This module holds global state of Keystore such as the thread local
16//! database connections and connections to services that Keystore needs
17//! to talk to.
18
19use crate::database::KeystoreDB;
20use std::cell::RefCell;
21
22thread_local! {
23 /// Database connections are not thread safe, but connecting to the
24 /// same database multiple times is safe as long as each connection is
25 /// used by only one thread. So we store one database connection per
26 /// thread in this thread local key.
27 pub static DB: RefCell<KeystoreDB> =
28 RefCell::new(KeystoreDB::new().expect("Failed to open database."));
29}