chromium/third_party/grpc/src/src/core/lib/iomgr/closure.h

//
//
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//

#ifndef GRPC_SRC_CORE_LIB_IOMGR_CLOSURE_H
#define GRPC_SRC_CORE_LIB_IOMGR_CLOSURE_H

#include <grpc/support/port_platform.h>

#include <assert.h>
#include <stdbool.h>

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>

#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/mpscq.h"
#include "src/core/lib/iomgr/error.h"

struct grpc_closure;
grpc_closure;

extern grpc_core::DebugOnlyTraceFlag grpc_trace_closure;

grpc_closure_list;

/// gRPC Callback definition.
///
///\param arg Arbitrary input.
///\param error absl::OkStatus() if no error occurred, otherwise some grpc_error
///             describing what went wrong.
///             Error contract: it is not the cb's job to unref this error;
///             the closure scheduler will do that after the cb returns
grpc_iomgr_cb_func;

/// A closure over a grpc_iomgr_cb_func.
struct grpc_closure {};

#ifndef NDEBUG
inline grpc_closure* grpc_closure_init(const char* file, int line,
                                       grpc_closure* closure,
                                       grpc_iomgr_cb_func cb, void* cb_arg) {}

/// Initializes \a closure with \a cb and \a cb_arg. Returns \a closure.
#ifndef NDEBUG
#define GRPC_CLOSURE_INIT(closure, cb, cb_arg, scheduler)
#else
#define GRPC_CLOSURE_INIT
#endif

namespace grpc_core {
template <typename T, void (T::*cb)(grpc_error_handle)>
grpc_closure MakeMemberClosure(T* p, DebugLocation location = DebugLocation()) {}

template <typename T, void (T::*cb)()>
grpc_closure MakeMemberClosure(T* p, DebugLocation location = DebugLocation()) {}

template <typename F>
grpc_closure* NewClosure(F f) {}
}  // namespace grpc_core

namespace closure_impl {

struct wrapped_closure {};
inline void closure_wrapper(void* arg, grpc_error_handle error) {}

}  // namespace closure_impl

#ifndef NDEBUG
inline grpc_closure* grpc_closure_create(const char* file, int line,
                                         grpc_iomgr_cb_func cb, void* cb_arg) {}

// Create a heap allocated closure: try to avoid except for very rare events
#ifndef NDEBUG
#define GRPC_CLOSURE_CREATE(cb, cb_arg, scheduler)
#else
#define GRPC_CLOSURE_CREATE
#endif

#define GRPC_CLOSURE_LIST_INIT

inline void grpc_closure_list_init(grpc_closure_list* closure_list) {}

/// add \a closure to the end of \a list
/// Returns true if \a list becomes non-empty
inline bool grpc_closure_list_append(grpc_closure_list* closure_list,
                                     grpc_closure* closure) {}

/// add \a closure to the end of \a list
/// and set \a closure's result to \a error
/// Returns true if \a list becomes non-empty
inline bool grpc_closure_list_append(grpc_closure_list* closure_list,
                                     grpc_closure* closure,
                                     grpc_error_handle error) {}

/// force all success bits in \a list to false
inline void grpc_closure_list_fail_all(grpc_closure_list* list,
                                       grpc_error_handle forced_failure) {}

/// append all closures from \a src to \a dst and empty \a src.
inline void grpc_closure_list_move(grpc_closure_list* src,
                                   grpc_closure_list* dst) {}

/// return whether \a list is empty.
inline bool grpc_closure_list_empty(grpc_closure_list closure_list) {}

namespace grpc_core {
class Closure {};
}  // namespace grpc_core

#endif  // GRPC_SRC_CORE_LIB_IOMGR_CLOSURE_H