#include <ucontext-fiber-manager.h>
Public Member Functions | |
UcontextFiberManager () | |
virtual | ~UcontextFiberManager () |
virtual struct Fiber * | Create (void(*callback)(void *), void *context, uint32_t stackSize) |
virtual struct Fiber * | CreateFromCaller (void) |
virtual void | Delete (struct Fiber *fiber) |
virtual uint32_t | GetStackSize (struct Fiber *fiber) const |
virtual void | SetSwitchNotification (void(*fn)(void)) |
virtual void | SwitchTo (struct Fiber *from, const struct Fiber *to) |
![]() | |
virtual | ~FiberManager () |
virtual struct Fiber * | Clone (struct Fiber *fiber) |
Private Member Functions | |
uint8_t * | AllocateStack (uint32_t stackSize) |
uint32_t | CalcStackSize (uint32_t size) |
void | DeallocateStack (uint8_t *buffer, uint32_t stackSize) |
void | SetupSignalHandler (void) |
Static Private Member Functions | |
static void | FreeAlternateSignalStack (void) |
static void | SegfaultHandler (int sig, siginfo_t *si, void *unused) |
static void | Trampoline (int a0, int a1, int a2, int a3) |
Private Attributes | |
void(* | m_notifySwitch )(void) |
Static Private Attributes | |
static void * | g_alternateSignalStack = 0 |
static std::list< unsigned long > | g_guardPages |
Definition at line 10 of file ucontext-fiber-manager.h.
ns3::UcontextFiberManager::UcontextFiberManager | ( | ) |
Definition at line 177 of file ucontext-fiber-manager.cc.
|
virtual |
Definition at line 181 of file ucontext-fiber-manager.cc.
|
private |
Definition at line 131 of file ucontext-fiber-manager.cc.
References CalcStackSize(), errno, g_guardPages, and SetupSignalHandler().
Referenced by Create().
|
private |
Definition at line 112 of file ucontext-fiber-manager.cc.
Referenced by AllocateStack(), and DeallocateStack().
|
readvirtual |
callback | function to use as main loop for the newly-created fiber |
stackSize | size of the stack to allocate for this fiber. |
Implements ns3::FiberManager.
Definition at line 203 of file ucontext-fiber-manager.cc.
References AllocateStack(), ns3::UcontextFiber::context, ns3::UcontextFiber::stack, ns3::UcontextFiber::stackSize, Trampoline(), VALGRIND_STACK_REGISTER, and ns3::UcontextFiber::vgId.
|
readvirtual |
Create a fiber context which can be used as a from argument to the SwitchTo method This method is usually used to create a context which references the main 'normal' thread. i.e., the thread initially managed by the underlying kernel which runs on the kernel-managed stack.
Implements ns3::FiberManager.
Definition at line 236 of file ucontext-fiber-manager.cc.
References ns3::UcontextFiber::stack, and ns3::UcontextFiber::stackSize.
|
private |
Definition at line 159 of file ucontext-fiber-manager.cc.
References CalcStackSize(), errno, and g_guardPages.
Referenced by Delete().
|
virtual |
context | to delete |
Release any ressource associated to this context. Obviously, this method must be called from another context than the one which is being deleted.
Implements ns3::FiberManager.
Definition at line 245 of file ucontext-fiber-manager.cc.
References DeallocateStack(), ns3::UcontextFiber::stack, ns3::UcontextFiber::stackSize, VALGRIND_STACK_DEREGISTER, and ns3::UcontextFiber::vgId.
|
staticprivate |
Definition at line 63 of file ucontext-fiber-manager.cc.
References g_alternateSignalStack.
Referenced by SetupSignalHandler().
|
virtual |
Implements ns3::FiberManager.
Definition at line 272 of file ucontext-fiber-manager.cc.
References ns3::UcontextFiber::stackSize.
|
staticprivate |
Definition at line 38 of file ucontext-fiber-manager.cc.
References g_guardPages.
Referenced by SetupSignalHandler().
|
virtual |
fn | a function which will be invoked whenever SwitchTo is invoked, just before it returns to the destination fiber. |
Implements ns3::FiberManager.
Definition at line 279 of file ucontext-fiber-manager.cc.
References m_notifySwitch.
|
private |
We need to setup an alternate signal stack because the kernel will refuse to deliver a SIGSEGV signal to our process while it is on the stack which triggered this same error. This kind of makes sense so, we cannot blame the kernel for this.
Definition at line 69 of file ucontext-fiber-manager.cc.
References errno, FreeAlternateSignalStack(), g_alternateSignalStack, and SegfaultHandler().
Referenced by AllocateStack().
from | from context |
to | to context |
This function saves the caller's context into the from context and restores the current context from the to context. The first time this function is called, it is usually called with a from set to a context obtained through CreateFromCaller and with a to set to a context obtained through Create.
Implements ns3::FiberManager.
Definition at line 259 of file ucontext-fiber-manager.cc.
References ns3::UcontextFiber::context, and m_notifySwitch.
|
staticprivate |
Definition at line 186 of file ucontext-fiber-manager.cc.
Referenced by Create().
|
staticprivate |
Definition at line 38 of file ucontext-fiber-manager.h.
Referenced by FreeAlternateSignalStack(), and SetupSignalHandler().
|
staticprivate |
Definition at line 39 of file ucontext-fiber-manager.h.
Referenced by AllocateStack(), DeallocateStack(), and SegfaultHandler().
|
private |
Definition at line 37 of file ucontext-fiber-manager.h.
Referenced by SetSwitchNotification(), and SwitchTo().