// Copyright 2022 The 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. #include <grpc/support/port_platform.h> #include "src/core/lib/event_engine/posix_engine/lockfree_event.h" #include <atomic> #include <cstdint> #include "absl/status/status.h" #include <grpc/support/atm.h> #include <grpc/support/log.h> #include "src/core/lib/event_engine/posix_engine/event_poller.h" #include "src/core/lib/event_engine/posix_engine/posix_engine_closure.h" #include "src/core/lib/gprpp/crash.h" #include "src/core/lib/gprpp/status_helper.h" // 'state' holds the to call when the fd is readable or writable respectively. // It can contain one of the following values: // kClosureReady : The fd has an I/O event of interest but there is no // closure yet to execute // kClosureNotReady : The fd has no I/O event of interest // closure ptr : The closure to be executed when the fd has an I/O // event of interest // shutdown_error | kShutdownBit : // 'shutdown_error' field ORed with kShutdownBit. // This indicates that the fd is shutdown. Since all // memory allocations are word-aligned, the lower two // bits of the shutdown_error pointer are always 0. So // it is safe to OR these with kShutdownBit // Valid state transitions: // <closure ptr> <-----3------ kClosureNotReady -----1-------> kClosureReady // | | ^ | ^ | | // | | | | | | | // | +--------------4----------+ 6 +---------2---------------+ | // | | | // | v | // +-----5-------> [shutdown_error | kShutdownBit] <-------7---------+ // For 1, 4 : See SetReady() function // For 2, 3 : See NotifyOn() function // For 5,6,7: See SetShutdown() function namespace grpc_event_engine { namespace experimental { void LockfreeEvent::InitEvent() { … } void LockfreeEvent::DestroyEvent() { … } void LockfreeEvent::NotifyOn(PosixEngineClosure* closure) { … } bool LockfreeEvent::SetShutdown(absl::Status shutdown_error) { … } void LockfreeEvent::SetReady() { … } } // namespace experimental } // namespace grpc_event_engine