Proper Method for using LockAcquire

From: Chris Bowlby <excalibur(at)accesswave(dot)ca>
To: pgsql-hackers list <pgsql-hackers(at)postgresql(dot)org>
Subject: Proper Method for using LockAcquire
Date: 2006-07-13 18:01:31
Message-ID: 44B68A7B.60203@accesswave.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

I've been working on a small module that I will be pluging into my
local PostreSQL 8.x database and am in need of doing some table locking.
At this time, I've used various other examples to no avail and was
wondering what the proper method for aquiring a table lock within the
module would be?

For example I am using an SPI based module:

static void mytest(void) {
LOCKMETHODID localLockTableId = INVALID_LOCKMETHOD;
LOCKTAG localtag;

memset(&localtag, 0, sizeof(localtag));
localtag.relId = XactLockTableId;
localtag.dbId = 1;
localtag.objId.xid = InvalidTransactionId;

if (!LockAcquire(LocalLockTableId, &localtag,
GetCurrentTransactionId(), Sharelock, false)) {
elog(ERROR, "mytest: did not acquire table lock");
}

....

if(!LockRelease(LocalLockTableId, &localtag,
GetCurrentTransactionId(), Sharelock)) {
elog(ERROR, "mytest: could not release lock");
}
}

I know there is something I am missing and would appreciate any help. I
believe I need to initialize the LocalLockTableId, but I have not been
able to find any examples of that being done. Could someone look this
over and point me in the right direction?

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message mark 2006-07-13 18:03:00 Re: Three weeks left until feature freeze
Previous Message Joshua D. Drake 2006-07-13 17:48:23 Re: Three weeks left until feature freeze