blob: 3ebca75eee66362933ea13b69e4a1f1b2c962ab2 [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/async/dispatcher.h>
#include <lib/async/task.h>
#include <zircon/syscalls.h>
#include <zircon/time.h>
#include <zircon/types.h>
namespace wlan::iwlwifi {
// Internal implementation of a task that runs on an async_dispatcher_t.
class TaskInternal : private async_task_t {
using FuncType = void (*)(void* data);
// Create the task.
explicit TaskInternal(async_dispatcher_t* dispatcher, FuncType func, void* data);
// Delete the task. The task will be cancelled synchronously before deletion.
// Post the task, to be run after `delay`.
zx_status_t Post(zx_duration_t delay);
// Wait for the task to complete. If the task has not been posted, return immediately.
zx_status_t Wait();
// Cancel the task, non-blocking. May return:
// * ZX_OK if the task was cancelled.
// * ZX_ERR_NOT_FOUND if the task was not queued and thus not cancelled.
// * Other errors in other error cases.
zx_status_t Cancel();
// Cancel the task, blocking.
zx_status_t CancelSync();
async_dispatcher_t* const dispatcher_ = nullptr;
FuncType const func_ = nullptr;
void* const data_ = nullptr;
zx_futex_t state_ = 0;
} // namespace wlan::iwlwifi