[PATCH] erofs-utils: lib: introduce atomic operations
Gao Xiang
hsiangkao at linux.alibaba.com
Thu Feb 29 01:39:46 AEDT 2024
On 2024/2/28 21:22, Yifan Zhao wrote:
>
> On 2/28/24 16:21, Gao Xiang wrote:
>> Add some helpers (relaxed semantics) in order to prepare for the
>> upcoming multi-threaded support.
>>
>> For example, compressor may be initialized more than once in different
>> worker threads, resulting in noisy warnings.
>>
>> This patch makes sure that each message will be printed only once by
>> adding `__warnonce` atomic booleans to each erofs_compressor_init().
>>
>> Cc: Yifan Zhao<zhaoyifan at sjtu.edu.cn>
>> Signed-off-by: Gao Xiang<hsiangkao at linux.alibaba.com>
>> ---
>> include/erofs/atomic.h | 27 +++++++++++++++++++++++++++
>> lib/compressor_deflate.c | 11 ++++++++---
>> lib/compressor_libdeflate.c | 6 +++++-
>> lib/compressor_liblzma.c | 5 ++++-
>> 4 files changed, 44 insertions(+), 5 deletions(-)
>> create mode 100644 include/erofs/atomic.h
>>
>> diff --git a/include/erofs/atomic.h b/include/erofs/atomic.h
>> new file mode 100644
>> index 0000000..c486491
>> --- /dev/null
>> +++ b/include/erofs/atomic.h
>> @@ -0,0 +1,27 @@
>> +/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
>> +/*
>> + * Copyright (C) 2024 Alibaba Cloud
>> + */
>> +#ifndef __EROFS_ATOMIC_H
>> +#define __EROFS_ATOMIC_H
>> +
>> +/*
>> + * Just use GCC/clang built-in functions for now
>> + * See:https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
>> + */
>> +typedef unsigned long erofs_atomic_t;
>
> According to [1] *__atomic_test_and_set *should**only be used for operands of type bool or char.
>
> [1] https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
>
> Maybe add
>
> /typedef bool erofs_atomic_bool_t;
> /
>
> for this purpose?
>
> Otherwise LGTM and I will include it in my patchset.
Ok, I'm fine with that. you could revise it directly.
Thanks,
Gao Xiang
More information about the Linux-erofs
mailing list