--- loncom/LONCAPA.pm 2006/06/26 21:19:36 1.8 +++ loncom/LONCAPA.pm 2006/06/27 15:21:28 1.10 @@ -1,7 +1,7 @@ # The LearningOnline Network # Base routines # -# $Id: LONCAPA.pm,v 1.8 2006/06/26 21:19:36 foxr Exp $ +# $Id: LONCAPA.pm,v 1.10 2006/06/27 15:21:28 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -228,9 +228,28 @@ sub _do_hash_untie { { my $sym; + my @pushed_syms; + sub push_locking_hash_tie { + if (!defined($sym)) { + die("Invalid used of push_locking_hash_tie, should only be called after a lock has occurred and before and unlock."); + } + push(@pushed_syms,$sym); + undef($sym); + } + + sub pop_locking_hash_tie { + if (defined($sym)) { + die("Invalid nested used of pop_locking_hash_tie, should only be called after a unlock has occurred."); + } + $sym = pop(@pushed_syms); + } sub _locking_hash_tie { my ($file_prefix,$namespace,$how,$loghead,$what) = @_; + if (defined($sym)) { + die('Nested locking attempted withut proper use of push_locking_hahs_tie, this is unsupportted'); + } + my $lock_type=LOCK_SH; # Are we reading or writing? if ($how eq &GDBM_READER()) { @@ -248,16 +267,22 @@ sub _do_hash_untie { open($sym,">>$file_prefix.db.lock"); } # Do a shared lock - if (!&flock_sym(LOCK_SH)) { return undef; } + if (!&flock_sym(LOCK_SH)) { + return undef; + } # If this is compressed, we will actually need an exclusive lock if (-e "$file_prefix.db.gz") { - if (!&flock_sym(LOCK_EX)) { return undef; } + if (!&flock_sym(LOCK_EX)) { + return undef; + } } } elsif ($how eq &GDBM_WRCREAT()) { # We are writing open($sym,">>$file_prefix.db.lock"); # Writing needs exclusive lock - if (!&flock_sym(LOCK_EX)) { return undef; } + if (!&flock_sym(LOCK_EX)) { + return undef; + } } else { die("Unknown method $how for $file_prefix"); }