Metadata-Version: 2.1
Name: cengal_memory_barriers
Version: 2.0.0
Summary: Extended, cached CPU info with consistent output format
Project-URL: Homepage, https://github.com/FI-Mihej/cengal_memory_barriers
Author-email: ButenkoMS <gtalk@butenkoms.space>
License-Expression: Apache-2.0
License-File: LICENSE.md
License-File: NOTICE
Keywords: AMD64,ARM,ARMv7,ARMv8,Emscripten,IA-32,IA-64,IA_32,IA_64,Intel64,barrier,barriers,cengal,crossplatform,hardware,memory,memory barrier,memory barriers,x86,x86-32,x86-64,x86_32,x86_64
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Environment :: MacOS X
Classifier: Environment :: Web Environment
Classifier: Environment :: WebAssembly
Classifier: Environment :: Win32 (MS Windows)
Classifier: Environment :: X11 Applications
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Manufacturing
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Telecommunications Industry
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: Android
Classifier: Operating System :: MacOS
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: Microsoft :: Windows :: Windows 7
Classifier: Operating System :: Microsoft :: Windows :: Windows 8
Classifier: Operating System :: Microsoft :: Windows :: Windows 8.1
Classifier: Operating System :: Microsoft :: Windows :: Windows 10
Classifier: Operating System :: Microsoft :: Windows :: Windows 11
Classifier: Operating System :: Microsoft :: Windows :: Windows NT/2000
Classifier: Operating System :: Microsoft :: Windows :: Windows Server 2003
Classifier: Operating System :: Microsoft :: Windows :: Windows Server 2008
Classifier: Operating System :: Microsoft :: Windows :: Windows Vista
Classifier: Operating System :: Microsoft :: Windows :: Windows XP
Classifier: Operating System :: OS Independent
Classifier: Operating System :: POSIX
Classifier: Operating System :: POSIX :: BSD
Classifier: Operating System :: POSIX :: BSD :: FreeBSD
Classifier: Operating System :: POSIX :: BSD :: NetBSD
Classifier: Operating System :: POSIX :: BSD :: OpenBSD
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: Unix
Classifier: Operating System :: iOS
Classifier: Programming Language :: Cython
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: MicroPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System
Classifier: Topic :: System :: Hardware
Classifier: Topic :: System :: Hardware :: Symmetric Multi-processing
Classifier: Typing :: Typed
Requires-Python: >=3.8
Requires-Dist: cengal-light
Description-Content-Type: text/markdown

# cengal_memory_barriers

Fast crossplatform memory barriers for Python.

Memory barriers are utilized by the operating system to implement synchronization primitives, such as Mutexes.

# Advantages

Supported OS: at least ["Linux", "Darwin", "Windows"]. Supported targets: at least ["Emscripten", "ARM", "x86_64", "x86", "i386", "i686", "AMD64"]. "Other" system or target should have "stdatomic.h" header to be supported.

# Installation

```bash
pip install cengal_memory_barriers
```

# Documentation

## Import

```python
from cengal_memory_barriers import full_memory_barrier, mm_pause
```

## Supported systems

| OS \ CPU:                               | x86 ("x86_64", "x86", "i386", "i686", "AMD64") | ARM | Emscripten | Other targets |
|-----------------------------------------|------------------------------------------------|-----|------------|---------------|
| Linux                                   | +                                              | +   | +          | +             |
| Darwin                                  | +                                              | +   | +          | +             |
| Windows                                 | +                                              | +   | +          |               |
| Other systems with "stdatomic.h" header | +                                              | +   | +          | +             |

## Available functions per system

| Func name: \ System:         | Linux/Darwin (x86) | Linux/Darwin (ARM) | Windows (x86) | Windows (ARM) | Emscripten | Other systems with "stdatomic.h" header |
|------------------------------|--------------------|--------------------|---------------|---------------|------------|-----------------------------------------|
| full_memory_barrier()        | +                  | +                  | +             | +             | +          | +                                       |
| memory_barrier()             | +                  | +                  | +             | +             | +          | +                                       |
| sync_synchronize()           | +                  | +                  | +             | +             | +          | +                                       |
|                              |                    |                    |               |               |            |                                         |
| mm_pause()                   | +                  | +                  | +             | +             | +          | +                                       |
| mm_mfence()                  | +                  | +                  | +             | +             | +          | +                                       |
| mm_sfence()                  | +                  | +                  | +             | +             | +          | +                                       |
| mm_lfence()                  | +                  | +                  | +             | +             | +          | +                                       |
|                              |                    |                    |               |               |            |                                         |
| mm_clflush(...)              | +                  |                    | +             |               |            |                                         |
| iso_volatile_store16(...)    |                    |                    |               | +             |            |                                         |
| py_emscripten_atomic_fence() |                    |                    |               |               | +          |                                         |
| clear_cache(...)             | +                  | +                  |               |               |            |                                         |
| py_atomic_thread_fence(...)  | +                  | +                  |               |               | +          | +                                       |
| py_atomic_thread_fence__*()  | +                  | +                  |               |               | +          | +                                       |

## Backend calls - Main functions

