[Tarantool-patches] [PATCH 1/6] txn: convert flags to explicit bitfield
Cyrill Gorcunov
gorcunov at gmail.com
Fri Jan 22 16:26:55 MSK 2021
Instead of shifting flags inside txn_x_flag() helpers
lets define precompiled value. Moreover we're about
to drop this helpers completely: better operate with
bitfield directly which allows to test/set/clear a set
of bits at once instead of one by one.
Part-of #5128
Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
src/box/txn.h | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/box/txn.h b/src/box/txn.h
index fca9bc1d0..b42249b17 100644
--- a/src/box/txn.h
+++ b/src/box/txn.h
@@ -56,25 +56,25 @@ struct Vdbe;
enum txn_flag {
/** Transaction has been processed. */
- TXN_IS_DONE,
+ TXN_IS_DONE = 0x1,
/**
* Transaction has been aborted by fiber yield so
* should be rolled back at commit.
*/
- TXN_IS_ABORTED_BY_YIELD,
+ TXN_IS_ABORTED_BY_YIELD = 0x2,
/**
* fiber_yield() is allowed inside the transaction.
* See txn_can_yield() for more details.
*/
- TXN_CAN_YIELD,
+ TXN_CAN_YIELD = 0x4,
/** on_commit and/or on_rollback list is not empty. */
- TXN_HAS_TRIGGERS,
+ TXN_HAS_TRIGGERS = 0x8,
/**
* Synchronous transaction touched sync spaces, or an
* asynchronous transaction blocked by a sync one until it
* is confirmed.
*/
- TXN_WAIT_SYNC,
+ TXN_WAIT_SYNC = 0x10,
/**
* Synchronous transaction 'waiting for ACKs' state before
* commit. In this state it waits until it is replicated
@@ -82,14 +82,14 @@ enum txn_flag {
* commit and returns success to a user.
* TXN_WAIT_SYNC is always set, if TXN_WAIT_ACK is set.
*/
- TXN_WAIT_ACK,
+ TXN_WAIT_ACK = 0x20,
/**
* A transaction may be forced to be asynchronous, not
* wait for any ACKs, and not depend on prepending sync
* transactions. This happens in a few special cases. For
* example, when applier receives snapshot from master.
*/
- TXN_FORCE_ASYNC,
+ TXN_FORCE_ASYNC = 0x40,
};
enum {
@@ -394,21 +394,21 @@ struct txn {
};
static inline bool
-txn_has_flag(struct txn *txn, enum txn_flag flag)
+txn_has_flag(struct txn *txn, unsigned int flag)
{
- return (txn->flags & (1 << flag)) != 0;
+ return (txn->flags & flag) != 0;
}
static inline void
-txn_set_flag(struct txn *txn, enum txn_flag flag)
+txn_set_flag(struct txn *txn, unsigned int flag)
{
- txn->flags |= 1 << flag;
+ txn->flags |= flag;
}
static inline void
-txn_clear_flag(struct txn *txn, enum txn_flag flag)
+txn_clear_flag(struct txn *txn, unsigned int flag)
{
- txn->flags &= ~(1 << flag);
+ txn->flags &= ~flag;
}
/* Pointer to the current transaction (if any) */
--
2.29.2
More information about the Tarantool-patches
mailing list