<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Cool, thanks!<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>От:</b> Pavel Tikhomirov <ptikhomirov@virtuozzo.com><br>
<b>Отправлено:</b> 4 ноября 2022 г. 15:56<br>
<b>Кому:</b> Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com><br>
<b>Копия:</b> devel@openvz.org <devel@openvz.org>; Konstantin Khorenko <khorenko@virtuozzo.com><br>
<b>Тема:</b> Re: [PATCH RH9 v4 01/10] drivers/vhost: vhost-blk accelerator for virtio-blk guests</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"><br>
<br>
On 04.11.2022 15:28, Andrey Zhadchenko wrote:<br>
> <br>
> <br>
> On 11/4/22 14:31, Pavel Tikhomirov wrote:<br>
>><br>
>><br>
>> On 01.11.2022 10:25, Andrey Zhadchenko wrote:<br>
>>> +/* It is forbidden to call more than one vhost_blk_flush() <br>
>>> simultaneously */<br>
>>> +static void vhost_blk_flush(struct vhost_blk *blk)<br>
>>> +{<br>
>>> + int flush_bin;<br>
>>> +<br>
>>> + spin_lock(&blk->flush_lock);<br>
>>> + blk->during_flush = 1;<br>
>>> + flush_bin = blk->new_req_bin;<br>
>>> + blk->new_req_bin = (blk->new_req_bin) ? 0 : 1;<br>
>><br>
>> We can use shorter and simpler expression for this:<br>
>><br>
>> blk->new_req_bin = !blk->new_req_bin;<br>
> <br>
> Are you sure C standard actually defines it this way and we are not <br>
> relying on unspecified behavior?<br>
> I thought ! operator only defined for logical expressions<br>
<br>
C99 6.5.3.3.5 says:<br>
"The result of the logical negation operator ! is 0 if the value of its <br>
operand compares<br>
unequal to 0, 1 if the value of its operand compares equal to 0. The <br>
result has type int.<br>
The expression !E is equivalent to (0==E)"<br>
<a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf">https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf</a><br>
<br>
So I don't see any problem comparing new_req_bin of type int to 0.<br>
<br>
> <br>
>><br>
>>> + spin_unlock(&blk->flush_lock);<br>
>><br>
<br>
-- <br>
Best regards, Tikhomirov Pavel<br>
Software Developer, Virtuozzo.<br>
</div>
</span></font></div>
</body>
</html>