1997-11-06 05:38:25 +08:00
|
|
|
/*
|
|
|
|
* user_locks.c --
|
|
|
|
*
|
2001-06-22 08:04:59 +08:00
|
|
|
* This loadable module provides support for user-level long-term
|
|
|
|
* cooperative locks.
|
1997-11-06 05:38:25 +08:00
|
|
|
*
|
1999-09-28 04:04:14 +08:00
|
|
|
* Copyright (C) 1999, Massimo Dal Zotto <dz@cs.unitn.it>
|
1998-08-31 03:37:51 +08:00
|
|
|
*
|
1999-09-28 04:04:14 +08:00
|
|
|
* This software is distributed under the GNU General Public License
|
1998-08-31 03:37:51 +08:00
|
|
|
* either version 2, or (at your option) any later version.
|
1997-11-06 05:38:25 +08:00
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
2001-06-22 08:04:59 +08:00
|
|
|
|
1997-11-06 05:38:25 +08:00
|
|
|
#include "miscadmin.h"
|
1999-06-01 17:35:39 +08:00
|
|
|
#include "storage/lmgr.h"
|
1997-11-06 05:38:25 +08:00
|
|
|
#include "storage/proc.h"
|
|
|
|
|
|
|
|
#include "user_locks.h"
|
|
|
|
|
2001-06-22 08:04:59 +08:00
|
|
|
|
2005-04-30 06:28:24 +08:00
|
|
|
#define SET_LOCKTAG_USERLOCK(locktag,id1,id2) \
|
2005-05-18 05:46:11 +08:00
|
|
|
((locktag).locktag_field1 = MyDatabaseId, \
|
|
|
|
(locktag).locktag_field2 = (id1), \
|
|
|
|
(locktag).locktag_field3 = (id2), \
|
2005-04-30 06:28:24 +08:00
|
|
|
(locktag).locktag_field4 = 0, \
|
|
|
|
(locktag).locktag_type = LOCKTAG_USERLOCK)
|
|
|
|
|
|
|
|
|
1997-11-06 05:38:25 +08:00
|
|
|
int
|
1999-06-01 17:35:39 +08:00
|
|
|
user_lock(uint32 id1, uint32 id2, LOCKMODE lockmode)
|
1997-11-06 05:38:25 +08:00
|
|
|
{
|
1998-02-26 12:46:47 +08:00
|
|
|
LOCKTAG tag;
|
1997-11-06 05:38:25 +08:00
|
|
|
|
2005-04-30 06:28:24 +08:00
|
|
|
SET_LOCKTAG_USERLOCK(tag, id1, id2);
|
1997-11-06 05:38:25 +08:00
|
|
|
|
2005-06-15 06:15:33 +08:00
|
|
|
return (LockAcquire(USER_LOCKMETHOD, &tag, false,
|
|
|
|
lockmode, true, true) != LOCKACQUIRE_NOT_AVAIL);
|
1997-11-06 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-06-01 17:35:39 +08:00
|
|
|
user_unlock(uint32 id1, uint32 id2, LOCKMODE lockmode)
|
1997-11-06 05:38:25 +08:00
|
|
|
{
|
1998-02-26 12:46:47 +08:00
|
|
|
LOCKTAG tag;
|
|
|
|
|
2005-04-30 06:28:24 +08:00
|
|
|
SET_LOCKTAG_USERLOCK(tag, id1, id2);
|
1998-02-26 12:46:47 +08:00
|
|
|
|
2005-06-15 06:15:33 +08:00
|
|
|
return LockRelease(USER_LOCKMETHOD, &tag, lockmode, true);
|
1997-11-06 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-06-01 17:35:39 +08:00
|
|
|
user_write_lock(uint32 id1, uint32 id2)
|
1997-11-06 05:38:25 +08:00
|
|
|
{
|
1999-06-01 17:35:39 +08:00
|
|
|
return user_lock(id1, id2, ExclusiveLock);
|
1997-11-06 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
1999-06-01 17:35:39 +08:00
|
|
|
user_write_unlock(uint32 id1, uint32 id2)
|
1997-11-06 05:38:25 +08:00
|
|
|
{
|
1999-06-01 17:35:39 +08:00
|
|
|
return user_unlock(id1, id2, ExclusiveLock);
|
1997-11-06 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
user_write_lock_oid(Oid oid)
|
|
|
|
{
|
1999-06-01 17:35:39 +08:00
|
|
|
return user_lock(0, oid, ExclusiveLock);
|
1997-11-06 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
user_write_unlock_oid(Oid oid)
|
|
|
|
{
|
1999-06-01 17:35:39 +08:00
|
|
|
return user_unlock(0, oid, ExclusiveLock);
|
1997-11-06 05:38:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-07 08:27:30 +08:00
|
|
|
user_unlock_all(void)
|
1997-11-06 05:38:25 +08:00
|
|
|
{
|
2005-05-20 07:30:18 +08:00
|
|
|
LockReleaseAll(USER_LOCKMETHOD, true);
|
|
|
|
|
|
|
|
return true;
|
1997-11-06 05:38:25 +08:00
|
|
|
}
|