Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
OperationListBase.cpp
00001 /* 00002 * Copyright (c) 2018-2019, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "OperationListBase.h" 00019 #include "AsyncOp.h" 00020 #include "mbed_assert.h" 00021 00022 OperationListBase::OperationListBase() 00023 { 00024 00025 } 00026 00027 OperationListBase::~OperationListBase() 00028 { 00029 remove_all(); 00030 } 00031 00032 bool OperationListBase::empty() 00033 { 00034 return _list.head() == NULL; 00035 } 00036 00037 void OperationListBase::add(AsyncOp *op) 00038 { 00039 bool was_empty = _list.head() == NULL; 00040 op->_list = this; 00041 _list.enqueue(op); 00042 if (was_empty) { 00043 process(); 00044 } 00045 } 00046 00047 void OperationListBase::process() 00048 { 00049 while (true) { 00050 AsyncOp *op = static_cast<AsyncOp *>(_list.head()); 00051 if (op == NULL) { 00052 // List empty, nothing left to do 00053 break; 00054 } 00055 if (!op->process()) { 00056 // Processing is in progress 00057 break; 00058 } 00059 _list.dequeue(); 00060 op->complete(); 00061 } 00062 } 00063 00064 void OperationListBase::remove(AsyncOp *op) 00065 { 00066 bool head = _list.head() == op; 00067 _list.remove(op); 00068 if (head) { 00069 process(); 00070 } 00071 } 00072 00073 AsyncOp *OperationListBase::dequeue_raw() 00074 { 00075 return static_cast<AsyncOp *>(_list.dequeue()); 00076 } 00077 00078 void OperationListBase::remove_all() 00079 { 00080 while (true) { 00081 AsyncOp *op = static_cast<AsyncOp *>(_list.head()); 00082 if (op == NULL) { 00083 // List empty, nothing left to do 00084 break; 00085 } 00086 op->complete(); 00087 } 00088 }
Generated on Tue Jul 12 2022 13:54:40 by
1.7.2