public Coroutinesin(SET defautSetValue, RES defautResValue) { ResDefautValue = defautResValue; SetDefautValue = defautSetValue; var ptr = GCHandle.ToIntPtr(GCHandle.Alloc(this)); FiberB = RiberStatic.CreateFiberEx(0, 0, 1, fiberproc, ptr); ThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; }
static void unmanaged_fiberproc(IntPtr arg) { GCHandle g = GCHandle.FromIntPtr(arg); Coroutinesin <SET, RES> tmp = g.Target as Coroutinesin <SET, RES>; g.Free(); tmp.ExtIng(); RiberStatic.SwitchToFiber(FiberA); }
public virtual void Dispose() { if (!IsDispose) { IsDispose = true; if (FiberB != IntPtr.Zero) { RiberStatic.DeleteFiber(FiberB); FiberB = IntPtr.Zero; } } state = FiberStateEnum.FiberStopped; }
void initialize_thread() { if (ThreadId != 0 && ThreadId != System.Threading.Thread.CurrentThread.ManagedThreadId) { throw new Exception("The Thread Not Use It"); } if (!thread_is_fiber) { if (FiberA == IntPtr.Zero) { FiberA = RiberStatic.ConvertThreadToFiberEx(0, 1); if (FiberA == IntPtr.Zero) { throw new Exception("not ConvertThreadToFiber"); } } thread_is_fiber = true; } }
static void CorSwitchToFiber(IntPtr fiber) { RiberStatic.SwitchToFiber(fiber); }