Skip to content

Commit 98326e3

Browse files
committed
service: remove explict Sync and Send markers from AppService
Signed-off-by: Jun Kimura <[email protected]>
1 parent 09cdf36 commit 98326e3

File tree

4 files changed

+64
-22
lines changed

4 files changed

+64
-22
lines changed

modules/enclave-api/src/enclave.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use store::host::{HostStore, IntoCommitStore};
99
use store::transaction::{CommitStore, CreatedTx, UpdateKey};
1010

1111
/// `Enclave` keeps an enclave id and reference to the host environement
12-
pub struct Enclave<S> {
12+
pub struct Enclave<S: CommitStore> {
1313
pub(crate) path: PathBuf,
1414
pub(crate) key_manager: EnclaveKeyManager,
1515
pub(crate) store: Arc<RwLock<HostStore>>,
1616
pub(crate) sgx_enclave: SgxEnclave,
1717
_marker: PhantomData<S>,
1818
}
1919

20-
impl<S> Enclave<S> {
20+
impl<S: CommitStore> Enclave<S> {
2121
pub fn new(
2222
path: impl Into<PathBuf>,
2323
key_manager: EnclaveKeyManager,
@@ -49,7 +49,7 @@ impl<S> Enclave<S> {
4949
}
5050

5151
/// `EnclaveInfo` is an accessor to enclave information
52-
pub trait EnclaveInfo {
52+
pub trait EnclaveInfo: Sync + Send {
5353
/// `get_eid` returns the enclave id
5454
fn get_eid(&self) -> sgx_enclave_id_t;
5555
/// `metadata` returns the metadata of the enclave
@@ -58,7 +58,7 @@ pub trait EnclaveInfo {
5858
fn get_key_manager(&self) -> &EnclaveKeyManager;
5959
}
6060

61-
impl<S> EnclaveInfo for Enclave<S> {
61+
impl<S: CommitStore> EnclaveInfo for Enclave<S> {
6262
/// `get_eid` returns the enclave id
6363
fn get_eid(&self) -> sgx_enclave_id_t {
6464
self.sgx_enclave.geteid()

modules/service/src/service.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ where
3333
}
3434
}
3535

36-
unsafe impl<E, S> Send for AppService<E, S>
37-
where
38-
S: CommitStore + 'static,
39-
E: EnclaveProtoAPI<S> + 'static,
40-
{
41-
}
42-
unsafe impl<E, S> Sync for AppService<E, S>
43-
where
44-
S: CommitStore + 'static,
45-
E: EnclaveProtoAPI<S> + 'static,
46-
{
47-
}
48-
4936
impl<E, S> AppService<E, S>
5037
where
5138
S: CommitStore + 'static,

modules/store/src/memory.rs

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,72 @@ use crate::store::TxId;
33
use crate::transaction::{CommitStore, CreatedTx, Tx, TxAccessor};
44
use crate::{KVStore, Result};
55
use std::collections::HashMap;
6+
use std::sync::Mutex;
67

78
// MemStore is only available for testing purposes
89
#[derive(Default, Debug)]
9-
pub struct MemStore {
10+
pub struct MemStore(Mutex<InnerMemStore>);
11+
12+
impl KVStore for MemStore {
13+
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
14+
self.0.lock().unwrap().get(key)
15+
}
16+
17+
fn set(&mut self, key: Vec<u8>, value: Vec<u8>) {
18+
self.0.lock().unwrap().set(key, value)
19+
}
20+
21+
fn remove(&mut self, key: &[u8]) {
22+
self.0.lock().unwrap().remove(key)
23+
}
24+
}
25+
26+
impl TxAccessor for MemStore {
27+
fn run_in_tx<T>(&self, tx_id: TxId, f: impl FnOnce(&dyn KVStore) -> T) -> Result<T> {
28+
self.0.lock().unwrap().run_in_tx(tx_id, f)
29+
}
30+
31+
fn run_in_mut_tx<T>(
32+
&mut self,
33+
tx_id: TxId,
34+
f: impl FnOnce(&mut dyn KVStore) -> T,
35+
) -> Result<T> {
36+
self.0.lock().unwrap().run_in_mut_tx(tx_id, f)
37+
}
38+
}
39+
40+
impl CommitStore for MemStore {
41+
type Tx = MemTx;
42+
43+
fn create_transaction(
44+
&mut self,
45+
_update_key: Option<crate::transaction::UpdateKey>,
46+
) -> Result<Self::Tx> {
47+
self.0.lock().unwrap().create_transaction(_update_key)
48+
}
49+
50+
fn begin(&mut self, tx: &<Self::Tx as CreatedTx>::PreparedTx) -> Result<()> {
51+
self.0.lock().unwrap().begin(tx)
52+
}
53+
54+
fn commit(&mut self, tx: <Self::Tx as CreatedTx>::PreparedTx) -> Result<()> {
55+
self.0.lock().unwrap().commit(tx)
56+
}
57+
58+
fn rollback(&mut self, tx: <Self::Tx as CreatedTx>::PreparedTx) {
59+
self.0.lock().unwrap().rollback(tx)
60+
}
61+
}
62+
63+
#[derive(Default, Debug)]
64+
pub struct InnerMemStore {
1065
running_tx_exists: bool,
1166
latest_tx_id: TxId,
1267
uncommitted_data: HashMap<Vec<u8>, Option<Vec<u8>>>,
1368
committed_data: HashMap<Vec<u8>, Vec<u8>>,
1469
}
1570

16-
impl KVStore for MemStore {
71+
impl KVStore for InnerMemStore {
1772
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
1873
if self.running_tx_exists {
1974
match self.uncommitted_data.get(key) {
@@ -42,7 +97,7 @@ impl KVStore for MemStore {
4297
}
4398
}
4499

45-
impl TxAccessor for MemStore {
100+
impl TxAccessor for InnerMemStore {
46101
fn run_in_tx<T>(&self, _tx_id: TxId, f: impl FnOnce(&dyn KVStore) -> T) -> Result<T> {
47102
Ok(f(self))
48103
}
@@ -56,7 +111,7 @@ impl TxAccessor for MemStore {
56111
}
57112
}
58113

59-
impl CommitStore for MemStore {
114+
impl CommitStore for InnerMemStore {
60115
type Tx = MemTx;
61116

62117
fn create_transaction(

modules/store/src/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub trait CreatedTx: Tx {
1919
}
2020

2121
/// `CommitStore` is a store that supports transactions
22-
pub trait CommitStore {
22+
pub trait CommitStore: Sync + Send {
2323
type Tx: CreatedTx;
2424

2525
/// `create_transaction` creates a transaction with a given `update_key`

0 commit comments

Comments
 (0)