// complete validating. It must be finished before we can decide to rollback or commit.
//
static txn_state_e tm_validate_key (txn_t *txn, void *key) {
+ assert(txn->state != TXN_RUNNING);
update_t *update = (update_t *) map_get(txn->map, key);
for (; update != NULL; update = update->next) {
}
static txn_state_e txn_validate (txn_t *txn) {
+ assert(txn->state != TXN_RUNNING);
int i;
switch (txn->state) {
txn->state = TXN_ABORTED;
break;
}
+ assert(s == TXN_VALIDATED);
}
if (txn->state == TXN_VALIDATING) {
txn->state = TXN_VALIDATED;
}
void txn_abort (txn_t *txn) {
+ if (txn->state != TXN_RUNNING)
+ return; // TODO: return some sort of error code
int i;
for (i = 0; i < txn->writes_count; ++i) {
}
txn_state_e txn_commit (txn_t *txn) {
+ if (txn->state != TXN_RUNNING)
+ return txn->state; // TODO: return some sort of error code
assert(txn->state == TXN_RUNNING);
txn->state = TXN_VALIDATING;
// Get most recent committed version prior to our read version.
uint64_t tm_get (txn_t *txn, void *key) {
+ if (txn->state != TXN_RUNNING)
+ return ERROR_TXN_NOT_RUNNING;
update_t *newest_update = (update_t *) map_get(txn->map, key);
if (!IS_TAGGED(newest_update, TAG2))
}
void tm_set (txn_t *txn, void *key, uint64_t value) {
+ if (txn->state != TXN_RUNNING)
+ return; // TODO: return some sort of error code
// create a new update record
update_t *update = alloc_update_rec();