static txn_state_e txn_validate (txn_t *txn);
+static skiplist_t *active_ = NULL;
+
static version_t version_ = 1;
-static skiplist_t *active_ = NULL;
+static inline skiplist_t *get_active (void) {
-__attribute__ ((constructor(103))) void txn_init (void) {
- active_ = sl_alloc(NULL);
+ return active_;
}
// Validate the updates for <key>. Validation fails if there is a write-write conflict. That is if after our
case TXN_VALIDATING:
if (txn->wv == UNDETERMINED_VERSION) {
version_t wv = SYNC_ADD(&version_, 1);
- SYNC_CAS(&txn->wv, UNDETERMINED_VERSION, wv);
+ (void)SYNC_CAS(&txn->wv, UNDETERMINED_VERSION, wv);
}
for (i = 0; i < txn->writes_count; ++i) {
txn->map = map;
txn->writes = nbd_malloc(sizeof(*txn->writes) * INITIAL_WRITES_SIZE);
txn->writes_size = INITIAL_WRITES_SIZE;
+ if (EXPECT_FALSE(active_ == NULL)) {
+ skiplist_t *a = sl_alloc(NULL);
+ if (SYNC_CAS(&active_, NULL, a) != NULL) {
+ sl_free(a);
+ }
+ }
// acquire the read version for txn. must be careful to avoid a race
do {