Commit 3f7ef527 authored by Leigh B Stoller's avatar Leigh B Stoller

Make sure emulab_locks table has the lock we are trying to lock.

parent 4dd0e720
......@@ -265,6 +265,9 @@ sub EmulabLock($)
{
my ($name) = @_;
EmulabCreateLock($name) == 0
or return -1;
my $query_result =
DBQueryWarn("update emulab_locks set value=1 " .
"where name='$name' and value=0");
......@@ -285,6 +288,36 @@ sub EmulabUnlock($)
return 0;
}
sub EmulabCreateLock($)
{
my ($name) = @_;
my $query_result =
DBQueryWarn("select * from emulab_locks where name='$name'");
return -1
if (! $query_result);
if (!$query_result->numrows) {
DBQueryWarn("lock tables emulab_locks write")
or return -1;
$query_result =
DBQueryWarn("select * from emulab_locks where name='$name'");
if (! $query_result) {
DBQueryWarn("unlock tables");
return -1;
}
if (!$query_result->numrows &&
!DBQueryWarn("insert into emulab_locks set ".
" name='$name',value=0")) {
DBQueryWarn("unlock tables");
return -1;
}
DBQueryWarn("unlock tables")
or return -1;
}
return 0;
}
#
# Count up/down locking.
#
......@@ -292,6 +325,9 @@ sub EmulabCountLock($$)
{
my ($name, $count) = @_;
EmulabCreateLock($name) == 0
or return -1;
my $query_result =
DBQueryWarn("update emulab_locks set value=value+1 " .
"where name='$name' and value<${count}");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment