Where exclusivity is needed, transactions are used in place of mutexes. Transactions provide a means of ensuring that the internal state of program has been consistent thorough the execution of transaction.
This approach trades better SMP capabilities and less contention for a bit of complexity on the user side. Any code that uses transactions has to define what will happen if transaction commit fails.
For most use cases the way to deal with transaction commit failure is to redo the action but some of them may figure out that the action is not needed anymore.
Unknown member type TxnType
typedef uint8_t Txn_tTransaction handle type.
os_txn_start()This function will start a transaction. Starting a transaction means that the code will remember actual record version number (active rolling counter value). rolling counters are updated whenever read-write transaction is commited. It is perfectly valid to start transaction and not commit it. This effectively equals to voluntarily aborting the transaction. Such abandonned transactions pose no overhead nor stall / corruption risk. transaction ID
int os_txn_commit(Txn_t transaction, enum TxnType type)This function will try to enter the critical section so that the code running afterwards has exclusive access to the shared resource. If another transaction has been commited meanwhile, then this call will fail as transaction couldn’t be commited. Then the critical section is left immediately. If no other transaction conflicted with this one, the code remains in the critical section and can modify the shared context. After the code is done with modifying the shared context, it mustos_txn_done
transaction the ID of transaction as obtained by the call to ox_txn_start()
type the type of transaction E_OK if transaction can be commited E_INVALID if transaction cannot be applied as different transaction has been commited meanwhile.
Returns E_OK if transaction can be commited
int os_txn_start_commit()This is a combination of os_txn_startos_txn_commitos_txn_doneE_OK as this action never fails.
void os_txn_done()This function will leave the critical section related to the transaction. This function has to be called for read-write transaction after all the data changes in the transaction were commited.
os_sys_txn_start(Txn_t *domain)This function performs some additional argument checking.
domain domain in which transactions are allocated transaction identifier within given domain
Returns transaction identifier within given domain
int os_sys_txn_commit(Txn_t *domain, Txn_t txn, enum TxnType type)This function performs some additional argument checking.
domain domain in which transactions are allocated
txn identifier of transaction to be committed
type identifies if transaction is read-only or read-write E_OK if transaction was committed. E_INVALID if transaction cannot be applied as different transaction has been committed meanwhile.
Returns E_OK if transaction was committed. E_INVALID if transaction cannot be applied as different transaction has been committed meanwhile.