src/fiber.hpp
author truebrain
Wed, 02 Apr 2008 10:55:28 +0000
branchnoai
changeset 9859 81621c6ba0e9
child 10429 1b99254f9607
permissions -rw-r--r--
(svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
[NoAI] -Codechange: rewritten ai_threads.cpp, to work with Fiber class. Reduces code duplication, and should fix all the stupid asserts we had with newgames and dying AIs
-NOTE: now my head spins.. 24 hours of working with threads/fibers is bad for health :p Tnx glx for the testing!
/* $Id$ */

/** @file fiber.hpp */

#ifndef FIBER_HPP
#define FIBER_HPP

typedef void (CDECL *FiberFunc)(void *);

class Fiber {
public:
	/**
	 * Switch to this fiber.
	 */
	virtual void SwitchToFiber() = 0;

	/**
	 * Exit a fiber.
	 */
	virtual void Exit() = 0;

	/**
	 * Check if a fiber is running.
	 */
	virtual bool IsRunning() = 0;

	/**
	 * Get the 'param' data of the Fiber.
	 */
	virtual void *GetFiberData() = 0;

	/**
	 * Virtual Destructor to mute warnings.
	 */
	virtual ~Fiber() {};

	/**
	 * Create a new fiber, calling proc(param) when running.
	 */
	static Fiber *New(FiberFunc proc, void *param);

	/**
	 * Attach a current thread to a new fiber.
	 */
	static Fiber *AttachCurrent(void *param);

	/**
	 * Get the 'param' data of the current active Fiber.
	 */
	static void *GetCurrentFiberData();
};

#endif /* FIBER_HPP */