class ControlRegion
Defined at line 58 of file ../../zircon/kernel/lib/control-region/include/lib/control-region.h
ControlRegion is a CPU synchronization tool.
Think of it as a region of a program that is protected by a gate. When the gate is open, CPUs
may freely enter or leave the controlled region. The gate may only be closed when all CPUs are
within the controlled region. The last CPU to enter the region is responsible for closing the
gate. CPUs may not leave the region until the gate is opened by one of them.
Usage:
// An instance shared by all CPUs.
ControlRegion region;
// A managed resource of some kind, shared by all CPUs.
Resource resource;
...
// Called once for each CPU before any other use of the region.
// Be sure to |Unregister| when taking a CPU offline.
region.Register();
...
resource.Use();
if (!region.TryEnter()) {
// We are the last one in, shutdown the resource before closing and entering.
resource.Shutdown();
region.CloseEnter();
}
// Start of the region.
// End of the region.
if (!region.TryLeave()) {
// We are the first leave, we must restore the resource before opening and leaving.
resource.Init();
region.OpenLeave();
}
resource.Use();
Public Methods
void Register ()
Registers a CPU for participation in a control region.
This should be called once for each CPU that may participate.
Defined at line 63 of file ../../zircon/kernel/lib/control-region/include/lib/control-region.h
void Unregister ()
Unregisters a CPU for participation in a control region.
This method should be called before offlining a CPU that had been registered.
Defined at line 74 of file ../../zircon/kernel/lib/control-region/include/lib/control-region.h
bool TryEnter ()
Attempt to enter the region.
Returns true if this CPU has successfully entered and isn't the last one in.
Returns false and sets the state to closing if this CPU is the only remaining CPU outside the
region. This CPU is then obligated to first perform any resource management tasks associated
with this region, and then finish closing the gate and entering by calling |CloseEnter|.
It is an error to call this method with interrupts enabled.
Defined at line 91 of file ../../zircon/kernel/lib/control-region/include/lib/control-region.h
void CloseEnter ()
Close the gate and enter the region. This is intended to be called after a call to |TryEnter|
has returned false and the caller has performed any necessary resource management tasks.
It is an error to call this method with interrupts enabled.
Defined at line 108 of file ../../zircon/kernel/lib/control-region/include/lib/control-region.h
bool TryLeave ()
Attempt to leave the region.
Returns true if this CPU has successfully left the region and there is already at least one CPU
outside the region.
Returns false and sets the state to opening if no other CPUs are outside the region. This CPU
is then obligated to then perform any resource management tasks associated with the region, and
then finish opening the gate and leaving by calling |OpenLeave|.
It is an error to call this method with interrupts enabled.
Note: If another CPU is in the process of opening or closing the gate, this method may spin
(busy-wait) until that other CPU has finished.
Defined at line 129 of file ../../zircon/kernel/lib/control-region/include/lib/control-region.h
void OpenLeave ()
Open the gate and leave the region. This is intended to be called after a call to |TryLeave|
has returned false and the caller has performed any necessary resource management tasks.
It is an error to call this method with interrupts enabled.
Defined at line 175 of file ../../zircon/kernel/lib/control-region/include/lib/control-region.h