postgresql/contrib/userlock/user_locks.c

91 lines
1.6 KiB
C
Raw Normal View History

1997-11-06 05:38:25 +08:00
/*
* user_locks.c --
*
* 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>
*
1999-09-28 04:04:14 +08:00
* This software is distributed under the GNU General Public License
* either version 2, or (at your option) any later version.
1997-11-06 05:38:25 +08:00
*/
#include "postgres.h"
1997-11-06 05:38:25 +08:00
#include "miscadmin.h"
#include "storage/lmgr.h"
1997-11-06 05:38:25 +08:00
#include "storage/proc.h"
#include "user_locks.h"
1997-11-06 05:38:25 +08:00
int
user_lock(uint32 id1, uint32 id2, LOCKMODE lockmode)
1997-11-06 05:38:25 +08:00
{
LOCKTAG tag;
1997-11-06 05:38:25 +08:00
memset(&tag, 0, sizeof(LOCKTAG));
1999-05-26 00:15:34 +08:00
tag.dbId = MyDatabaseId;
tag.relId = 0;
tag.objId.blkno = (BlockNumber) id2;
tag.offnum = (OffsetNumber) (id1 & 0xffff);
1997-11-06 05:38:25 +08:00
return LockAcquire(USER_LOCKMETHOD, &tag, InvalidTransactionId,
lockmode, true);
1997-11-06 05:38:25 +08:00
}
int
user_unlock(uint32 id1, uint32 id2, LOCKMODE lockmode)
1997-11-06 05:38:25 +08:00
{
LOCKTAG tag;
memset(&tag, 0, sizeof(LOCKTAG));
1999-05-26 00:15:34 +08:00
tag.dbId = MyDatabaseId;
tag.relId = 0;
tag.objId.blkno = (BlockNumber) id2;
tag.offnum = (OffsetNumber) (id1 & 0xffff);
return LockRelease(USER_LOCKMETHOD, &tag, InvalidTransactionId, lockmode);
1997-11-06 05:38:25 +08:00
}
int
user_write_lock(uint32 id1, uint32 id2)
1997-11-06 05:38:25 +08:00
{
return user_lock(id1, id2, ExclusiveLock);
1997-11-06 05:38:25 +08:00
}
int
user_write_unlock(uint32 id1, uint32 id2)
1997-11-06 05:38:25 +08:00
{
return user_unlock(id1, id2, ExclusiveLock);
1997-11-06 05:38:25 +08:00
}
int
user_write_lock_oid(Oid oid)
{
return user_lock(0, oid, ExclusiveLock);
1997-11-06 05:38:25 +08:00
}
int
user_write_unlock_oid(Oid oid)
{
return user_unlock(0, oid, ExclusiveLock);
1997-11-06 05:38:25 +08:00
}
int
user_unlock_all(void)
1997-11-06 05:38:25 +08:00
{
return LockReleaseAll(USER_LOCKMETHOD, MyProc, false,
InvalidTransactionId);
1997-11-06 05:38:25 +08:00
}
/* end of file */
/*
* Local Variables:
* tab-width: 4
* c-indent-level: 4
* c-basic-offset: 4
* End:
*/