1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright The Pit Project Owners. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Please see https://github.com/openpitkit and the OWNERS file for details.
//! Single-threaded, no-synchronization locking policy.
use PhantomData;
use crate;
use crate;
/// Locking policy factory that performs **no synchronization** at all.
///
/// A [`Storage`](crate::storage::Storage) configured with `NoLocking`
/// has zero runtime synchronization overhead but is not thread-safe: it
/// is `!Send` and `!Sync`. The Rust type system enforces single-threaded
/// use.
///
/// # Aliasing safety
///
/// The closure-based access methods on
/// [`Storage`](crate::storage::Storage) ensure that references handed to
/// the caller never escape the call that produced them. Read-from-read
/// re-entry is allowed because it creates only shared references. Any
/// re-entry path involving a write hold is detected by `Storage` in
/// debug builds and panics with a clear message; release builds skip the
/// check and pay nothing extra.
///
/// Use this when the storage lives entirely on the stack of one thread
/// or behind an external synchronization primitive of the caller's
/// choosing.
///
/// # Examples
///
/// ```
/// use openpit::Engine;
///
/// let builder = Engine::builder::<(), (), ()>().no_sync();
/// let storage = builder.storage_builder().create_for_bound_key::<u32, String>();
/// storage.with_mut(1, || "hello".to_string(), |entry, is_new| {
/// assert!(is_new);
/// entry.push_str(", world");
/// });
/// assert_eq!(
/// storage.with(&1, |v| v.clone()),
/// Some("hello, world".to_string()),
/// );
/// ```
;
/// Concrete no-op policy installed in storages built from
/// [`NoLocking`].
///
/// Held privately by the storage; users never name it directly. Not
/// re-exported from the crate; name it via the associated type if
/// needed: `<NoLocking as LockingPolicyFactory>::Policy`.
// SAFETY: every locking method is a no-op. The storage that owns this
// policy is `!Sync` and `!Send` because of the `NotThreadSafe` marker,
// so the Rust type system guarantees that no two threads ever observe the
// same storage through this policy. Each method returns a no-op guard,
// matching the no-synchronization contract.
unsafe