Skip to content

Commit 271d17d

Browse files
bors[bot]adamgreig
andauthored
Merge #35
35: Prepare v1.0.0 r=jonas-schievink a=adamgreig I'm opening this PR so we can move discussions forward around v1; I am very happy to have some changes or more feedback before we go ahead with this. Essentially, this crate is now just `CriticalSection` and `Mutex`, which are widely used and probably won't change without becoming something totally new (e.g. the new mutex-trait crate). There are some known issues (especially CSs don't disable NMI or HardFault) which perhaps could be documented and understood better, but I think are all platform-specific (cortex-m). In this PR: * Remove `StaticResource`: it's not been released in any published version so hasn't been proven yet; we could re-add it in a later release or separate crate * Remove `deny(warnings)` and instead deny them in CI * Update version to 1.0.0 We'll still want to close off #26. Otherwise I think everything from #22 is covered. Co-authored-by: Adam Greig <[email protected]>
2 parents 28bad8e + 828da45 commit 271d17d

File tree

4 files changed

+11
-55
lines changed

4 files changed

+11
-55
lines changed

CHANGELOG.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8-
### Added
9-
10-
- Added the `StaticResource` trait.
8+
## [v1.0.0] - 2020-06-23
119

1210
### Breaking Changes
1311

@@ -77,7 +75,8 @@ YANKED due to a soundness issue: see v0.2.1 for details
7775

7876
- Initial release
7977

80-
[Unreleased]: https://github.com/japaric/bare-metal/compare/v0.2.5...HEAD
78+
[Unreleased]: https://github.com/japaric/bare-metal/compare/v1.0.0...HEAD
79+
[v1.0.0]: https://github.com/japaric/bare-metal/compare/v0.2.5...v1.0.0
8180
[v0.2.5]: https://github.com/japaric/bare-metal/compare/v0.2.4...v0.2.5
8281
[v0.2.4]: https://github.com/japaric/bare-metal/compare/v0.2.3...v0.2.4
8382
[v0.2.3]: https://github.com/japaric/bare-metal/compare/v0.2.2...v0.2.3

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ keywords = ["bare-metal", "register", "peripheral", "interrupt"]
77
license = "MIT OR Apache-2.0"
88
name = "bare-metal"
99
repository = "https://github.com/rust-embedded/bare-metal"
10-
version = "0.2.5"
10+
version = "1.0.0"
11+
readme = "README.md"

ci/script.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
set -euxo pipefail
22

3+
export RUSTFLAGS="-D warnings"
4+
35
main() {
46
cargo check --target $TARGET
57

src/lib.rs

+4-50
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Abstractions common to bare metal systems.
22
33
#![deny(missing_docs)]
4-
#![deny(warnings)]
54
#![no_std]
5+
#![doc(html_root_url="https://docs.rs/bare-metal/1.0")]
66

77
use core::cell::UnsafeCell;
88
use core::marker::PhantomData;
@@ -12,7 +12,7 @@ use core::marker::PhantomData;
1212
/// An instance of this type indicates that the current core is executing code within a critical
1313
/// section. This means that no interrupts must be enabled that could preempt the currently running
1414
/// code.
15-
#[derive(Clone, Copy)]
15+
#[derive(Clone, Copy, Debug)]
1616
pub struct CriticalSection<'cs> {
1717
_0: PhantomData<&'cs ()>,
1818
}
@@ -47,6 +47,7 @@ impl<'cs> CriticalSection<'cs> {
4747
/// **This Mutex is only safe on single-core systems.**
4848
///
4949
/// On multi-core systems, a `CriticalSection` **is not sufficient** to ensure exclusive access.
50+
#[derive(Debug)]
5051
pub struct Mutex<T> {
5152
inner: UnsafeCell<T>,
5253
}
@@ -92,52 +93,5 @@ unsafe impl<T> Sync for Mutex<T> where T: Send {}
9293
/// }
9394
/// ```
9495
#[allow(dead_code)]
96+
#[doc(hidden)]
9597
const GH_6: () = ();
96-
97-
/// Trait for static (singleton) resources with managed ownership.
98-
///
99-
/// This trait allows application code and libraries to take ownership of resources that exist once
100-
/// on every core, or once on the entire system.
101-
///
102-
/// # Safety
103-
///
104-
/// In order to safely implement this trait, the implementor must ensure that:
105-
/// - A call to `take()` or `steal()` atomically ensures that no further call to `take()` will
106-
/// succeed. This is commonly accomplished by using a static `AtomicBool` variable and a
107-
/// compare-and-swap operation or a critical section.
108-
/// - It is impossible to link multiple crates containing the synchronization state together. This
109-
/// is usually accomplished by defining a well-known [`links = "..."`][links] key in the
110-
/// `Cargo.toml`.
111-
///
112-
/// [links]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
113-
pub unsafe trait StaticResource: Sized {
114-
/// Obtains ownership of this resource singleton and makes it unavailable to future callers of
115-
/// `take()`.
116-
///
117-
/// If `take()` or `steal()` have been called before, this returns `None`.
118-
fn take() -> Option<Self>;
119-
120-
/// Obtains an instance of this resource and makes all future calls to `take()` return `None`.
121-
///
122-
/// This will not check if `take()` or `steal()` have already been called before. It is the
123-
/// caller's responsibility to use the returned instance in a safe way that does not conflict
124-
/// with other instances.
125-
///
126-
/// This function is intended to be used when it is statically known that the resource is still
127-
/// available (for example, in generated code that runs immediately after reset). It generally
128-
/// has lower cost than `take().unwrap()`.
129-
unsafe fn steal() -> Self;
130-
131-
/// Unsafely obtains an instance of this resource.
132-
///
133-
/// This will not check if `take()` or `steal()` have already been called before. It is the
134-
/// caller's responsibility to use the returned instance in a safe way that does not conflict
135-
/// with other instances.
136-
///
137-
/// Contrary to `steal()`, `conjure()` will *not* make future calls to `take()` return `None`.
138-
///
139-
/// This function can be used to perform operations on a resource, ignoring any current
140-
/// ownership of the resource. The safety of this depends on the specific resource, and on the
141-
/// operations performed.
142-
unsafe fn conjure() -> Self;
143-
}

0 commit comments

Comments
 (0)