1 |
root |
1.1 |
use ExtUtils::MakeMaker; |
2 |
|
|
|
3 |
root |
1.7 |
use 5.005; |
4 |
root |
1.1 |
|
5 |
root |
1.2 |
use Config; |
6 |
|
|
|
7 |
root |
1.6 |
$|=1; |
8 |
|
|
|
9 |
root |
1.2 |
$DEFINE = ""; |
10 |
|
|
|
11 |
|
|
$DEFINE .= " -DHAVE_MMAP" if $Config{d_mmap} eq "define" && $Config{d_munmap} eq "define"; |
12 |
|
|
|
13 |
|
|
if ($^O =~ /windows/) { |
14 |
root |
1.3 |
$DEFINE = " -DCORO_LOOSE"; |
15 |
root |
1.4 |
} elsif ($^O =~ /linux/) { |
16 |
|
|
$iface = "l"; |
17 |
root |
1.2 |
} elsif (-e "/usr/include/ucontext.h") { |
18 |
root |
1.3 |
$iface = "u"; |
19 |
root |
1.2 |
} else { |
20 |
root |
1.3 |
$iface = "s"; |
21 |
root |
1.2 |
} |
22 |
|
|
|
23 |
root |
1.6 |
print <<EOF; |
24 |
|
|
|
25 |
|
|
Version 0.12 introduced experimental C context sharing. This makes it |
26 |
|
|
possible to share the C stack and context between many coroutines, |
27 |
|
|
resulting in memory savings and slight speed gains, at the cost of |
28 |
|
|
potential segfaults. On my Linux/x86 machine this decreased the size of |
29 |
|
|
a new coroutine from 9k to 5k, the savings are much more apparent on |
30 |
|
|
machines without mmap or good memory management. This algorithm relies |
31 |
|
|
on the non-fact that the same machine stack pointer indicates the same |
32 |
|
|
function call nesting level, which usually works good enough but might |
33 |
|
|
fail... |
34 |
|
|
|
35 |
|
|
Disabling this option is save, as it only increases memory consumption. |
36 |
|
|
|
37 |
|
|
EOF |
38 |
|
|
|
39 |
|
|
print "Do you want to enable experimental context sharing (y/n) [n]? "; |
40 |
|
|
|
41 |
|
|
if (<> =~ /^\s*y/i) { |
42 |
|
|
print "\nExperimental context sharing enabled.\n\n"; |
43 |
|
|
$DEFINE .= " -DCORO_LAZY_STACK"; |
44 |
|
|
} |
45 |
|
|
|
46 |
root |
1.3 |
if ($iface) { |
47 |
|
|
print <<EOF; |
48 |
root |
1.2 |
|
49 |
root |
1.3 |
Coro has the option of using two different ways to implement coroutines |
50 |
root |
1.4 |
at the C level: |
51 |
root |
1.3 |
|
52 |
root |
1.4 |
u The unix ucontext functions are newer and not implemented in older |
53 |
|
|
unices (or broken libc's like glibc-2.2.2 and below). They allow very |
54 |
|
|
fast coroutine creation and fast switching, and, most importantly, are |
55 |
|
|
very stable. |
56 |
|
|
|
57 |
|
|
s If the ucontext functions are not working or you don't want |
58 |
|
|
to use them for other reasons you can try a workaround using |
59 |
|
|
setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine |
60 |
|
|
creation is rather slow, but switching is very fast as well (often much |
61 |
|
|
faster than with the ucontext functions). Unfortunately, glibc-2.1 and |
62 |
|
|
below don't even feature a working sigaltstack. |
63 |
|
|
|
64 |
|
|
l Older GNU/Linux systems (glibc-2.1 and below) need this hack. Since it is |
65 |
root |
1.6 |
very linux-specific it is also quite fast for newer versions; when it works, |
66 |
|
|
that is... |
67 |
root |
1.2 |
|
68 |
|
|
EOF |
69 |
root |
1.3 |
|
70 |
|
|
retry: |
71 |
root |
1.4 |
print "Use which implementation (s, u, l) [$iface]? "; |
72 |
root |
1.3 |
my $r = <>; |
73 |
|
|
$iface = lc $1 if $r =~ /(\S)/; |
74 |
|
|
|
75 |
|
|
if ($iface eq "u") { |
76 |
|
|
$DEFINE .= " -DCORO_UCONTEXT"; |
77 |
|
|
print "\nUsing ucontext implementation\n\n"; |
78 |
|
|
} elsif ($iface eq "s") { |
79 |
|
|
$DEFINE .= " -DCORO_SJLJ"; |
80 |
|
|
print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n"; |
81 |
root |
1.4 |
} elsif ($iface eq "l") { |
82 |
|
|
$DEFINE .= " -DCORO_LINUX"; |
83 |
|
|
print "\nUsing linux-specific implementation\n\n"; |
84 |
root |
1.3 |
} else { |
85 |
|
|
print "\nUnknown implementation \"$iface\"\n"; |
86 |
|
|
goto retry; |
87 |
|
|
} |
88 |
|
|
} else { |
89 |
|
|
print "\nUsing microsoft coroutine implementation\n\n"; |
90 |
|
|
} |
91 |
root |
1.2 |
|
92 |
root |
1.1 |
WriteMakefile( |
93 |
root |
1.2 |
NAME => "Coro::State", |
94 |
|
|
VERSION_FROM => "State.pm", |
95 |
|
|
DEFINE => $DEFINE, |
96 |
|
|
DIR => [], |
97 |
root |
1.1 |
); |
98 |
root |
1.2 |
|
99 |
|
|
|
100 |
root |
1.1 |
|