On 04.11.2022 15:28, Andrey Zhadchenko wrote:


On 11/4/22 14:31, Pavel Tikhomirov wrote:


On 01.11.2022 10:25, Andrey Zhadchenko wrote:
+/* It is forbidden to call more than one vhost_blk_flush() simultaneously */
+static void vhost_blk_flush(struct vhost_blk *blk)
+{
+    int flush_bin;
+
+    spin_lock(&blk->flush_lock);
+    blk->during_flush = 1;
+    flush_bin = blk->new_req_bin;
+    blk->new_req_bin = (blk->new_req_bin) ? 0 : 1;

We can use shorter and simpler expression for this:

blk->new_req_bin = !blk->new_req_bin;

Are you sure C standard actually defines it this way and we are not relying on unspecified behavior?
I thought ! operator only defined for logical expressions

C99 6.5.3.3.5 says:
"The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int.
The expression !E is equivalent to (0==E)"
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

So I don't see any problem comparing new_req_bin of type int to 0.



+    spin_unlock(&blk->flush_lock);


--
Best regards, Tikhomirov Pavel
Software Developer, Virtuozzo.
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to