aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/lmgr/single.c
blob: 8d41ea38bb66f5a8d7d9d7f4ec19a39f7525c07a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*-------------------------------------------------------------------------
 *
 * single.c--
 *    set single locks in the multi-level lock hierarchy
 *
 *    Sometimes we don't want to set all levels of the multi-level
 *	lock hierarchy at once.  This allows us to set and release
 * 	one level at a time.  It's useful in index scans when
 *	you can set an intent lock at the beginning and thereafter
 * 	only set page locks.  Tends to speed things up.
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *    $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/single.c,v 1.1.1.1 1996/07/09 06:21:57 scrappy Exp $
 *
 *-------------------------------------------------------------------------
 */
#include <string.h>
#include "storage/lmgr.h"	/* where the declarations go */
#include "storage/lock.h"
#include "storage/multilev.h"
#include "utils/rel.h"

/*
 * SingleLockReln -- lock a relation
 *
 * Returns: TRUE if the lock can be set, FALSE otherwise.
 */
bool
SingleLockReln(LockInfo linfo, LOCKT lockt, int action)
{
    LOCKTAG	tag;
    
    /* 
     * LOCKTAG has two bytes of padding, unfortunately.  The
     * hash function will return miss if the padding bytes aren't
     * zero'd.
     */
    memset(&tag,0,sizeof(tag));
    tag.relId = linfo->lRelId.relId;
    tag.dbId = linfo->lRelId.dbId;
    BlockIdSet(&(tag.tupleId.ip_blkid), InvalidBlockNumber);
    tag.tupleId.ip_posid = InvalidOffsetNumber;
    
    if (action == UNLOCK)
	return(LockRelease(MultiTableId, &tag, lockt));
    else
	return(LockAcquire(MultiTableId, &tag, lockt));
}

/*
 * SingleLockPage -- use multi-level lock table, but lock
 *	only at the page level.
 *
 * Assumes that an INTENT lock has already been set in the
 * multi-level lock table.
 *
 */
bool
SingleLockPage(LockInfo linfo,
	       ItemPointer tidPtr,
	       LOCKT lockt,
	       int action)
{
    LOCKTAG	tag;
    
    /* 
     * LOCKTAG has two bytes of padding, unfortunately.  The
     * hash function will return miss if the padding bytes aren't
     * zero'd.
     */
    memset(&tag,0,sizeof(tag));
    tag.relId = linfo->lRelId.relId;
    tag.dbId = linfo->lRelId.dbId;
    BlockIdCopy(&(tag.tupleId.ip_blkid), &(tidPtr->ip_blkid));
    tag.tupleId.ip_posid = InvalidOffsetNumber;
    
    
    if (action == UNLOCK)
	return(LockRelease(MultiTableId, &tag, lockt));
    else
	return(LockAcquire(MultiTableId, &tag, lockt));
}