History

demux/stheader: use atomic types for mp_codec_params names

Notably they are exchanged between demux and decode thread. It's fine because we know those pointers will be alive as long as avctx is alive. And only the value may change during decoding in rare situations. Make those pointers atomic for the sake of it. It shouldn't change anything, except some codegen. From https://www.gnu.org/software/libc/manual/html_node/Atomic-Types.html#Atomic-Types: In practice, you can assume that int is atomic. You can also assume that pointer types are atomic; that is very convenient. Both of these assumptions are true on all of the machines that the GNU C Library supports and on all POSIX systems we know of.

Kacper Michajłow committed 1 year ago

Commit 6294e481 parent e9c895f2 files · +7 −6Browse files

Unified · Split

2 files
  1. demux/stheader.h +6 −5
  2. sub/sd_ass.c +1 −1
demux/stheader.h+6−5
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 #ifndef MPLAYER_STHEADER_H
1919 #define MPLAYER_STHEADER_H
2020
21+#include <stdatomic.h>
2122 #include <stdbool.h>
2223
2324 #include "common/common.h"
@@ -70,19 +71,19 @@ struct mp_codec_params { · 46 unmodified lines
7071 enum stream_type type;
7172
7273 // E.g. "h264" (usually corresponds to AVCodecDescriptor.name)
73− const char *codec;
74+ const char *_Atomic codec;
7475
7576 // Usually corresponds to AVCodecDescriptor.long_name
76− const char *codec_desc;
77+ const char *_Atomic codec_desc;
7778
7879 // Corresponding codec profile
79− const char *codec_profile;
80+ const char *_Atomic codec_profile;
8081
8182 // E.g. "h264" (usually corresponds to AVCodec.name)
82− const char *decoder;
83+ const char *_Atomic decoder;
8384
8485 // Usually corresponds to AVCodec.long_name
85− const char *decoder_desc;
86+ const char *_Atomic decoder_desc;
8687
8788 // Usually a FourCC, exact meaning depends on codec.
8889 unsigned int codec_tag;
sub/sd_ass.c+1−1
@@ -316,7 +316,7 @@ static int init(struct sd *sd) · 315 unmodified lines
316316 ctx->packer = mp_ass_packer_alloc(ctx);
317317
318318 // Subtitles does not have any profile value, so put the converted type as a profile.
319− const char **desc = ctx->converter ? &sd->codec->codec_profile : &sd->codec->codec_desc;
319+ const char *_Atomic *desc = ctx->converter ? &sd->codec->codec_profile : &sd->codec->codec_desc;
320320 switch (ctx->ass_track->track_type) {
321321 case TRACK_TYPE_ASS:
322322 *desc = "Advanced Sub Station Alpha";

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t