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 =~ /win32/i or $^O =~ /cygwin/) { |
14 |
$DEFINE = " -DCORO_LOOSE"; |
15 |
} elsif ($^O =~ /irix/) { |
16 |
$iface = "i"; |
17 |
} elsif ($^O =~ /linux/) { |
18 |
$iface = "l"; |
19 |
} elsif ($^O =~ /solaris/) { |
20 |
$iface = "s"; |
21 |
} elsif (-e "/usr/include/ucontext.h") { |
22 |
$iface = "u"; |
23 |
} else { |
24 |
$iface = "s"; |
25 |
} |
26 |
|
27 |
print <<EOF; |
28 |
|
29 |
Version 0.12 introduced experimental C context sharing. This makes it |
30 |
possible to share the C stack and context between many coroutines, |
31 |
resulting in memory savings and slight speed gains, at the cost of |
32 |
potential segfaults (especially with exception handling). On my Linux/x86 |
33 |
machine this decreased the size of a new coroutine from 9k to 5k, the |
34 |
savings are much more apparent on machines without mmap or good memory |
35 |
management. This algorithm relies on the non-fact that the same machine |
36 |
stack pointer indicates the same function call nesting level, which |
37 |
usually works good enough but might fail... |
38 |
|
39 |
The default (disabled) is safe, as it only increases memory consumption. |
40 |
|
41 |
EOF |
42 |
|
43 |
print "Do you want to enable experimental context sharing (y/n) [n]? "; |
44 |
|
45 |
if (<> =~ /^\s*y/i) { |
46 |
print "\nExperimental context sharing enabled.\n\n"; |
47 |
$DEFINE .= " -DCORO_LAZY_STACK"; |
48 |
} |
49 |
|
50 |
if ($iface) { |
51 |
print <<EOF; |
52 |
|
53 |
Coro can use various ways to implement coroutines at the C level: |
54 |
|
55 |
u The unix ucontext functions are newer and not implemented in older |
56 |
unices (or broken libc's like glibc-2.2.2 and below). They allow very |
57 |
fast coroutine creation and fast switching, and, most importantly, are |
58 |
very stable. |
59 |
|
60 |
s If the ucontext functions are not working or you don't want |
61 |
to use them for other reasons you can try a workaround using |
62 |
setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine |
63 |
creation is rather slow, but switching is very fast as well (often much |
64 |
faster than with the ucontext functions). Unfortunately, glibc-2.1 and |
65 |
below don't even feature a working sigaltstack. |
66 |
|
67 |
l Older GNU/Linux systems (glibc-2.1 and below) need this hack. Since it is |
68 |
very linux-specific it is also quite fast for newer versions; when it |
69 |
works, that is... |
70 |
|
71 |
i IRIX. For some reason, SGI really does not like to follow the unix |
72 |
standard (does that surprise you?), so this workaround might be needed |
73 |
(it's fast), although s and u should also work now. |
74 |
|
75 |
EOF |
76 |
|
77 |
retry: |
78 |
print "Use which implementation,\n", |
79 |
"<s>etjmp/longjump, <u>context, <i>rix or <l>inux [$iface]? "; |
80 |
|
81 |
my $r = <>; |
82 |
$iface = lc $1 if $r =~ /(\S)/; |
83 |
|
84 |
if ($iface eq "u") { |
85 |
$DEFINE .= " -DCORO_UCONTEXT"; |
86 |
print "\nUsing ucontext implementation\n\n"; |
87 |
conftest("TEST_makecontext"); |
88 |
} elsif ($iface eq "s") { |
89 |
$DEFINE .= " -DCORO_SJLJ"; |
90 |
print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n"; |
91 |
conftest("TEST_sigaltstack"); |
92 |
} elsif ($iface eq "l") { |
93 |
$DEFINE .= " -DCORO_LINUX"; |
94 |
print "\nUsing linux-specific implementation\n\n"; |
95 |
} elsif ($iface eq "i") { |
96 |
$DEFINE .= " -DCORO_IRIX"; |
97 |
print "\nUsing irix-specific implementation\n\n"; |
98 |
} else { |
99 |
print "\nUnknown implementation \"$iface\"\n"; |
100 |
goto retry; |
101 |
} |
102 |
} else { |
103 |
print "\nUsing microsoft compatible coroutines\n\n"; |
104 |
} |
105 |
|
106 |
WriteMakefile( |
107 |
NAME => "Coro::State", |
108 |
VERSION_FROM => "State.pm", |
109 |
DEFINE => $DEFINE, |
110 |
DIR => [], |
111 |
PM => { |
112 |
'State.pm' => '$(INST_LIBDIR)/State.pm', |
113 |
|
114 |
'MakeMaker.pm' => '$(INST_LIBDIR)/MakeMaker.pm', |
115 |
'CoroAPI.h' => '$(INST_LIBDIR)/CoroAPI.h', |
116 |
|
117 |
'Cont.pm' => '$(INST_LIBDIR)/Cont.pm', |
118 |
|
119 |
'Specific.pm' => '$(INST_LIBDIR)/Specific.pm', |
120 |
|
121 |
'Timer.pm' => '$(INST_LIBDIR)/Timer.pm', |
122 |
'Signal.pm' => '$(INST_LIBDIR)/Signal.pm', |
123 |
'Channel.pm' => '$(INST_LIBDIR)/Channel.pm', |
124 |
'Semaphore.pm' => '$(INST_LIBDIR)/Semaphore.pm', |
125 |
'SemaphoreSet.pm' => '$(INST_LIBDIR)/SemaphoreSet.pm', |
126 |
'RWLock.pm' => '$(INST_LIBDIR)/RWLock.pm', |
127 |
}, |
128 |
); |
129 |
|
130 |
sub conftest { |
131 |
my $type = shift; |
132 |
|
133 |
print "\nTrying to detect stack growth direction (for $type)\n"; |
134 |
print "You might see some warnings, this should not concern you.\n\n"; |
135 |
system "$Config{cc} $Config{ccflags} -D$type libcoro/conftest.c"; |
136 |
|
137 |
my $res = qx<./a.out>; |
138 |
$res =~ s/\s+$//; |
139 |
my ($sp, $ss) = split /,/, $res; |
140 |
|
141 |
print "\n\n*****************************************************************************\n"; |
142 |
print "If the testsuite fails PLEASE provide the following information\n"; |
143 |
print "to Marc Lehmann <pcg\@goof.com>: operating system name, version,\n"; |
144 |
print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d# |
145 |
print "*****************************************************************************\n\n"; |
146 |
|
147 |
unlink "a.out"; |
148 |
unlink "conftestval"; |
149 |
} |
150 |
|
151 |
|