Commit Graph
24 Commits
Author SHA1 Message Date
Peter Adams 43931b7a7d Make all imports of CNIOLinux conditional on OS (#1704)
Motivation:

Some users are including NIO in Xcode workspaces
rather than using SPM.  When this is done, if all
imports of CNIOLinux are conditional they can
remove this project from their workspace.

Modifications:

Make all imports of CNIOLinux conditional on Linux,
Android or FreeBSD

Result:

No user visible change.
2020-12-16 10:41:56 +00:00
Johannes Weiss a5e35655e6 fix macOS build & cleanup Thread (#1433)
Motivation:

The macOS build was broken by #1424, also the Thread.swift file became
a bit of a mess with `#if os(...)/#else` everywhere.

Modifications:

- fix macOS build
- cleanup Thread by splitting it into ThreadPosix & ThreadWindows

Result:

- build working again
- cleaner code
2020-03-04 15:12:10 +00:00
Saleem AbdulrasoolandJohannes Weiss 546a84c4e1 Thread: port to Windows (#1424)
This restructures `Thread` to have a more generic representation of a
thread handle.  Using that it is possible to have an implementation of
the threading APIs for Windows.

Similarly, introduce an abstraction over the Thread Specific Key.  This
allows us to abstract away the key type and the usage.

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-03-03 20:21:45 +00:00
Johannes Weiss 6174c9802c add descriptions to EventLoop and NIOThread (#1317)
Motivation:

Certain issues are easier debugged if we can print the thread names.

Modifications:

- add the thread name to SelectableEventLoop's description
- make EventLoop and NIOThread CustomStringConvertible

Result:

easier debugging.
2019-12-19 14:52:03 +00:00
Johannes Weiss 8c6c83c05d NIOThreadPool: backed by NIOThreads (pthreads) instead of DispatchQueues (#1100)
Motivation:

NIOThreadPool was grossly abusing Dispatch to block a large number of
threads for (usually) blocking IO work.

Modifications:

Back the NIOThreadPool by NIOThreads (pthreads) instead of
DispatchQueues.

Result:

Less abuse.
2019-08-09 15:20:53 +01:00
George Barnett 93df43e5ec Fix incorrect closure names in documentation. (#1025)
Motivation:

I noticed some closures were referred to by the wrong name in the
documentation.

Modifications:

Updated the documentation to use the correct names.

Result:

More correct documentation.
2019-06-04 15:23:21 +01:00
Johannes Weiss 14327af193 don't leak pthread_keys (#157)
Motivation:

Previously we leaked `pthread_key`s as we only ever called
`pthread_key_create` but never `pthread_key_delete`. This patch fixes
that.

Modifications:

- made `ThreadSpecificVariable` a class (so we get lifecycle management
  through ARC)
- instead of just storing the value, store `Box<(ThreadSpecificVariable<T>, T)>`
  so we can control the lifecycle of the `ThreadSpecificVariable` as
  needed

Result:

We don't leak `pthread_key`s anymore.
2019-02-26 14:57:47 +00:00
Johannes Weiss 3d3cc6d685 rename FileHandle to NIOFileHandle (#818)
Motivation:

Collisions with Foundation and other standard libraries is painful.

Modifications:

- rename `FileHandle` to `NIOFileHandle`
- rename `Thread` to `NIOThread` (only exposed in docs)

Result:

fewer collisions
2019-02-19 16:52:00 +00:00
Johannes Weiss 7ded801710 Thread's == was public by accident (#819)
Motivation:

Thread's equality function was public by accident.

Modifications:

make Thread's equality function internal

Result:

Thread remains internal
2019-02-14 13:25:49 +00:00
Johannes Weiss cf958fb5a5 ignore pthread_setname_np result (#656)
Motivation:

We have seen pthread_setname_np fail with EPERM in containers, it's
non-critical so best to ignore.

Modifications:

ignore pthread_setname_np's return code.

Result:

works in containers.
2018-11-16 20:01:11 +00:00
Ole Begemann c6acf77fc9 Fix some typos in comments (#543)
Motivation:

I came across a few typos and then went through the entire code base
fixing similar errors when I noticed a pattern.

Modifications:

No changes to the code, just to comments.

Result:

No changes.
2018-08-01 15:57:27 +01:00
Ole Begemann 81307bd24f Fix Unmanaged.fromOpaque() usage in class Thread (#542)
Motivation:

As discussed with Andrew Trick on the Swift Forums, the additional call
to assumingMemoryBound(to:) is redundant here. Unmanaged.fromOpaque
takes a raw pointer, and p is just that.

See https://forums.swift.org/t/withunsafetypepunnedpointer/14540/9
for the discussion.

Modifications:

Deleted an unnecessary call to assumingMemoryBound(to:). With this
change, we follow the intended usage of Unmanaged more closely.

Result:

No material change. We save one redundant UnsafeRawPointer ->
UnsafePointer<ThreadBox> -> UnsafeRawPointer conversion.
2018-08-01 15:29:13 +01:00
Matt Eaton 66e4fdfbba Fixed a few minor typos and some force unwraps (#259)
fix some typos, force unwraps and inconsistencies

Motivation:
Reviewing the code I found a few typos that hindered readability, some unnecessary force unwraps and inconsistencies in the codebase.

Modifications:

- The main file in NIOWebSocketServer now accepts command line arguments
and binds to a passed in host and port like the other server examples do.
- Minor typo fixes
- removed one force unwrap

Result:

- The result of my change will bring the NIOWebSocketServer more inline
with how the NIOHTTP1 and NIOChat servers examples are setup.
- less force unwrapping
- fewer typos

[message edited by @weissi]
2018-04-03 11:44:14 +01:00
Norman Maurer 784c5a7355 Declare ThreadSpecificVariable public (#102)
Motivation:

It's often useful for users to be able to store a thread-specific value (and so also EventLoop specific). We have ThreadSpecificVariable for this which was internal.

Modifications:

Change ThreadSpecificVariable to be public.

Result:

Fixes [#61].
2018-03-06 00:32:05 +09:00
John Connolly fa60fa8c40 Change class func to static on Thread. (#101)
Motivation:
Thread is declared final, so I believe spawnAndRun should be static.

Modifications:
Change class func to static
Result:
More consistent code, and spawnAndRun is statically dispatched.
2018-03-06 00:12:23 +09:00
adamnemecek 0bbed6d72f * removed trailing whitespace (#52) 2018-03-02 15:40:52 +09:00
Johannes Weiß 73a805c7f6 minor stylistic improvements (#36)
Motivation:

Sometimes we deviated from the style the Swift stdlib sets out for no
reason.

Modifications:

Fixed some stylistic deviations.

Result:

Looks more Swift-like.
2018-02-26 15:52:49 +00:00
Norman Maurer 4f75af6582 Allow access to pthread_t via withUnsafe function.
Motivation:

We should better allow access to pthread_t via an withUnsafe function which is more swift-like.

Modifications:

- Add withUnsafePthread and use it
- mark pthread_t as private in Thread.

Result:

More swifty code.
2018-02-12 12:29:07 +01:00
Norman Maurer 0b5d59fd25 Consolidate #if #else blocks and use precondition
Motivation:

We sometimes used fatalError(...) where we really could just use precondation(...). Beside this we can also consolidate the #if #else code for handling Darwin and Linux differently and so make the code easier to maintain.

Modifications:

- Use precondation
- Consoldate #if #else blocks for Thread

Result:

Cleaner and easier to maintain code.
2018-02-12 09:21:14 +01:00
Johannes Weiß ebf351abda implement thread specific values 2018-02-08 17:37:01 +00:00
Norman Maurer 995177fbc6 Support setting Thread affinity and use it with EventLoopGroups 2018-02-06 16:08:57 +01:00
Johannes Weiß b26bfce61e detach threads so we don't leak them 2018-02-08 10:57:51 +00:00
Norman Maurer 71f179e63b Change Thread to be internal as we not expose it to the user 2018-02-08 09:26:53 +01:00
Norman Maurer e1bf447a9a Replace usage of Foundation.Thread with our own Thread that just used…
* Replace usage of Foundation.Thread with our own Thread that just used pthread

* Address comments

* some more docs / comments

* Address comments of cory
2018-02-06 11:45:57 +01:00