forked from FFmpeg/FFmpeg
avutil/crc: use ff_thread_once at av_crc_get_table
Fix tsan warnings. Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
This commit is contained in:
parent
9283a4f19b
commit
8329ae781a
1 changed files with 29 additions and 20 deletions
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "thread.h"
|
||||||
|
#include "avassert.h"
|
||||||
#include "bswap.h"
|
#include "bswap.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
|
@ -291,20 +293,24 @@ static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
|
||||||
#else
|
#else
|
||||||
#define CRC_TABLE_SIZE 1024
|
#define CRC_TABLE_SIZE 1024
|
||||||
#endif
|
#endif
|
||||||
static struct {
|
|
||||||
uint8_t le;
|
|
||||||
uint8_t bits;
|
|
||||||
uint32_t poly;
|
|
||||||
} av_crc_table_params[AV_CRC_MAX] = {
|
|
||||||
[AV_CRC_8_ATM] = { 0, 8, 0x07 },
|
|
||||||
[AV_CRC_16_ANSI] = { 0, 16, 0x8005 },
|
|
||||||
[AV_CRC_16_CCITT] = { 0, 16, 0x1021 },
|
|
||||||
[AV_CRC_24_IEEE] = { 0, 24, 0x864CFB },
|
|
||||||
[AV_CRC_32_IEEE] = { 0, 32, 0x04C11DB7 },
|
|
||||||
[AV_CRC_32_IEEE_LE] = { 1, 32, 0xEDB88320 },
|
|
||||||
[AV_CRC_16_ANSI_LE] = { 1, 16, 0xA001 },
|
|
||||||
};
|
|
||||||
static AVCRC av_crc_table[AV_CRC_MAX][CRC_TABLE_SIZE];
|
static AVCRC av_crc_table[AV_CRC_MAX][CRC_TABLE_SIZE];
|
||||||
|
|
||||||
|
#define DECLARE_CRC_INIT_TABLE_ONCE(id, le, bits, poly) \
|
||||||
|
static AVOnce id ## _once_control = AV_ONCE_INIT; \
|
||||||
|
static void id ## _init_table_once(void) \
|
||||||
|
{ \
|
||||||
|
av_assert0(av_crc_init(av_crc_table[id], le, bits, poly, sizeof(av_crc_table[id])) >= 0); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CRC_INIT_TABLE_ONCE(id) ff_thread_once(&id ## _once_control, id ## _init_table_once)
|
||||||
|
|
||||||
|
DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM, 0, 8, 0x07)
|
||||||
|
DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI, 0, 16, 0x8005)
|
||||||
|
DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT, 0, 16, 0x1021)
|
||||||
|
DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE, 0, 24, 0x864CFB)
|
||||||
|
DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_32_IEEE, 0, 32, 0x04C11DB7)
|
||||||
|
DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_32_IEEE_LE, 1, 32, 0xEDB88320)
|
||||||
|
DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI_LE, 1, 16, 0xA001)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size)
|
int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size)
|
||||||
|
@ -343,13 +349,16 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size)
|
||||||
const AVCRC *av_crc_get_table(AVCRCId crc_id)
|
const AVCRC *av_crc_get_table(AVCRCId crc_id)
|
||||||
{
|
{
|
||||||
#if !CONFIG_HARDCODED_TABLES
|
#if !CONFIG_HARDCODED_TABLES
|
||||||
if (!av_crc_table[crc_id][FF_ARRAY_ELEMS(av_crc_table[crc_id]) - 1])
|
switch (crc_id) {
|
||||||
if (av_crc_init(av_crc_table[crc_id],
|
case AV_CRC_8_ATM: CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM); break;
|
||||||
av_crc_table_params[crc_id].le,
|
case AV_CRC_16_ANSI: CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI); break;
|
||||||
av_crc_table_params[crc_id].bits,
|
case AV_CRC_16_CCITT: CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT); break;
|
||||||
av_crc_table_params[crc_id].poly,
|
case AV_CRC_24_IEEE: CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE); break;
|
||||||
sizeof(av_crc_table[crc_id])) < 0)
|
case AV_CRC_32_IEEE: CRC_INIT_TABLE_ONCE(AV_CRC_32_IEEE); break;
|
||||||
return NULL;
|
case AV_CRC_32_IEEE_LE: CRC_INIT_TABLE_ONCE(AV_CRC_32_IEEE_LE); break;
|
||||||
|
case AV_CRC_16_ANSI_LE: CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI_LE); break;
|
||||||
|
default: av_assert0(0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return av_crc_table[crc_id];
|
return av_crc_table[crc_id];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue