This may be called from an ISR, in which case we need to defer the close
| 182 | |
| 183 | // This may be called from an ISR, in which case we need to defer the close |
| 184 | bool FileStore::Close() noexcept |
| 185 | { |
| 186 | switch (usageMode) |
| 187 | { |
| 188 | case FileUseMode::free: |
| 189 | if (!inInterrupt()) |
| 190 | { |
| 191 | REPORT_INTERNAL_ERROR; |
| 192 | } |
| 193 | return false; |
| 194 | |
| 195 | case FileUseMode::readOnly: |
| 196 | case FileUseMode::readWrite: |
| 197 | { |
| 198 | const auto flags = IrqSave(); |
| 199 | if (openCount > 1) |
| 200 | { |
| 201 | --openCount; |
| 202 | IrqRestore(flags); |
| 203 | return true; |
| 204 | } |
| 205 | else if (inInterrupt()) |
| 206 | { |
| 207 | closeRequested = true; |
| 208 | IrqRestore(flags); |
| 209 | return true; |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | IrqRestore(flags); |
| 214 | return ForceClose(); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | case FileUseMode::invalidated: |
| 219 | default: |
| 220 | { |
| 221 | const auto flags = IrqSave(); |
| 222 | if (openCount > 1) |
| 223 | { |
| 224 | --openCount; |
| 225 | IrqRestore(flags); |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | #if HAS_MASS_STORAGE || HAS_SBC_INTERFACE |
| 230 | FileWriteBuffer *wb = nullptr; |
| 231 | std::swap(wb, writeBuffer); |
| 232 | IrqRestore(flags); |
| 233 | if (wb != nullptr) |
| 234 | { |
| 235 | MassStorage::ReleaseWriteBuffer(wb); |
| 236 | } |
| 237 | #endif |
| 238 | usageMode = FileUseMode::free; |
| 239 | } |
| 240 | return true; |
| 241 | } |
no outgoing calls
no test coverage detected