net: Make check_next_chunk() mutually exclusive 05/316905/1
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 19 Dec 2024 06:23:47 +0000 (15:23 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 19 Dec 2024 06:58:59 +0000 (15:58 +0900)
commitd8510092c75a5b534705275a38e208bc102615a6
treec4bf48ebf192a8231772b81284f8c30a62f513d1
parent702e8433a34e4576a438b1e5ea8ca8b4d2a2c4cf
net: Make check_next_chunk() mutually exclusive

Since 4004285311 ("Fix the race in data_finished() and resp_finished()"),
Although the possibility of a race between two threads executing
data_finished() and resp_finished() is reduced, it is still possible
to enter the check_next_chunk() function at the same time in certain
circumstances as below:

Thread A  | Thread B
-------------------------------------------------+--------------------------------------------------------------
 | chunk->resp_finished = 1;
chunk->data_finished = 1;  |
if (chunk->resp_finished)      |
check_next_chunk(chunk, transfer);  |
chunk->chunk_number = transfer->chunk_number++;  |
 | if (chunk->data_finished)
 | check_next_chunk(chunk, transfer);
 |      >> chunk->chunk_number = transfer->chunk_number++;
                                                 | <chunk_number becomes unmatched>
chunk->data_finished = chunk->resp_finished = 0; |


To address this, this makes the functions completely mutually exclusive.

Change-Id: I94df217ec82dadc322050693e86763f9c8213d05
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
libthor/thor_net.c