mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
c599a247bb
the data defining the semantics of a lock method (ie, conflict resolution table and ancillary data, which is all constant) and the hash tables storing the current state. The only thing we give up by this is the ability to use separate hashtables for different lock methods, but there is no need for that anyway. Put some extra fields into the LockMethod definition structs to clean up some other uglinesses, like hard-wired tests for DEFAULT_LOCKMETHOD and USER_LOCKMETHOD. This commit doesn't do anything about the performance issues we were discussing, but it clears away some of the underbrush that's in the way of fixing that.
83 lines
1.5 KiB
C
83 lines
1.5 KiB
C
/*
|
|
* user_locks.c --
|
|
*
|
|
* This loadable module provides support for user-level long-term
|
|
* cooperative locks.
|
|
*
|
|
* Copyright (C) 1999, Massimo Dal Zotto <dz@cs.unitn.it>
|
|
*
|
|
* This software is distributed under the GNU General Public License
|
|
* either version 2, or (at your option) any later version.
|
|
*/
|
|
#include "postgres.h"
|
|
|
|
#include "miscadmin.h"
|
|
#include "storage/lmgr.h"
|
|
#include "storage/proc.h"
|
|
|
|
#include "user_locks.h"
|
|
|
|
|
|
#define SET_LOCKTAG_USERLOCK(locktag,id1,id2) \
|
|
((locktag).locktag_field1 = MyDatabaseId, \
|
|
(locktag).locktag_field2 = (id1), \
|
|
(locktag).locktag_field3 = (id2), \
|
|
(locktag).locktag_field4 = 0, \
|
|
(locktag).locktag_type = LOCKTAG_USERLOCK, \
|
|
(locktag).locktag_lockmethodid = USER_LOCKMETHOD)
|
|
|
|
|
|
int
|
|
user_lock(uint32 id1, uint32 id2, LOCKMODE lockmode)
|
|
{
|
|
LOCKTAG tag;
|
|
|
|
SET_LOCKTAG_USERLOCK(tag, id1, id2);
|
|
|
|
return (LockAcquire(&tag, false,
|
|
lockmode, true, true) != LOCKACQUIRE_NOT_AVAIL);
|
|
}
|
|
|
|
int
|
|
user_unlock(uint32 id1, uint32 id2, LOCKMODE lockmode)
|
|
{
|
|
LOCKTAG tag;
|
|
|
|
SET_LOCKTAG_USERLOCK(tag, id1, id2);
|
|
|
|
return LockRelease(&tag, lockmode, true);
|
|
}
|
|
|
|
int
|
|
user_write_lock(uint32 id1, uint32 id2)
|
|
{
|
|
return user_lock(id1, id2, ExclusiveLock);
|
|
}
|
|
|
|
|
|
int
|
|
user_write_unlock(uint32 id1, uint32 id2)
|
|
{
|
|
return user_unlock(id1, id2, ExclusiveLock);
|
|
}
|
|
|
|
int
|
|
user_write_lock_oid(Oid oid)
|
|
{
|
|
return user_lock(0, oid, ExclusiveLock);
|
|
}
|
|
|
|
int
|
|
user_write_unlock_oid(Oid oid)
|
|
{
|
|
return user_unlock(0, oid, ExclusiveLock);
|
|
}
|
|
|
|
int
|
|
user_unlock_all(void)
|
|
{
|
|
LockReleaseAll(USER_LOCKMETHOD, true);
|
|
|
|
return true;
|
|
}
|