Mistake on this page?
Report an issue in GitHub or email us
AsyncOp.h
1 /*
2  * Copyright (c) 2018-2019, Arm Limited and affiliates.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef MBED_ASYNC_OP_H
19 #define MBED_ASYNC_OP_H
20 
21 #include "Mutex.h"
22 #include "Semaphore.h"
23 #include "Callback.h"
24 
25 #include "LinkEntry.h"
26 #include "OperationListBase.h"
27 
28 class AsyncOp: public LinkEntry {
29 public:
30 
31  /**
32  * Construct a new AsyncOp object
33  */
34  AsyncOp();
35 
36  /**
37  * Construct a new AsyncOp object
38  *
39  * @param callback Completion callback
40  */
42 
43  /**
44  * Cleanup resources used by this AsyncOp
45  */
46  virtual ~AsyncOp();
47 
48  /**
49  * Wait for this asynchronous operation to complete
50  *
51  * If the timeout expires then this asynchronous operation is
52  * aborted and the timeout flag is set.
53  *
54  * @note - the host object's lock MUST NOT be held when this call is made
55  */
56  void wait(rtos::Mutex *host_mutex, uint32_t milliseconds = osWaitForever);
57 
58  /**
59  * Abort this asynchronous operation
60  *
61  * This function has no effect if the operation is complete. Otherwise
62  * the aborted flag is set.
63  *
64  * @note - the host object's lock MUST be held when this call is made
65  */
66  void abort();
67 
68  /**
69  * Check if this operation timed out
70  *
71  * @return true if this operation timed out, false otherwise
72  */
73  bool timeout();
74 
75  /**
76  * Check if this operation was aborted
77  *
78  * @return true if this operation was aborted, false otherwise
79  */
80  bool aborted();
81 
82 protected:
83 
84  /**
85  * Callback indicating that something changed
86  *
87  * @return true if finished false if not
88  */
89  virtual bool process() = 0;
90 
91  /**
92  * Callback indicating that this event finished
93  */
94  virtual void complete();
95 
96 private:
97  friend class OperationListBase;
98 
99  mbed::Callback<void()> _callback;
100  OperationListBase *_list;
101  rtos::Semaphore *_wait;
102  bool _aborted;
103  bool _timeout;
104 
105  void _abort(bool timeout);
106 
107  static void _host_lock(rtos::Mutex *host_mutex);
108 
109  static void _host_unlock(rtos::Mutex *host_mutex);
110 };
111 
112 #endif
virtual bool process()=0
Callback indicating that something changed.
virtual ~AsyncOp()
Cleanup resources used by this AsyncOp.
The Semaphore class is used to manage and protect access to a set of shared resources.
Definition: Semaphore.h:46
void wait(rtos::Mutex *host_mutex, uint32_t milliseconds=osWaitForever)
Wait for this asynchronous operation to complete.
bool timeout()
Check if this operation timed out.
bool aborted()
Check if this operation was aborted.
Callback< R()> callback(R(*func)()=0)
Create a callback class with type inferred from the arguments.
Definition: Callback.h:3848
virtual void complete()
Callback indicating that this event finished.
AsyncOp()
Construct a new AsyncOp object.
The Mutex class is used to synchronize the execution of threads.
Definition: Mutex.h:66
void abort()
Abort this asynchronous operation.
Definition: LinkEntry.h:23
Callback class based on template specialization.
Definition: Callback.h:39
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.