MinGW: Fix errors due to Native TLS with

This commit is contained in:
Robin Gareus
2026-06-24 21:04:17 +02:00
parent 27783db5ed
commit b168ce622c
3 changed files with 33 additions and 0 deletions
+8
View File
@@ -52,6 +52,14 @@ SerializedRCUManager<TempoMap> TempoMap::_map_mgr (0);
thread_local TempoMap::SharedPtr TempoMap::_tempo_map_p;
PBD::Signal<void()> TempoMap::MapChanged;
#ifdef MINGW_NATIVE_TLS
TempoMap::SharedPtr&
TempoMap::_tempo_map_ref ()
{
return _tempo_map_p;
}
#endif
#ifndef NDEBUG
#define TEMPO_MAP_ASSERT(expr) TempoMap::map_assert(expr, #expr, __FILE__, __LINE__)
#else
+16
View File
@@ -753,6 +753,12 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
typedef std::shared_ptr<TempoMap> WritableSharedPtr;
private:
static thread_local SharedPtr _tempo_map_p;
#ifdef MINGW_NATIVE_TLS
/* Due to Native TLS recently being added, errors come from
thread_local variables during external linkage.
See https://github.com/msys2/MINGW-packages/issues/29272 */
static LIBTEMPORAL_API SharedPtr& _tempo_map_ref ();
#endif
static SerializedRCUManager<TempoMap> _map_mgr;
static bool fetch_condition ();
public:
@@ -762,9 +768,15 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
public:
LIBTEMPORAL_API static void init ();
#ifndef MINGW_NATIVE_TLS
LIBTEMPORAL_API static void update_thread_tempo_map() { _tempo_map_p = _map_mgr.reader(); }
LIBTEMPORAL_API static SharedPtr use() { assert (_tempo_map_p); return _tempo_map_p; }
LIBTEMPORAL_API static SharedPtr fetch() { assert (fetch_condition()); update_thread_tempo_map(); return _tempo_map_p; }
#else
LIBTEMPORAL_API static void update_thread_tempo_map() { _tempo_map_ref() = _map_mgr.reader(); }
LIBTEMPORAL_API static SharedPtr use() { assert (_tempo_map_ref()); return _tempo_map_ref(); }
LIBTEMPORAL_API static SharedPtr fetch() { assert (fetch_condition()); update_thread_tempo_map(); return _tempo_map_ref(); }
#endif
/* No fetch condition for this, to be used only in association with LocalTempoMapScope */
LIBTEMPORAL_API static SharedPtr global_fetch() { return _map_mgr.reader(); }
@@ -778,7 +790,11 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
* can be used on either a write_copy()'ed map, or one obtained via the
* RCU reader() method.
*/
#ifndef MINGW_NATIVE_TLS
LIBTEMPORAL_API static void set (SharedPtr new_map) { _tempo_map_p = new_map; }
#else
LIBTEMPORAL_API static void set (SharedPtr new_map) { _tempo_map_ref() = new_map; }
#endif
/* API for typical tempo map changes */
+9
View File
@@ -1272,6 +1272,15 @@ int main () { return 0; }
# conf.env.append_value('CFLAGS', '-DUSE_PTW32_SEMAPHORE')
# conf.env.append_value('CXXFLAGS', '-DUSE_PTW32_SEMAPHORE')
# Check if GCC was built with native TLS support
# gcc -v prints configure flags to stderr, not stdout
gcc_config = subprocess.run([str(conf.env['CC'][0]), '-v'], capture_output=True, text=True).stderr
have_native_tls = '--enable-tls' in gcc_config
if have_native_tls:
conf.env.append_value('CFLAGS', '-DMINGW_NATIVE_TLS')
conf.env.append_value('CXXFLAGS', '-DMINGW_NATIVE_TLS')
if Options.options.dist_target == 'msvc':
conf.env.append_value('CFLAGS', '-DPLATFORM_WINDOWS')
conf.env.append_value('CFLAGS', '-DCOMPILER_MSVC')