[Bio] / Clearinghouse / utils.pm Repository:
ViewVC logotype

Annotation of /Clearinghouse/utils.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : olson 1.1
2 :     #
3 :     # Clearinghouse utility functions.
4 :     #
5 :    
6 :     use strict;
7 :     use base 'Exporter';
8 :    
9 :     use Clearinghouse::ch_database;
10 :    
11 :     our @EXPORT = qw(check_types
12 :     get_lock
13 :     release_lock
14 :     );
15 :    
16 :     sub check_types {
17 :     my ($type) = @_;
18 :     my $db = db_init();
19 :    
20 :     my $ar = $db->SQL(qq(SELECT type FROM types WHERE type = '$type'));
21 :     return @$ar; #length = 0, if no rows
22 :     }
23 :    
24 :    
25 :    
26 :     sub get_lock {
27 :     my ($dbh, $name, $timeout) = @_;
28 :    
29 :     my $sth = $dbh->prepare(q{UPDATE locks set lock = 1 where name = ? and lock = 0}) or die $dbh->errstr;
30 :     my $res = $sth->execute($name);
31 :     while ($sth->rows == 0) {
32 :     if ($timeout-- == 0) {
33 :     die "Lock timout";
34 :     }
35 :     sleep 1;
36 :     my $res = $sth->execute($name);
37 :     }
38 :     }
39 :    
40 :    
41 :     sub release_lock {
42 :     my ($dbh, $name) = @_;
43 :    
44 :     my $sth = $dbh->prepare(q{UPDATE locks set lock = 0 where name = ?}) or die $dbh->errstr;
45 :     $sth->execute($name);
46 :     }
47 :    
48 :    
49 :    
50 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3