# Copyright (c) 1997 Graham Barr <gbarr@pobox.com>. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
use IPC
::SysV
qw(GETNCNT GETZCNT GETVAL SETVAL GETPID GETALL SETALL
IPC_STAT IPC_SET IPC_RMID);
$VERSION = eval $VERSION;
package IPC::Semaphore::stat;
use Class::Struct qw(struct);
struct
'IPC::Semaphore::stat' => [
@_ == 4 || croak
'new ' . __PACKAGE__
. '( KEY, NSEMS, FLAGS )';
my $id = semget($_[0],$_[1],$_[2]);
(semctl($$self,0,IPC_RMID
,0), undef $$self)[0];
@_ == 2 || croak
'$sem->getncnt( SEM )';
my $v = semctl($$self,$sem,GETNCNT
,0);
@_ == 2 || croak
'$sem->getzcnt( SEM )';
my $v = semctl($$self,$sem,GETZCNT
,0);
@_ == 2 || croak
'$sem->getval( SEM )';
my $v = semctl($$self,$sem,GETVAL
,0);
@_ == 2 || croak
'$sem->getpid( SEM )';
my $v = semctl($$self,$sem,GETPID
,0);
@_ >= 4 || croak
'$sem->op( OPLIST )';
croak
'Bad arg count' if @_ % 3;
my $data = pack("s!*",@_);
semctl($$self,0,IPC_STAT
,$data)
IPC
::Semaphore
::stat->new->unpack($data);
croak
'Bad arg count' if @_ % 2;
while(($key,$val) = each %arg);
my $v = semctl($$self,0,IPC_SET
,$ds->pack);
semctl($$self,0,GETALL
,$data)
my $data = pack("s!*",@_);
semctl($$self,0,SETALL
,$data);
@_ == 3 || croak
'$sem->setval( SEM, VAL )';
semctl($$self,$sem,SETVAL
,$val);
IPC::Semaphore - SysV Semaphore IPC object class
use IPC::SysV qw(IPC_PRIVATE S_IRWXU IPC_CREAT);
$sem = new IPC::Semaphore(IPC_PRIVATE, 10, S_IRWXU | IPC_CREAT);
A class providing an object based interface to SysV IPC semaphores.
=item new ( KEY , NSEMS , FLAGS )
Create a new semaphore set associated with C<KEY>. C<NSEMS> is the number
of semaphores in the set. A new set is created if
C<KEY> is equal to C<IPC_PRIVATE>
C<KEY> does not already have a semaphore identifier
associated with it, and C<I<FLAGS> & IPC_CREAT> is true.
On creation of a new semaphore set C<FLAGS> is used to set the
Returns the values of the semaphore set as an array.
Returns the number of processes waiting for the semaphore C<SEM> to
become greater than its current value
Returns the process id of the last process that performed an operation
Returns the current value of the semaphore C<SEM>.
Returns the number of processes waiting for the semaphore C<SEM> to
Returns the system identifier for the semaphore set.
C<OPLIST> is a list of operations to pass to C<semop>. C<OPLIST> is
a concatenation of smaller lists, each which has three values. The
first is the semaphore number, the second is the operation and the last
is a flags value. See L<semop> for more details. For example
Remove and destroy the semaphore set from the system.
=item set ( NAME => VALUE [, NAME => VALUE ...] )
C<set> will set the following values of the C<stat> structure associated
mode (only the permission bits)
C<set> accepts either a stat object, as returned by the C<stat> method,
or a list of I<name>-I<value> pairs.
Sets all values in the semaphore set to those given on the C<VALUES> list.
C<VALUES> must contain the correct number of values.
=item setval ( N , VALUE )
Set the C<N>th value in the semaphore set to C<VALUE>
Returns an object of type C<IPC::Semaphore::stat> which is a sub-class of
C<Class::Struct>. It provides the following fields. For a description
of these fields see your system documentation.
L<IPC::SysV> L<Class::Struct> L<semget> L<semctl> L<semop>
Graham Barr <gbarr@pobox.com>
Copyright (c) 1997 Graham Barr. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.