| System: \ Func name:                    | `full_memory_barrier()`                   | `memory_barrier()`                        | `sync_synchronize()`                      |
|-----------------------------------------|-------------------------------------------|-------------------------------------------|-------------------------------------------|
| Linux/Darwin (x86)                      | _mm_mfence()                              | _mm_mfence()                              | __sync_synchronize()                      |
| Linux/Darwin (ARM)                      | __sync_synchronize()                      | __sync_synchronize()                      | __sync_synchronize()                      |
| Windows (x86)                           | MemoryBarrier()                           | MemoryBarrier()                           | MemoryBarrier()                           |
| Windows (ARM)                           | MemoryBarrier()                           | MemoryBarrier()                           | MemoryBarrier()                           |
| Emscripten                              | emscripten_atomic_fence()                 | __sync_synchronize()                      | __sync_synchronize()                      |
| Other systems with "stdatomic.h" header | atomic_thread_fence(MEMORY_ORDER_SEQ_CST) | atomic_thread_fence(MEMORY_ORDER_SEQ_CST) | atomic_thread_fence(MEMORY_ORDER_SEQ_CST) |

## Backend calls - Secondary functions

| System: \ Func name:                    | `mm_mfence()`                             | `mm_sfence()`                             | `mm_lfence()`                             | `mm_pause()` |
|-----------------------------------------|-------------------------------------------|-------------------------------------------|-------------------------------------------|--------------|
| Linux/Darwin (x86)                      | _mm_mfence()                              | _mm_sfence()                              | _mm_lfence()                              | _mm_pause()  |
| Linux/Darwin (ARM)                      | __sync_synchronize()                      | __sync_synchronize()                      | __sync_synchronize()                      | pass         |
| Windows (x86)                           | _mm_mfence()                              | _mm_sfence()                              | _mm_lfence()                              | _mm_pause()  |
| Windows (ARM)                           | MemoryBarrier()                           | MemoryBarrier()                           | MemoryBarrier()                           | pass         |
| Emscripten                              | __sync_synchronize()                      | __sync_synchronize()                      | __sync_synchronize()                      | pass         |
| Other systems with "stdatomic.h" header | atomic_thread_fence(MEMORY_ORDER_SEQ_CST) | atomic_thread_fence(MEMORY_ORDER_SEQ_CST) | atomic_thread_fence(MEMORY_ORDER_SEQ_CST) | pass         |

## Backend calls - Unique calls

| Func name:                                     | Backend call:                             |
|------------------------------------------------|-------------------------------------------|
| mm_clflush(p: int) -> None                     | _mm_clflush(...)                          |
| iso_volatile_store16(p: int, val: int) -> None | __iso_volatile_store16(...)               |
| py_emscripten_atomic_fence() -> None           | emscripten_atomic_fence()                 |
| clear_cache(beg: int, end: int) -> None        | __clear_cache(...)                        |
| py_atomic_thread_fence(order: int) -> None     | atomic_thread_fence(...)                  |
| py_atomic_thread_fence__memory_order_relaxed() | atomic_thread_fence(MEMORY_ORDER_RELAXED) |
| py_atomic_thread_fence__memory_order_consume() | atomic_thread_fence(MEMORY_ORDER_CONSUME) |
| py_atomic_thread_fence__memory_order_acquire() | atomic_thread_fence(MEMORY_ORDER_ACQUIRE) |
| py_atomic_thread_fence__memory_order_release() | atomic_thread_fence(MEMORY_ORDER_RELEASE) |
| py_atomic_thread_fence__memory_order_acq_rel() | atomic_thread_fence(MEMORY_ORDER_ACQ_REL) |
| py_atomic_thread_fence__memory_order_seq_cst() | atomic_thread_fence(MEMORY_ORDER_SEQ_CST) |

Alternatives description:
* `clear_cache(beg: int, end: int) -> None` - "Linux", "Darwin" - An alternative to `mm_clflush()` in GCC and Clang compilers
* `iso_volatile_store16(p: int, val: int) -> None` - "Windows" - "ARM" - An alternative to `mm_clflush()` for ARM in Visual Studio compiler
* `py_emscripten_atomic_fence() -> None` - "Emscripten" - Probably can be used as an alternative to `mm_clflush()` for Emscripten

# Based on Cengal

Represents part of Cengal library:
* https://pypi.org/project/cengal/
* https://github.com/FI-Mihej/Cengal

An equivalent import:
```python
from cengal.hardware.memory.barriers import full_memory_barrier, mm_pause
```

Cengal library can be installed by:

```bash
pip install cengal
```


# Projects using Cengal

* [flet_async](https://github.com/FI-Mihej/flet_async) - wrapper which makes [Flet](https://github.com/flet-dev/flet) async and brings booth Cengal.coroutines and asyncio to Flet (Flutter based UI)
* [justpy_containers](https://github.com/FI-Mihej/justpy_containers) - wrapper around [JustPy](https://github.com/justpy-org/justpy) in order to bring more security and more production-needed features to JustPy (VueJS based UI)
* [Bensbach](https://github.com/FI-Mihej/Bensbach) - decompiler from Unreal Engine 3 bytecode to a Lisp-like script and compiler back to Unreal Engine 3 bytecode. Made for a game modding purposes
* [Realistic-Damage-Model-mod-for-Long-War](https://github.com/FI-Mihej/Realistic-Damage-Model-mod-for-Long-War) - Mod for both the original XCOM:EW and the mod Long War. Was made with a Bensbach, which was made with Cengal
* [SmartCATaloguer.com](http://www.smartcataloguer.com/index.html) - TagDB based catalog of images (tags), music albums (genre tags) and apps (categories)

# License

Copyright © 2012-2023 ButenkoMS. All rights reserved.

Licensed under the Apache License, Version 2.0.
