Coder Social home page Coder Social logo

ptumati / swift-atomics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from glessard/swift-atomics

0.0 2.0 0.0 272 KB

Atomic operations bridged from Clang to Swift

License: BSD 3-Clause "New" or "Revised" License

Swift 86.98% C 9.71% Shell 3.31%

swift-atomics's Introduction

swift-atomics Build Status

Some atomic functions from Clang in Swift

The atomic functions available in /usr/include/libkern/OSAtomic.h are quite limiting in Swift, due to the type system. Furthermore, some simple things such as a synchronized load or a synchronized store are not immediately available. On top of that, they have now been deprecated.

Clang, on the other hand, has an implementation of the C11 atomic functions built-in. They're also available on Linux.

This project bridges a subset of Clang's C11 atomics support to Swift.

The following Swift types are implemented:

  • AtomicPointer, AtomicMutablePointer, AtomicRawPointer, AtomicMutableRawPointer and AtomicOpaquePointer;
  • AtomicInt and AtomicUInt, AtomicInt32 and AtomicUInt32, AtomicInt64 and AtomicUInt64;
  • AtomicBool

The pointer types have the following methods:

  • load, store, swap and CAS

The integer types have the following methods:

  • load, store, swap, CAS, add, subtract, increment, decrement, bitwiseAnd, bitwiseOr and bitwiseXor

The memory order (from <stdatomic.h>) can be set by using the order parameter on each method; the default is .relaxed for the integer types (it is sufficient for counter operations, the most common application,) and .sequential for pointer types.

The integer types also have a value property, as a convenient way to perform a .relaxed load. The pointer types have a pointer property for the same purpose.

These types should be used as members of reference types, or captured by closures. They are implemented as structs so that using them does not automatically incur additional memory allocation. They should not be used members of another struct, since that would result in violations the law-of-exclusivity.

This library requires Swift 3.0 or later. On Linux, it also requires Clang 3.6 or later.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.