1997-11-06 00:38:25 +03:00
|
|
|
/*
|
|
|
|
* user_locks.c --
|
|
|
|
*
|
2001-06-22 04:04:59 +04:00
|
|
|
* This loadable module provides support for user-level long-term
|
|
|
|
* cooperative locks.
|
1997-11-06 00:38:25 +03:00
|
|
|
*
|
1999-09-28 00:04:14 +04:00
|
|
|
* Copyright (C) 1999, Massimo Dal Zotto <dz@cs.unitn.it>
|
1998-08-30 23:37:51 +04:00
|
|
|
*
|
1999-09-28 00:04:14 +04:00
|
|
|
* This software is distributed under the GNU General Public License
|
1998-08-30 23:37:51 +04:00
|
|
|
* either version 2, or (at your option) any later version.
|
1997-11-06 00:38:25 +03:00
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
2001-06-22 04:04:59 +04:00
|
|
|
|
1997-11-06 00:38:25 +03:00
|
|
|
#include "miscadmin.h"
|
1999-06-01 13:35:39 +04:00
|
|
|
#include "storage/lmgr.h"
|
1997-11-06 00:38:25 +03:00
|
|
|
#include "storage/proc.h"
|
|
|
|
|
|
|
|
#include "user_locks.h"
|
|
|
|
|
2001-06-22 04:04:59 +04:00
|
|
|
|
1997-11-06 00:38:25 +03:00
|
|
|
int
|
1999-06-01 13:35:39 +04:00
|
|
|
user_lock(uint32 id1, uint32 id2, LOCKMODE lockmode)
|
1997-11-06 00:38:25 +03:00
|
|
|
{
|
1998-02-26 07:46:47 +03:00
|
|
|
LOCKTAG tag;
|
1997-11-06 00:38:25 +03:00
|
|
|
|
1998-02-26 07:46:47 +03:00
|
|
|
memset(&tag, 0, sizeof(LOCKTAG));
|
1999-05-25 20:15:34 +04:00
|
|
|
tag.dbId = MyDatabaseId;
|
1998-02-26 07:46:47 +03:00
|
|
|
tag.relId = 0;
|
1999-06-01 13:35:39 +04:00
|
|
|
tag.objId.blkno = (BlockNumber) id2;
|
|
|
|
tag.offnum = (OffsetNumber) (id1 & 0xffff);
|
1997-11-06 00:38:25 +03:00
|
|
|
|
2001-06-22 04:04:59 +04:00
|
|
|
return LockAcquire(USER_LOCKMETHOD, &tag, InvalidTransactionId,
|
|
|
|
lockmode, true);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-06-01 13:35:39 +04:00
|
|
|
user_unlock(uint32 id1, uint32 id2, LOCKMODE lockmode)
|
1997-11-06 00:38:25 +03:00
|
|
|
{
|
1998-02-26 07:46:47 +03:00
|
|
|
LOCKTAG tag;
|
|
|
|
|
|
|
|
memset(&tag, 0, sizeof(LOCKTAG));
|
1999-05-25 20:15:34 +04:00
|
|
|
tag.dbId = MyDatabaseId;
|
1998-02-26 07:46:47 +03:00
|
|
|
tag.relId = 0;
|
1999-06-01 13:35:39 +04:00
|
|
|
tag.objId.blkno = (BlockNumber) id2;
|
|
|
|
tag.offnum = (OffsetNumber) (id1 & 0xffff);
|
1998-02-26 07:46:47 +03:00
|
|
|
|
2000-12-22 03:51:54 +03:00
|
|
|
return LockRelease(USER_LOCKMETHOD, &tag, InvalidTransactionId, lockmode);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-06-01 13:35:39 +04:00
|
|
|
user_write_lock(uint32 id1, uint32 id2)
|
1997-11-06 00:38:25 +03:00
|
|
|
{
|
1999-06-01 13:35:39 +04:00
|
|
|
return user_lock(id1, id2, ExclusiveLock);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
1999-06-01 13:35:39 +04:00
|
|
|
user_write_unlock(uint32 id1, uint32 id2)
|
1997-11-06 00:38:25 +03:00
|
|
|
{
|
1999-06-01 13:35:39 +04:00
|
|
|
return user_unlock(id1, id2, ExclusiveLock);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
user_write_lock_oid(Oid oid)
|
|
|
|
{
|
1999-06-01 13:35:39 +04:00
|
|
|
return user_lock(0, oid, ExclusiveLock);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
user_write_unlock_oid(Oid oid)
|
|
|
|
{
|
1999-06-01 13:35:39 +04:00
|
|
|
return user_unlock(0, oid, ExclusiveLock);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
user_unlock_all()
|
|
|
|
{
|
1998-02-26 07:46:47 +03:00
|
|
|
PROC *proc;
|
|
|
|
SHMEM_OFFSET location;
|
|
|
|
|
1998-08-30 23:37:51 +04:00
|
|
|
ShmemPIDLookup(MyProcPid, &location);
|
1998-02-26 07:46:47 +03:00
|
|
|
if (location == INVALID_OFFSET)
|
|
|
|
{
|
|
|
|
elog(NOTICE, "UserUnlockAll: unable to get proc ptr");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
proc = (PROC *) MAKE_PTR(location);
|
2000-12-22 03:51:54 +03:00
|
|
|
return LockReleaseAll(USER_LOCKMETHOD, proc, false, InvalidTransactionId);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* end of file */
|
1998-08-30 23:37:51 +04:00
|
|
|
|
|
|
|
/*
|
1999-06-05 23:09:48 +04:00
|
|
|
* Local Variables:
|
2000-04-12 21:17:23 +04:00
|
|
|
* tab-width: 4
|
|
|
|
* c-indent-level: 4
|
|
|
|
* c-basic-offset: 4
|
1998-08-30 23:37:51 +04:00
|
|
|
* End:
|
|
|
|
*/
|