src/fiber_thread.cpp
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 23:20:33 +0300
changeset 11184 88c967f1422b
parent 10866 242436c016b8
permissions -rw-r--r--
add an empty bin/cache dir
10175
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
     1
/* $Id$ */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
     2
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
     3
/** @file fiber_thread.cpp ThreadObject implementation of Fiber. */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
     4
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
     5
#include "stdafx.h"
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
     6
#include "fiber.hpp"
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
     7
#include "thread.h"
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
     8
#include <stdlib.h>
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
     9
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    10
class Fiber_Thread : public Fiber {
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    11
private:
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    12
	ThreadObject *m_thread;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    13
	FiberFunc m_proc;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    14
	void *m_param;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    15
	bool m_attached;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    16
	ThreadSemaphore *m_sem;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    17
	bool m_kill;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    18
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    19
	static Fiber_Thread *s_current;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    20
	static Fiber_Thread *s_main;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    21
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    22
public:
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    23
	/**
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    24
	 * Create a ThreadObject fiber and start it, calling proc(param).
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    25
	 */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    26
	Fiber_Thread(FiberFunc proc, void *param) :
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    27
		m_thread(NULL),
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    28
		m_proc(proc),
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    29
		m_param(param),
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    30
		m_attached(false),
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    31
		m_kill(false)
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    32
	{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    33
		this->m_sem = ThreadSemaphore::New();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    34
		/* Create a thread and start stFiberProc */
10866
242436c016b8 (svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents: 10861
diff changeset
    35
		this->m_thread = ThreadObject::New(&stFiberProc, this);
10175
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    36
	}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    37
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    38
	/**
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    39
	 * Create a ThreadObject fiber and attach current thread to it.
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    40
	 */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    41
	Fiber_Thread(void *param) :
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    42
		m_thread(NULL),
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    43
		m_proc(NULL),
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    44
		m_param(param),
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    45
		m_attached(true),
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    46
		m_kill(false)
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    47
	{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    48
		this->m_sem = ThreadSemaphore::New();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    49
		/* Attach the current thread to this Fiber */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    50
		this->m_thread = ThreadObject::AttachCurrent();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    51
		/* We are the current thread */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    52
		if (s_current == NULL) s_current = this;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    53
		if (s_main == NULL) s_main = this;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    54
	}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    55
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    56
	~Fiber_Thread()
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    57
	{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    58
		/* Remove the thread if needed */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    59
		if (this->m_thread != NULL) {
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    60
			assert(this->m_attached || !this->m_thread->IsRunning());
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    61
			delete this->m_thread;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    62
		}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    63
		/* Remove the semaphore */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    64
		delete this->m_sem;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    65
	}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    66
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    67
	/* virtual */ void SwitchToFiber()
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    68
	{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    69
		/* You can't switch to yourself */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    70
		assert(s_current != this);
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    71
		Fiber_Thread *cur = s_current;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    72
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    73
		/* Continue the execution of 'this' Fiber */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    74
		this->m_sem->Set();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    75
		/* Hold the execution of the current Fiber */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    76
		cur->m_sem->Wait();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    77
		if (this->m_kill) {
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    78
			/* If the thread we switched too was killed, join it so it can finish quiting */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    79
			this->m_thread->Join();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    80
		}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    81
		/* If we continue, we are the current thread */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    82
		s_current = cur;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    83
	}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    84
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    85
	/* virtual */ void Exit()
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    86
	{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    87
		/* Kill off our thread */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    88
		this->m_kill = true;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    89
		this->m_thread->Exit();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    90
	}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    91
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    92
	/* virtual */ bool IsRunning()
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    93
	{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    94
		if (this->m_thread == NULL) return false;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    95
		return this->m_thread->IsRunning();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    96
	}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    97
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    98
	/* virtual */ void *GetFiberData()
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
    99
	{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   100
		return this->m_param;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   101
	}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   102
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   103
	static Fiber_Thread *GetCurrentFiber()
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   104
	{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   105
		return s_current;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   106
	}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   107
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   108
private:
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   109
	/**
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   110
	 * First function which is called within the fiber.
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   111
	 */
10860
ae89867701fe (svn r13411) -Codechange: remove the return value from the thread procs because it is never used.
rubidium
parents: 10175
diff changeset
   112
	static void stFiberProc(void *fiber)
10175
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   113
	{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   114
		Fiber_Thread *cur = (Fiber_Thread *)fiber;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   115
		/* Now suspend the thread until we get SwitchToFiber() for the first time */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   116
		cur->m_sem->Wait();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   117
		/* If we continue, we are the current thread */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   118
		s_current = cur;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   119
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   120
		try {
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   121
			cur->m_proc(cur->m_param);
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   122
		} catch (...) {
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   123
			/* Unlock the main thread */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   124
			s_main->m_sem->Set();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   125
			throw;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   126
		}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   127
	}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   128
};
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   129
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   130
/* Initialize the static member of Fiber_Thread */
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   131
/* static */ Fiber_Thread *Fiber_Thread::s_current = NULL;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   132
/* static */ Fiber_Thread *Fiber_Thread::s_main = NULL;
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   133
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   134
#ifndef WIN32
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   135
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   136
/* static */ Fiber *Fiber::New(FiberFunc proc, void *param)
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   137
{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   138
	return new Fiber_Thread(proc, param);
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   139
}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   140
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   141
/* static */ Fiber *Fiber::AttachCurrent(void *param)
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   142
{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   143
	return new Fiber_Thread(param);
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   144
}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   145
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   146
/* static */ void *Fiber::GetCurrentFiberData()
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   147
{
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   148
	return Fiber_Thread::GetCurrentFiber()->GetFiberData();
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   149
}
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   150
1119f6640ee6 (svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
diff changeset
   151
#endif /* WIN32 */