mardi 4 juin 2019

std::atomic on struct bit-fields

I'm modifying some existing open source library and there is a struct (say named as Node) containing bit-fields, e.g.

struct Node {
    uint32_t size:30;
    uint32_t isnull:1;
};

To fit my needs, these fields need to be atomic so I was expecting to use std::atomic for this and faced compile time error:

error: bit-field 'a' has non-integral type 'std::atomic<uint32_t>'

According to documentation, there is a restricted set of types which can be used for std::atomic

Can anyone advise/have idea on how to get functionality of atomic fields with the minimum impact to the existing source code?

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire