src/fiber.hpp
author truebrain
Mon, 30 Jun 2008 21:31:23 +0000
branchnoai
changeset 11111 1b984dab8cec
parent 10455 22c441f5adf9
permissions -rw-r--r--
(svn r13669) [NoAI] -Fix: allow clients only to join non-AI controlled companies in multiplayer
9859
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
     1
/* $Id$ */
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
     2
10455
22c441f5adf9 (svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents: 9859
diff changeset
     3
/** @file fiber.hpp Base for all fiber related classes. */
9859
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
     4
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
     5
#ifndef FIBER_HPP
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
     6
#define FIBER_HPP
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
     7
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
     8
typedef void (CDECL *FiberFunc)(void *);
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
     9
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    10
class Fiber {
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    11
public:
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    12
	/**
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    13
	 * Switch to this fiber.
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    14
	 */
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    15
	virtual void SwitchToFiber() = 0;
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    16
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    17
	/**
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    18
	 * Exit a fiber.
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    19
	 */
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    20
	virtual void Exit() = 0;
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    21
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    22
	/**
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    23
	 * Check if a fiber is running.
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    24
	 */
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    25
	virtual bool IsRunning() = 0;
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    26
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    27
	/**
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    28
	 * Get the 'param' data of the Fiber.
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    29
	 */
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    30
	virtual void *GetFiberData() = 0;
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    31
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    32
	/**
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    33
	 * Virtual Destructor to mute warnings.
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    34
	 */
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    35
	virtual ~Fiber() {};
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    36
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    37
	/**
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    38
	 * Create a new fiber, calling proc(param) when running.
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    39
	 */
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    40
	static Fiber *New(FiberFunc proc, void *param);
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    41
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    42
	/**
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    43
	 * Attach a current thread to a new fiber.
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    44
	 */
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    45
	static Fiber *AttachCurrent(void *param);
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    46
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    47
	/**
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    48
	 * Get the 'param' data of the current active Fiber.
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    49
	 */
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    50
	static void *GetCurrentFiberData();
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    51
};
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    52
81621c6ba0e9 (svn r12538) [NoAI] -Codechange: introducing fiber.hpp, a class to have fibers in your application via either Windows Fibers, or via thread.h
truebrain
parents:
diff changeset
    53
#endif /* FIBER_HPP */