Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple spinlock crate based on the abstractions provided by the `lock_api` crate.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

rust-osdev/spinning_top

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image of a spinning top

Build StatusDocs.rs Badge

A simple spinlock crate based on the abstractions provided bylock_api.

Example

First, import the crate as a dependency in yourCargo.toml. Then you can use it in the following way:

use spinning_top::Spinlock;fnmain(){// Wrap some data in a spinlocklet data =String::from("Hello");let spinlock =Spinlock::new(data);make_uppercase(&spinlock);// only pass a shared reference// We have ownership of the spinlock, so we can extract the data without locking// Note: this consumes the spinlocklet data = spinlock.into_inner();assert_eq!(data.as_str(),"HELLO");}fnmake_uppercase(spinlock:&Spinlock<String>){// Lock the spinlock to get a mutable reference to the dataletmut locked_data = spinlock.lock();assert_eq!(locked_data.as_str(),"Hello");    locked_data.make_ascii_uppercase();// the lock is automatically freed at the end of the scope}

Spinlock::new is aconst function. This makes theSpinlock typeusable in statics:

use spinning_top::Spinlock;staticDATA:Spinlock<u32> =Spinlock::new(0);fnmain(){letmut data =DATA.lock();*data +=1;assert_eq!(*data,1);}

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

A simple spinlock crate based on the abstractions provided by the `lock_api` crate.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors5

Languages


[8]ページ先頭

©2009-2025 Movatter.jp