File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
//! Kernel async functionality.
4
4
5
+ use core:: {
6
+ future:: Future ,
7
+ pin:: Pin ,
8
+ task:: { Context , Poll } ,
9
+ } ;
10
+
5
11
#[ cfg( CONFIG_NET ) ]
6
12
pub mod net;
13
+
14
+ /// Yields execution of the current task so that other tasks may execute.
15
+ ///
16
+ /// The task continues to be in a "runnable" state though, so it will eventually run again.
17
+ ///
18
+ /// # Examples
19
+ ///
20
+ /// ```
21
+ /// use kernel::kasync::yield_now;
22
+ ///
23
+ /// async fn example() {
24
+ /// pr_info!("Before yield\n");
25
+ /// yield_now().await;
26
+ /// pr_info!("After yield\n");
27
+ /// }
28
+ /// ```
29
+ pub fn yield_now ( ) -> impl Future < Output = ( ) > {
30
+ struct Yield {
31
+ first_poll : bool ,
32
+ }
33
+
34
+ impl Future for Yield {
35
+ type Output = ( ) ;
36
+
37
+ fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < ( ) > {
38
+ if !self . first_poll {
39
+ Poll :: Ready ( ( ) )
40
+ } else {
41
+ self . first_poll = false ;
42
+ cx. waker ( ) . wake_by_ref ( ) ;
43
+ Poll :: Pending
44
+ }
45
+ }
46
+ }
47
+
48
+ Yield { first_poll : true }
49
+ }
You can’t perform that action at this time.
0 commit comments