GithubHelp home page GithubHelp logo

doytsujin / win64fibers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pushkoff/win64fibers

0.0 1.0 0.0 5 KB

Fibers for win64 without assembler

License: MIT License

C++ 67.74% Shell 23.41% Lua 8.84%

win64fibers's Introduction

Win64 coroutine/fiber without asm

It uses RtlCaptureContext/RtlRestoreContext to switch context.

Usage

#include <stdio.h>
#include <thread>
#include "Fiber.h"

void fn1(void* any)
{
	printf("fn1 start\n");
	Fiber::Yield();
	printf("fn1 end\n");
}

int main()
{
	Fiber::Handle* c1 = Fiber::Spawn(fn1, (void*)1);

	while (Fiber::Active())
	{
		if (Fiber::Update() == false)
			std::this_thread::sleep_for(1s);
	}
	return 0;
}

Api

Handle* Spawn(void(*fn)(void*), void* arg, size_t stackSize = 0)

Creates new fiber -- fn: a pointer to the function to be executed by the fiber -- arg: -- stackSize: desired stack size of fiber. if 0 stack size will have default length (about 28kb).

bool Active()

Returns true, if there is created and not finished fibers.

bool Update();

Get first ready fiber and run it. Returns true if any fiber was runned. Returns false if there is no ready fibers.

void Yield();

Suspends the execution of the current fiber. If fiber in ready state, it will be continued at next Update calls.

Handle* Self();

Returns handle of current fiber.

void Suspend(Handle* fiber);

Set fiber to waitable state. Have no effect up to Yield is called.

void Resume(Handle* fiber);

Set fiber to ready state and add to ready queue. It will be continued at next Update calls.

win64fibers's People

Contributors

pushkoff avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.