6 $SIG{__DIE__} = 'cleanup';
12 unless($Config{'d_semget'} eq 'define' &&
13 $Config{'d_semctl'} eq 'define') {
21 use IPC::SysV qw(IPC_PRIVATE IPC_CREAT IPC_STAT IPC_RMID
23 S_IRWXU S_IRWXG S_IRWXO);
27 my $sem = semget(IPC_PRIVATE, 10, S_IRWXU | S_IRWXG | S_IRWXO | IPC_CREAT);
28 # Very first time called after machine is booted value may be 0
29 die "semget: $!\n" unless defined($sem) && $sem >= 0;
34 semctl($sem,0,IPC_STAT,$data) or print "not ";
37 print "not " unless length($data);
42 # Find the pack/unpack template capable of handling native C shorts.
44 if ($Config{shortsize} == 2) {
46 } elsif ($Config{shortsize} == 4) {
48 } elsif ($Config{shortsize} == 8) {
49 foreach my $t (qw(i q)) { # Try quad last because not supported everywhere.
50 # We could trap the unsupported quad template with eval
51 # but if we get this far we should have quad support anyway.
52 if (length(pack($t, 0)) == 8) {
59 die "$0: cannot pack native shorts\n" unless defined $template;
65 semctl($sem,0,SETALL,pack($template,(0) x $nsem)) or print "not ";
69 semctl($sem,0,GETALL,$data) or print "not ";
72 print "not " unless length($data) == length(pack($template,(0) x $nsem));
75 my @data = unpack($template,$data);
77 my $adata = "0" x $nsem;
79 print "not " unless @data == $nsem and join("",@data) eq $adata;
85 semctl($sem,0,SETALL,pack($template,@data)) or print "not ";
89 semctl($sem,0,GETALL,$data) or print "not ";
92 @data = unpack($template,$data);
94 my $bdata = "0" x $poke . "1" . "0" x ($nsem-$poke-1);
96 print "not " unless join("",@data) eq $bdata;
99 sub cleanup { semctl($sem,0,IPC_RMID,undef) if defined $sem }