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