File-BasicFlock

 view release on metacpan or  search on metacpan

lib/File/BasicFlock.pm  view on Meta::CPAN

			delete $locks{$file};
			my $f = $lockHandle{$file};
			close($f);
			delete $lockHandle{$file};
			delete $shared{$file};
		}
		return 0;
	}
	croak "flock $f $flags: $!";
}

sub unlock
{
	my ($file) = @_;

	croak "no lock on $file" unless exists $locks{$file};

	delete $locks{$file};
	my $f = $lockHandle{$file};
	delete $lockHandle{$file};

	return 0 unless defined $f;

	print " $$) " if $debug;
	flock($f, LOCK_UN)
		or croak "flock $f UN: $!";

	close($f);
	return 1;
}

END {
	my $f;
	for $f (keys %locks) {
		&unlock($f);
	}
}

__DATA__

=head1 NAME

 File::BasicFlock - file locking with flock

=head1 SYNOPSIS

 use File::BasicFlock;

 lock($filename);

 lock($filename, 'shared');

 lock($filename, undef, 'nonblocking');

 lock($filename, 'shared', 'nonblocking');

 unlock($filename);

=head1 DESCRIPTION

Lock files using the flock() call.  The file to be locked must 
already exist.  This is a very thing interface.

=head1 AUTHOR

David Muir Sharnoff, <muir@idiom.com>




( run in 0.406 second using v1.01-cache-2.11-cpan-df04353d9ac )