1997-11-06 00:38:25 +03:00
|
|
|
/*
|
|
|
|
* user_locks.c --
|
|
|
|
*
|
|
|
|
* This loadable module, together with my user-lock.patch applied to the
|
|
|
|
* backend, provides support for user-level long-term cooperative locks.
|
|
|
|
*
|
1998-08-30 23:37:51 +04:00
|
|
|
* Copyright (c) 1998, Massimo Dal Zotto <dz@cs.unitn.it>
|
|
|
|
*
|
|
|
|
* This file is distributed under the GNU General Public License
|
|
|
|
* either version 2, or (at your option) any later version.
|
1997-11-06 00:38:25 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "storage/lock.h"
|
|
|
|
#include "storage/proc.h"
|
|
|
|
#include "storage/multilev.h"
|
|
|
|
#include "utils/elog.h"
|
|
|
|
|
|
|
|
#include "user_locks.h"
|
|
|
|
|
|
|
|
int
|
1998-08-30 23:37:51 +04:00
|
|
|
user_lock(unsigned int id1, unsigned int 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;
|
|
|
|
tag.tupleId.ip_blkid.bi_hi = id2 >> 16;
|
|
|
|
tag.tupleId.ip_blkid.bi_lo = id2 & 0xffff;
|
|
|
|
tag.tupleId.ip_posid = (unsigned short) (id1 & 0xffff);
|
1997-11-06 00:38:25 +03:00
|
|
|
|
1998-08-30 23:37:51 +04:00
|
|
|
return LockAcquire(USER_LOCKMETHOD, &tag, lockmode);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-08-30 23:37:51 +04:00
|
|
|
user_unlock(unsigned int id1, unsigned int 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;
|
|
|
|
tag.tupleId.ip_blkid.bi_hi = id2 >> 16;
|
|
|
|
tag.tupleId.ip_blkid.bi_lo = id2 & 0xffff;
|
|
|
|
tag.tupleId.ip_posid = (unsigned short) (id1 & 0xffff);
|
|
|
|
|
1998-08-30 23:37:51 +04:00
|
|
|
return LockRelease(USER_LOCKMETHOD, &tag, lockmode);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
user_write_lock(unsigned int id1, unsigned int id2)
|
|
|
|
{
|
1998-02-26 07:46:47 +03:00
|
|
|
return user_lock(id1, id2, WRITE_LOCK);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
user_write_unlock(unsigned int id1, unsigned int id2)
|
|
|
|
{
|
1998-02-26 07:46:47 +03:00
|
|
|
return user_unlock(id1, id2, WRITE_LOCK);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
user_write_lock_oid(Oid oid)
|
|
|
|
{
|
1998-02-26 07:46:47 +03:00
|
|
|
return user_lock(0, oid, WRITE_LOCK);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
user_write_unlock_oid(Oid oid)
|
|
|
|
{
|
1998-02-26 07:46:47 +03:00
|
|
|
return user_unlock(0, oid, WRITE_LOCK);
|
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);
|
1998-08-30 23:37:51 +04:00
|
|
|
return LockReleaseAll(USER_LOCKMETHOD, &proc->lockQueue);
|
1997-11-06 00:38:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* end of file */
|
1998-08-30 23:37:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
1999-05-25 20:15:34 +04:00
|
|
|
* tab-width: 4
|
|
|
|
* c-indent-level: 4
|
|
|
|
* c-basic-offset: 4
|
1998-08-30 23:37:51 +04:00
|
|
|
* End:
|
|
|
|
*/
|