aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xid.c
blob: faeeb623d58ccebfede6e715ce59fe6615d1b274 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*-------------------------------------------------------------------------
 *
 * xid.c--
 *    POSTGRES transaction identifier code.
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *    $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/xid.c,v 1.1.1.1 1996/07/09 06:21:14 scrappy Exp $
 *
 * OLD COMMENTS
 * XXX WARNING
 *	Much of this file will change when we change our representation
 *	of transaction ids -cim 3/23/90
 *
 * It is time to make the switch from 5 byte to 4 byte transaction ids
 * This file was totally reworked. -mer 5/22/92
 *
 *-------------------------------------------------------------------------
 */
#include <stdio.h>
#include "postgres.h"
#include "utils/palloc.h"
#include "utils/elog.h"
#include "utils/memutils.h"
#include "utils/nabstime.h"

extern TransactionId NullTransactionId;
extern TransactionId DisabledTransactionId;
extern TransactionId AmiTransactionId;
extern TransactionId FirstTransactionId;

/* ----------------------------------------------------------------
 * 	TransactionIdIsValid
 *
 *	Macro-ize me.
 * ----------------------------------------------------------------
 */
bool
TransactionIdIsValid(TransactionId transactionId)
{
    return ((bool) (transactionId != NullTransactionId) );
}

/* XXX char16 name for catalogs */
TransactionId
xidin(char *representation)
{
    return (atol(representation));
}

/* XXX char16 name for catalogs */
char*
xidout(TransactionId transactionId)
{
/*    return(TransactionIdFormString(transactionId)); */
    char 			*representation;
    
    /* maximum 32 bit unsigned integer representation takes 10 chars */
    representation = palloc(11);
    
    (void)sprintf(representation, "%u", transactionId);
    
    return (representation);

}

/* ----------------------------------------------------------------
 *	StoreInvalidTransactionId
 *
 *	Maybe do away with Pointer types in these routines.
 *      Macro-ize this one.
 * ----------------------------------------------------------------
 */
void
StoreInvalidTransactionId(TransactionId *destination)
{
    *destination = NullTransactionId;
}

/* ----------------------------------------------------------------
 *	TransactionIdStore
 *
 *      Macro-ize this one.
 * ----------------------------------------------------------------
 */
void
TransactionIdStore(TransactionId transactionId,
		   TransactionId *destination)
{
    *destination = transactionId;
}

/* ----------------------------------------------------------------
 *	TransactionIdEquals
 * ----------------------------------------------------------------
 */
bool
TransactionIdEquals(TransactionId id1, TransactionId id2)
{
    return ((bool) (id1 == id2));
}

/* ----------------------------------------------------------------
 *	TransactionIdIsLessThan
 * ----------------------------------------------------------------
 */
bool
TransactionIdIsLessThan(TransactionId id1, TransactionId id2)
{
    return ((bool)(id1 < id2));
}

/* ----------------------------------------------------------------
 *	xideq
 * ----------------------------------------------------------------
 */

/*
 *	xideq		- returns 1, iff xid1 == xid2
 *				  0  else;
 */
bool
xideq(TransactionId xid1, TransactionId xid2)
{
    return( (bool) (xid1 == xid2) );
}



/* ----------------------------------------------------------------
 *	TransactionIdIncrement
 * ----------------------------------------------------------------
 */
void
TransactionIdIncrement(TransactionId *transactionId)
{
    
    (*transactionId)++;
    if (*transactionId == DisabledTransactionId)
	elog(FATAL, "TransactionIdIncrement: exhausted XID's");
    return;
}

/* ----------------------------------------------------------------
 *	TransactionIdAdd
 * ----------------------------------------------------------------
 */
void
TransactionIdAdd(TransactionId *xid, int value)
{
    *xid += value;
    return;
}