* _bitmap_getbuf() -- return the buffer for the given block number and * the access method. */
| 58 | * the access method. |
| 59 | */ |
| 60 | Buffer |
| 61 | _bitmap_getbuf(Relation rel, BlockNumber blkno, int access) |
| 62 | { |
| 63 | Buffer buf; |
| 64 | |
| 65 | if (blkno != P_NEW) |
| 66 | { |
| 67 | buf = ReadBuffer(rel, blkno); |
| 68 | if (access != BM_NOLOCK) |
| 69 | LockBuffer(buf, access); |
| 70 | } |
| 71 | |
| 72 | else |
| 73 | { |
| 74 | bool needLock; |
| 75 | |
| 76 | Assert(access == BM_WRITE); |
| 77 | |
| 78 | /* |
| 79 | * Extend the relation by one page. |
| 80 | * |
| 81 | * We have to use a lock to ensure no one else is extending the rel at |
| 82 | * the same time, else we will both try to initialize the same new |
| 83 | * page. We can skip locking for new or temp relations, however, |
| 84 | * since no one else could be accessing them. |
| 85 | */ |
| 86 | needLock = !RELATION_IS_LOCAL(rel); |
| 87 | |
| 88 | if (needLock) |
| 89 | LockRelationForExtension(rel, ExclusiveLock); |
| 90 | |
| 91 | buf = ReadBuffer(rel, P_NEW); |
| 92 | |
| 93 | /* Acquire buffer lock on new page */ |
| 94 | LockBuffer(buf, BM_WRITE); |
| 95 | |
| 96 | /* |
| 97 | * Release the file-extension lock; it's now OK for someone else to |
| 98 | * extend the relation some more. |
| 99 | */ |
| 100 | if (needLock) |
| 101 | UnlockRelationForExtension(rel, ExclusiveLock); |
| 102 | } |
| 103 | |
| 104 | return buf; |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * _bitmap_wrtbuf() -- write a buffer page to disk. |
no test coverage detected