/[suikacvs]/webroot/swe/lib/SWE/DB/Lock.pm
Suika

Diff of /webroot/swe/lib/SWE/DB/Lock.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by wakaba, Sun Jul 12 10:57:24 2009 UTC revision 1.5 by wakaba, Mon Sep 21 09:10:40 2009 UTC
# Line 7  my $LockTypes = [qw/ Line 7  my $LockTypes = [qw/
7  /];  /];
8    ## If you are locking for Graph, then you cannot lock for Global, but    ## If you are locking for Graph, then you cannot lock for Global, but
9    ## still you can lock for ID.    ## still you can lock for ID.
10      ##
11      ## In addition, if you are locking for an ID, then you can't lock
12      ## for another ID.
13      ##
14      ## XXX Maybe we should get rid of IDs and Name locks because they
15      ## conflict with ID and Names locks respectively.  Additionally,
16      ## maybe we should remove Global lock as well.
17    
18    ## idgen is currently controled by Names lock.    ## idgen is currently controled by Names lock.
19    
# Line 33  sub check_lockability ($) { Line 40  sub check_lockability ($) {
40        
41    my $self_lt = $self->lock_type;    my $self_lt = $self->lock_type;
42    for my $lt (@$LockTypes) {    for my $lt (@$LockTypes) {
43      if ($self_lt eq $lt) {      if ($CurrentlyLocking->{$lt}) {
       last;  
     } elsif ($CurrentlyLocking->{$lt}) {  
44        die qq[$0: It is currently locking for "$lt" so that it cannot be locked for the "$self_lt"];        die qq[$0: It is currently locking for "$lt" so that it cannot be locked for the "$self_lt"];
45        } elsif ($self_lt eq $lt) {
46          last;
47      }      }
48    }    }
49    
# Line 48  sub lock ($) { Line 55  sub lock ($) {
55    
56    $self->check_lockability;    $self->check_lockability;
57    $CurrentlyLocking->{$self->lock_type}++;    $CurrentlyLocking->{$self->lock_type}++;
58  warn "@{[$self->lock_type]} $CurrentlyLocking->{$self->lock_type} $self->{file_name}";  
59    warn "XXX @{[$self->lock_type]} $CurrentlyLocking->{$self->lock_type} $self->{file_name}";
60        
61    open my $file, '>', $self->{file_name} or die "$0: $self->{file_name}: $!";    open my $file, '>', $self->{file_name} or die "$0: $self->{file_name}: $!";
62    flock $file, LOCK_EX;    flock $file, LOCK_EX;

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24