Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
waiter_state.h
Go to the documentation of this file.
1// Copyright 2026 The Action Engine Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef THREAD_FIBER_CHANNEL_WAITER_STATE_H_
16#define THREAD_FIBER_CHANNEL_WAITER_STATE_H_
17
18#include "thread/cases.h"
19
20namespace thread::internal {
21// A struct that maintains readers' and writers' queues and provides methods
22// to find matching readers and writers in a coordinated way, i.e. locking
23// the selector mutexes of both case states if a pair is found.
24struct ChannelWaiterState {
25 bool GetMatchingReader(const CaseInSelectClause* absl_nonnull writer,
26 CaseInSelectClause* absl_nonnull* absl_nonnull reader)
27 const ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true, (*reader)->selector->mu,
28 writer->selector->mu);
29 bool GetMatchingWriter(const CaseInSelectClause* absl_nonnull reader,
30 CaseInSelectClause* absl_nonnull* absl_nonnull writer)
31 const ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true, reader->selector->mu,
32 (*writer)->selector->mu);
33
34 // Attempt to find an eligible queued writer.
35 bool GetWaitingWriter(CaseInSelectClause* absl_nonnull* absl_nonnull writer)
36 const ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(true, (*writer)->selector->mu);
37
38 // Unlock (and mark selected) the passed reader/writer respectively.
39 // REQUIRES: selector mutex is held, picked == kNonePicked
40 void UnlockAndReleaseReader(CaseInSelectClause* absl_nonnull reader)
41 ABSL_UNLOCK_FUNCTION(reader->selector->mu);
42 void UnlockAndReleaseWriter(CaseInSelectClause* absl_nonnull writer)
43 ABSL_UNLOCK_FUNCTION(writer->selector->mu);
44
45 // Releases all waiting readers. Unselected readers are picked and marked to
46 // return that this channel was closed.
47 void CloseAndReleaseReaders();
48
49 internal::CaseInSelectClause* absl_nullable readers = nullptr;
50 internal::CaseInSelectClause* absl_nullable writers = nullptr;
51};
52} // namespace thread::internal
53
54#endif // THREAD_FIBER_CHANNEL_WAITER_STATE_H_
Definition channel.h:29