Description: Use a mutuex if AtomicU64 is unavailable
 AtomicU64 is not available on Debian architectures armel and powerpc
Author: Peter Michael Green <plugwash

--- rust-pyo3-0.20.2.orig/src/impl_/pymodule.rs
+++ rust-pyo3-0.20.2/src/impl_/pymodule.rs
@@ -2,8 +2,10 @@
 
 use std::cell::UnsafeCell;
 
-#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
+#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10))),target_has_atomic="64"))]
 use std::sync::atomic::{AtomicI64, Ordering};
+#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10))),not(target_has_atomic="64")))]
+use std::sync::Mutex;
 
 #[cfg(not(PyPy))]
 use crate::exceptions::PyImportError;
@@ -15,8 +17,10 @@ pub struct ModuleDef {
     ffi_def: UnsafeCell<ffi::PyModuleDef>,
     initializer: ModuleInitializer,
     /// Interpreter ID where module was initialized (not applicable on PyPy).
-    #[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
+    #[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10))),target_has_atomic="64"))]
     interpreter: AtomicI64,
+    #[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10))),not(target_has_atomic="64")))]
+    interpreter: Mutex<i64>,
     /// Initialized module object, cached to avoid reinitialization.
     module: GILOnceCell<Py<PyModule>>,
 }
@@ -58,8 +62,10 @@ impl ModuleDef {
             ffi_def,
             initializer,
             // -1 is never expected to be a valid interpreter ID
-            #[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))]
+            #[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10))),target_has_atomic="64"))]
             interpreter: AtomicI64::new(-1),
+            #[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10))),not(target_has_atomic="64")))]
+            interpreter: Mutex::new(-1),
             module: GILOnceCell::new(),
         }
     }
@@ -93,6 +99,7 @@ impl ModuleDef {
                 let current_interpreter =
                     unsafe { ffi::PyInterpreterState_GetID(ffi::PyInterpreterState_Get()) };
                 crate::err::error_on_minusone(py, current_interpreter)?;
+                #[cfg(target_has_atomic="64")]
                 if let Err(initialized_interpreter) = self.interpreter.compare_exchange(
                     -1,
                     current_interpreter,
@@ -105,6 +112,18 @@ impl ModuleDef {
                         ));
                     }
                 }
+                #[cfg(not(target_has_atomic="64"))]
+                {
+                    let mut guard  = self.interpreter.lock().unwrap();
+                    if *guard == -1 {
+                        *guard = current_interpreter;
+                    } else if *guard != current_interpreter {
+                        return Err(PyImportError::new_err(
+                            "PyO3 modules do not yet support subinterpreters, see https://github.com/PyO3/pyo3/issues/576",
+                        ));
+                    }
+                }
+
             }
             #[cfg(not(all(Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10))))))]
             {
