blob: 3ef75c83ed9031537f8484cf2c98b2a050bf425c [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> =
Janis Danisevskisbf15d732020-12-08 10:35:26 -080028 RefCell::new(
29 KeystoreDB::new(
30 // Keystore changes to the database directory on startup
31 // (see keystor2_main.rs).
32 &std::env::current_dir()
33 .expect("Could not get the current working directory.")
34 )
35 .expect("Failed to open database."));
Janis Danisevskisa75e2082020-10-07 16:44:26 -070036}