|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.41 2001/09/2904:02:24 tgl Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.42 2001/09/2915:29:48 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -310,19 +310,24 @@ GetSnapshotData(bool serializable) |
310 | 310 | if (snapshot==NULL) |
311 | 311 | elog(ERROR,"Memory exhausted in GetSnapshotData"); |
312 | 312 |
|
313 | | -snapshot->xmin=GetCurrentTransactionId(); |
314 | | - |
315 | | -LWLockAcquire(SInvalLock,LW_SHARED); |
316 | | - |
317 | 313 | /* |
318 | | - * There can be no more than lastBackend active transactions, so this |
319 | | - * is enough space: |
| 314 | + * Allocating space for MaxBackends xids is usually overkill; |
| 315 | + * lastBackend would be sufficient. But it seems better to do the |
| 316 | + * malloc while not holding the lock, so we can't look at lastBackend. |
320 | 317 | */ |
321 | 318 | snapshot->xip= (TransactionId*) |
322 | | -malloc(segP->lastBackend*sizeof(TransactionId)); |
| 319 | +malloc(MaxBackends*sizeof(TransactionId)); |
323 | 320 | if (snapshot->xip==NULL) |
324 | 321 | elog(ERROR,"Memory exhausted in GetSnapshotData"); |
325 | 322 |
|
| 323 | +snapshot->xmin=GetCurrentTransactionId(); |
| 324 | + |
| 325 | +/* |
| 326 | + * If we are going to set MyProc->xmin then we'd better get exclusive |
| 327 | + * lock; if not, this is a read-only operation so it can be shared. |
| 328 | + */ |
| 329 | +LWLockAcquire(SInvalLock,serializable ?LW_EXCLUSIVE :LW_SHARED); |
| 330 | + |
326 | 331 | /*-------------------- |
327 | 332 | * Unfortunately, we have to call ReadNewTransactionId() after acquiring |
328 | 333 | * SInvalLock above. It's not good because ReadNewTransactionId() does |
|