1/**
2 * The thread module provides support for thread creation and management.
3 *
4 * Copyright: Copyright Sean Kelly 2005 - 2012.
5 * License: Distributed under the
6 *      $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
7 *    (See accompanying file LICENSE)
8 * Authors:   Sean Kelly, Walter Bright, Alex R��nne Petersen, Martin Nowak
9 * Source:    $(DRUNTIMESRC core/thread/context.d)
10 */
11
12module core.thread.context;
13
14struct StackContext
15{
16    void* bstack, tstack;
17
18    /// Slot for the EH implementation to keep some state for each stack
19    /// (will be necessary for exception chaining, etc.). Opaque as far as
20    /// we are concerned here.
21    void* ehContext;
22    StackContext* within;
23    StackContext* next, prev;
24}
25
26struct Callable
27{
28    void opAssign(void function() fn) pure nothrow @nogc @safe
29    {
30        () @trusted { m_fn = fn; }();
31        m_type = Call.FN;
32    }
33    void opAssign(void delegate() dg) pure nothrow @nogc @safe
34    {
35        () @trusted { m_dg = dg; }();
36        m_type = Call.DG;
37    }
38    void opCall()
39    {
40        switch (m_type)
41        {
42            case Call.FN:
43                m_fn();
44                break;
45            case Call.DG:
46                m_dg();
47                break;
48            default:
49                break;
50        }
51    }
52private:
53    enum Call
54    {
55        NO,
56        FN,
57        DG
58    }
59    Call m_type = Call.NO;
60    union
61    {
62        void function() m_fn;
63        void delegate() m_dg;
64    }
65}
66