Commit Graph
13 Commits
Author SHA1 Message Date
Egor ZhdanandCory Benfield adfa636b4b Make CNIOAtomics and CNIODarwin compatible with C++ interop (#3251)
### Motivation:

This fixes linker errors such as
```
@nonobjc __C.catmc_nio_atomic_uint_least32_t_create_with_existing_storage(Swift.UnsafeMutablePointer<__C.catmc_nio_atomic_uint_least32_t>, Swift.UInt32) -> () in NIOAtomic.swift.o
   NOTE: found '_catmc_nio_atomic_uint_least32_t_create_with_existing_storage' in c-nioatomics.c.o, declaration possibly missing 'extern "C"'
```
when building with Swift/C++ interoperability enabled.

### Modifications:

Wrapped the C declarations a couple of headers in `extern "C" { ... }`
blocks.

### Result:

The project builds successfully with Swift/C++ interop enabled.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-05-23 17:30:27 +00:00
Franz Busch 5cc05490c4 [GHA] Unacceptable language check (#2766)
* [GHA] Unacceptable language check

# Motivation

Next up replacing part of our soundness script that checked for unacceptable language.

# Modification

This PR adds a new GH action that checks for unacceptable language.

# Result

One more script replaced

* PR review

* Change homepage link to repo
2024-07-09 07:56:26 +01:00
Michael StackandCory Benfield ebb271a6a9 Fix failed c++ compile of CNIOAtomics.h (#2518)
Motivation:

    On c++ compile, we get 'error: unknown type name '_Bool' DECLARE_ATOMIC_OPERATIONS(_Bool, _Bool)'

    The c++ compile is happening when SwiftPM builds a module
    with swiftSettings: [.interoperabilityMode(.Cxx)] set and
    where nio is a dependency.

Modifications:

* Sources/CNIOAtomics/include/CNIOAtomics.h

 Conditionally, if __cplusplus, use bool type instead of
 _Bool (a c-type only) for booleans.

Result:

 Compiles where previous it error'd.

After your change, what will change.

 No change other than now it compiles under c++.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-09-20 23:40:54 -07:00
Saleem AbdulrasoolandJohannes Weiss 1595c42b9a CNIOAtomics: define types for uintptr_t and intptr_t (#1401)
On LLP64 hosts, `Int` is mapped to `intptr_t` and `UInt` to `uintptr_t`.
As a result, we need to ensure that we map the atomic extensions to
those types for type conversions.

Add the types for `uintptr_t` and `intptr_t` so that they can be used to
implement `CNIOConcurrencyHelpers` on Windows.

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-02-26 17:07:39 +00:00
Saleem AbdulrasoolandCory Benfield 1832cff669 CNIOAtomics: declare atomic operations using a macro (#1400)
Use a macro to define the interface for the typed atomics.  This reduces
the boiler plate that is expanded by hand.  More importantly, it makes
it easier to add new types in the future.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-02-18 10:24:20 +00:00
Jake 3c879ebbaf Fast atomics (#1263)
Motivation:

The existing Atomic class holds an UnsafeEmbeddedAtomic which holds an OpaquePointer to raw memory for the C atomic. This results in multiple allocations on init. The new NIOAtomic class uses ManagedBufferPointer which tail allocates memory for the C atomic as part of the NIOAtomic class allocation.

Modifications:

Created NIOAtomic class that uses ManagedBufferPointer to allocate memory for the C atomic. Created version of catmc_atomic_* C functions that expect memory to be allocated/deallocated by caller. Created NIOAtomicPrimitive protocol for the new version of catmc_atomic_* functions.

Result:

Purely additive. NIOAtomic is available as a replacement for Atomic which results in fewer memory allocations.
2019-11-28 07:45:05 +00:00
Gwynne Raskind 790827800d Remove cpp_magic.h import and ancient Clang compatibility hack from CNIOAtomics.h (#1111)
The inclusion of `cpp_magic.h` in `CNIOAtomics.h` is unnecessary and pollutes the namespace of anyone else importing the header. NIO now also requires Swift 5, which itself will not be built with a Clang too old to understand `_Nonnull`. Note: Removing the extra import of cpp-magic.h required moving it to the src/ directory to avoid complaints about its inclusion (or lack thereof) in the module's umbrella header.
2019-08-15 10:54:43 +01:00
Gwynne Raskind 584e107928 Rename BOOL to BOOLIFY (#1107)
Prevents conflicts when this header is included in a project using Objective-C.
2019-08-13 09:46:51 +01:00
Gwynne Raskind ab9b8eb701 Remove unused wrapper functions for atomic_flag (#1106)
The `atomic_flag` wrappers (structure, `create` helper, and `destroy` helper) are not referenced from anywhere else in the NIO source tree; they can not be invoked, and appear to serve no purpose. Under sufficiently strict compiler settings, they even cause errors due to the functions lacking prototype declarations.
2019-08-13 09:17:40 +01:00
Johannes Weiss 9bae007a15 use umbrella headers for C modules (#636)
Motivation:

SwiftPM only generates fully usable clang modules for C modules if they
have umbrella headers. Therefore, adding a generated NIO.xcodeproj to
another Xcode project as a sub-project never worked.
To make a header an umbrella header you need to name them _exactly_ like
the module.

Modifications:

give each C module an umbrella header

Result:

generated NIO Xcode projects can be used as sub-projects.
2018-10-19 14:49:43 +01:00
Cory Benfield db88f35d49 Remove unnecessary import in c-atomics.h (#561) 2018-08-09 12:15:32 +01:00
Johannes Weiß 4098832e4e don't use _Nonnull for clang 3.6 (#147) (#154)
Motivation:

Clang 3.6 doesn't know about `_Nonnull` which breaks compilation for our
C atomics.

Modifications:

Defined `_Nonnull` as `__attribute__((nonnull))` which seems to already
be available before clang 3.7.

Result:

NIO compiles with clang 3.6 as the default C compiler.
2018-03-14 22:11:17 +09:00
Johannes Weiß 06f9b1d63b merge ConcurrencyHelpers 2017-11-21 18:32:33 +00:00