4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
25 * Copyright (c) 1988-2000 by Sun Microsystems, Inc.
26 * All Rights Reserved.
29 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include "db_headers.h"
38 const long unsigned MAXLOW
= 32768*32768;
40 /* Constructor that makes copy of 'other'. */
41 vers::vers(vers
* other
)
48 vers::assign(vers
* other
)
50 WRITELOCKV(this, "w vers::assign");
52 syslog(LOG_ERR
, "vers::vers: making copy of null vers?");
53 vers_high
= vers_low
= time_sec
= time_usec
= 0;
55 time_sec
= other
->time_sec
;
56 time_usec
= other
->time_usec
;
57 vers_low
= other
->vers_low
;
58 vers_high
= other
->vers_high
;
60 WRITEUNLOCKV(this, "wu vers::assign");
64 * Creates new 'vers' with next higher minor version.
65 * If minor version exceeds MAXLOW, bump up major version instead.
66 * Set timestamp to that of the current time.
71 READLOCK(this, NULL
, "r vers::nextminor");
73 vers
* newvers
= new vers
;
75 if (newvers
== NULL
) {
76 READUNLOCK(this, NULL
, "ru vers::nextminor DB_MEMORY_LIMIT");
77 FATAL3("vers::nextminor: cannot allocation space",
78 DB_MEMORY_LIMIT
, NULL
);
82 gettimeofday(&mt
, NULL
);
84 newvers
->time_sec
= (unsigned int) mt
.tv_sec
;
85 newvers
->time_usec
= (unsigned int) mt
.tv_usec
;
86 newvers
->vers_low
= (this->vers_low
+ 1);
87 newvers
->vers_high
= (this->vers_high
);
89 if (newvers
->vers_low
>= MAXLOW
){
91 newvers
->vers_low
= 0;
94 READUNLOCK(this, newvers
, "ru vers::nextminor");
99 * Creates new 'vers' with next higher major version.
100 * Set timestamp to that of the current time.
105 READLOCK(this, NULL
, "r vers::nextmajor");
107 vers
* newvers
= new vers
;
109 if (newvers
== NULL
) {
110 READUNLOCK(this, NULL
, "ru vers::nextmajor DB_MEMORY_LIMIT");
111 FATAL3("vers::nextminor: cannot allocation space",
112 DB_MEMORY_LIMIT
, NULL
);
116 gettimeofday(&mt
, NULL
);
118 newvers
->time_sec
= (unsigned int) mt
.tv_sec
;
119 newvers
->time_usec
= (unsigned int) mt
.tv_usec
;
120 newvers
->vers_low
= 0;
121 newvers
->vers_high
= (this->vers_high
+1);
123 READUNLOCK(this, newvers
, "ru vers::nextmajor");
128 * Predicate indicating whether this vers is earlier than 'other' in
129 * terms of version numbers.
132 vers::earlier_than(vers
*other
)
138 "vers::earlier_than: comparing against null vers");
142 READLOCK(this, FALSE
, "r vers::earlier_than");
143 READLOCKNR(other
, lret
, "r other vers::earlier_than");
145 READUNLOCK(this, FALSE
, "ru + r other vers::earlier_than");
149 if (other
->vers_high
> vers_high
) ret
= TRUE
;
150 else if (other
->vers_high
< vers_high
) ret
= FALSE
;
151 else if (other
->vers_low
> vers_low
) ret
= TRUE
;
154 READUNLOCKNR(other
, lret
, "ru other vers::earlier_than");
155 READUNLOCK(this, ret
, ((lret
!= 0) ?
156 "ru + ru other vers::earlier_than" :
157 "ru vers::earlier_than"));
161 /* Print the value of this 'vers' to specified file. */
163 vers::print(FILE* file
)
166 thetime
= ctime((long *) (&(time_sec
)));
167 thetime
[strlen(thetime
)-1] = 0;
169 READLOCKV(this, "r vers::print");
170 fprintf(file
, "version=%u.%u %s:%u",
176 READUNLOCKV(this, "ru vers::print");
181 WRITELOCKV(this, "r vers::zero");
182 vers_high
= vers_low
= time_sec
= time_usec
= 0;
183 WRITEUNLOCKV(this, "ru vers::zero");
187 vers::equal( vers
*other
) {
188 READLOCK(this, FALSE
, "r vers::equal");
189 bool_t ret
= other
!= NULL
&&
190 vers_high
== other
->vers_high
&&
191 vers_low
== other
->vers_low
&&
192 time_sec
== other
->time_sec
&&
193 time_usec
== other
->time_usec
;
194 READUNLOCK(this, ret
, "ru vers::equal");