aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix/posix_thread.c
Commit message (Collapse)AuthorAge
* platform: remove reader/writer locksGarrett D'Amore2025-01-05
| | | | | | The only thing using this was the transport lookups, but as those transports are now fully initialized in nng_init, we no longer need to lock that at all.
* pthreads: avoid double indirection for cv mutexGarrett D'Amore2025-01-05
|
* Cleanup POSIX platform initialization.Garrett D'Amore2024-11-11
| | | | | This also avoids a potential leak of thread attributes. although no current platform actually seems to do so.
* refactor initialization/finalizationGarrett D'Amore2024-11-11
| | | | | | | | | Applications must now call nng_init(), but they can supply a set of parameters optionally. The code is now safe for multiple libraries to do this concurrently, meaning nng_fini no longer can race against another instance starting up. The nni_init checks on all public APIs are removed now.
* Use static initialization for lists and mutexes.Garrett D'Amore2021-12-05
| | | | | | This eliminates some run-time initialization, moving it to compile time. Additional follow up work will expand on this to simplify initialization and reduce the need for certain locks.
* fixes #1409 reader/writer lock desiredGarrett D'Amore2021-07-11
| | | | | | This provides the initial implementation, and converts the transport lookup routines to use it. This is probably of limited performance benefit, but rwlock's may be useful in further future work.
* fix implicit declaration warnings for pthread_set_name_np on OpenBSD (#1425)Dave Voutila2021-03-11
| | | | | | OpenBSD requires an additional header for both pthread_set_name_np and pthread_get_name_np. See http://man.openbsd.org/pthread_set_name_np for details.
* Build fix for NetBSD (#1433)Pierre Pronchery2021-03-11
|
* fixes #1363 build ios version failsGarrett D'Amore2020-12-27
|
* fixes #960 NNG threads inherit application thread nameGarrett D'Amore2020-08-08
| | | | | | This also exposes an nng_thread_set_name() function for applications to use. All NNG thread names start with "nng:". Note that support is highly dependent on the operating system.
* fixes #767 Want tunable stack sizeGarrett D'Amore2018-10-31
|
* fixes #572 Several locking errors foundGarrett D'Amore2018-07-03
| | | | | | | | | | fixes #573 atomic flags could help This introduces a new atomic flag, and reduces some of the global locking. The lock refactoring work is not yet complete, but this is a positive step forward, and should help with certain things. While here we also fixed a compile warning due to incorrect types.
* fixes #32 autoscale based on CPUs availableGarrett D'Amore2018-06-12
| | | | | | This should work on both Windows and the most common POSIX variants. We will create at least two threads for running completions, but there are numerous other threads in the code.
* fixes #488 pthread mutex initializer could be simplerGarrett D'Amore2018-05-29
| | | | | | | The fallback logic was unnecessarily complicated, and found to be somewhat data-racy; on modern systems initializing these things never fails, and on BSD systems that only occurs under extreme memory shortage.
* fixes #352 aio lock is burning hotGarrett D'Amore2018-05-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #326 consider nni_taskq_exec_synch() fixes #410 kqueue implementation could be smarter fixes #411 epoll_implementation could be smarter fixes #426 synchronous completion can lead to panic fixes #421 pipe close race condition/duplicate destroy This is a major refactoring of two significant parts of the code base, which are closely interrelated. First the aio and taskq framework have undergone a number of simplifications, and improvements. We have ditched a few parts of the internal API (for example tasks no longer support cancellation) that weren't terribly useful but added a lot of complexity, and we've made aio_schedule something that now checks for cancellation or other "premature" completions. The aio framework now uses the tasks more tightly, so that aio wait can devolve into just nni_task_wait(). We did have to add a "task_prep()" step to prevent race conditions. Second, the entire POSIX poller framework has been simplified, and made more robust, and more scalable. There were some fairly inherent race conditions around the shutdown/close code, where we *thought* we were synchronizing against the other thread, but weren't doing so adequately. With a cleaner design, we've been able to tighten up the implementation to remove these race conditions, while substantially reducing the chance for lock contention, thereby improving scalability. The illumos poller also got a performance boost by polling for multiple events. In highly "busy" systems, we expect to see vast reductions in lock contention, and therefore greater scalability, in addition to overall improved reliability. One area where we currently can do better is that there is still only a single poller thread run. Scaling this out is a task that has to be done differently for each poller, and carefuly to ensure that close conditions are safe on all pollers, and that no chance for deadlock/livelock waiting for pfd finalizers can occur.
* fixes #234 Investigate enabling more verbose compiler warningsGarrett D'Amore2018-02-14
| | | | | | | We enabled verbose compiler warnings, and found a lot of issues. Some of these were even real bugs. As a bonus, we actually save some initialization steps in the compat layer, and avoid passing some variables we don't need.
* fixes #206 Want NNG_OPT_TLS_VERIFIED optionGarrett D'Amore2018-01-16
| | | | | | | | | | | | | | It is useful to have support for validating that a peer *was* verified, especially in the presence of optional validation. We have added a property that does this, NNG_OPT_TLS_VERIFIED. Further, all the old NNG_OPT_WSS_TLS_* property names have also been renamed to generic NNG_OPT_TLS property names, which have been moved to nng.h to facilitate reuse and sharing, with the comments moved and corrected as well. Finally, the man pages have been updated, with substantial improvements to the nng_ws man page in particular.
* fixes #84 Consider using msec for durationsGarrett D'Amore2017-10-19
| | | | | | There is now a public nng_duration type. We have also updated the zerotier work to work with the signed int64_t's that the latst ZeroTier dev branch is using.
* Conditional platform inclusion cleanups.Garrett D'Amore2017-08-21
| | | | | | | | | | We only compile files that are appropriate for the platform. (We still have guards in place, to allow for a future single .C file to be built from all the sources.) We also remove the subsystem defines; if a new platform needs to deviate from POSIX in ways beyond what we intended here, then that platform should just copy those parts into a new platform directory, rather than cross including portions from POSIX.
* Provide versions of mutex, condvar, and aio init that never fail.Garrett D'Amore2017-08-16
| | | | | | | | | | | | | | | | | | | | | | | If the underlying platform fails (FreeBSD is the only one I'm aware of that does this!), we use a global lock or condition variable instead. This means that our lock initializers never ever fail. Probably we could eliminate most of this for Linux and Darwin, since on those platforms, mutex and condvar initialization reasonably never fails. Initial benchmarks show little difference either way -- so we can revisit (optimize) later. This removes a lot of otherwise untested code in error cases and so forth, improving coverage and resilience in the face of allocation failures. Platforms other than POSIX should follow a similar pattern if they need this. (VxWorks, I'm thinking of you.) Most sane platforms won't have an issue here, since normally these initializations do not need to allocate memory. (Reportedly, even FreeBSD has plans to "fix" this in libthr2.) While here, some bugs were fixed in initialization & teardown. The fallback code is properly tested with dedicated test cases.
* Thundering herd kills performance.Garrett D'Amore2017-08-10
| | | | | | | | | | | | | | A little benchmarking showed that we were encountering far too many wakeups, leading to severe performance degradation; we had a bunch of threads all sleeping on the same condition variable (taskqs) and this woke them all up, resulting in heavy mutex contention. Since we only need one of the threads to wake, and we don't care which one, let's just wake only one. This reduced RTT latency from about 240 us down to about 30 s. (1/8 of the former cost.) There's still a bunch of tuning to do; performance remains worse than we would like.
* Yet more race condition fixes.Garrett D'Amore2017-07-20
| | | | | | | | | We need to remember that protocol stops can run synchronously, and therefore we need to wait for the aio to complete. Further, we need to break apart shutting down aio activity from deallocation, as we need to shut down *all* async activity before deallocating *anything*. Noticed that we had a pipe race in the surveyor pattern too.
* Give up on uncrustify; switch to clang-format.Garrett D'Amore2017-07-10
|
* TCP asynchronous working now.Garrett D'Amore2017-07-07
| | | | | | | | | | | | | | | | It turns out that I had to fix a number of subtle asynchronous handling bugs, but now TCP is fully asynchronous. We need to change the high-level dial and listen interfaces to be async as well. Some of the transport APIs have changed here, and I've elected to change what we expose to consumers as endpoints into seperate dialers and listeners. Under the hood they are the same, but it turns out that its helpful to know the intended use of the endpoint at initialization time. Scalability still occasionally hangs on Linux. Investigation pending.
* Fixes for async resolver, plus a test suite for it.Garrett D'Amore2017-07-06
|
* Separate out poller/pollq from basic socket operations.Garrett D'Amore2017-07-04
|
* Convert to POSIX polled I/O for async; start of cancelable aio.Garrett D'Amore2017-06-27
| | | | | | | | | | | | | | | | | | This eliminates the two threads per pipe that were being used to provide basic I/O handling, replacing them with a single global thread for now, that uses poll and nonblocking I/O. This should lead to great scalability. The infrastructure is in place to easily expand to multiple polling worker threads. Some thought needs to be given about how to scale this to engage multiple CPUs. Horizontal scaling may also shorten the poll() lists easing C10K problem. We should look into better solutions than poll() for platforms that have them (epoll on Linux, kqueue on BSD, and event ports on illumos). Note that the file descriptors start out in blocking mode for now, but then are placed into non-blocking mode. This is because the negotiation phase is not yet callback driven, and so needs to be synchronous.
* Adding mutex lock during fini to prevent false positive data race.Garrett D'Amore2017-06-25
|
* Clear the owner while *still* holding the lock.Garrett D'Amore2017-06-25
|
* Additional mutex debugging support.Garrett D'Amore2017-06-22
|
* Expose a library finalizer suitable for atexit().Garrett D'Amore2017-06-21
|
* Initial start of compat layer with bind, connect, etc. Untested.Garrett D'Amore2017-01-22
|
* Fix synchronization problem in msgqueue with multiple consumers.Garrett D'Amore2017-01-19
|
* Start of event framework.Garrett D'Amore2017-01-16
| | | | | | | | | | This compiles correctly, but doesn't actually deliver events yet. As part of this, I've made most of the initializables in nng safe to tear-down if uninitialized (or set to zero e.g. via calloc). This makes it loads easier to write the teardown on error code, since I can deinit everything, without worrying about which things have been initialized and which have not.
* Compile static *and* shared libraries.Garrett D'Amore2017-01-15
| | | | | Test code needs to use the static libraries so that they can get access to the entire set of symbols, including private ones that are not exported.
* Windows TCP now working.Garrett D'Amore2017-01-14
| | | | | | | There are lots of changes here, mostly stuff we did in support of Windows TCP. However, there are some bugs that were fixed, and we added some new error codes, and generalized the handling of some failures during accept. Windows IPC (NamedPipes) is still missing.
* Many fixes for Windows. It compiles, and some tests work.Garrett D'Amore2017-01-13
| | | | | | Windows is getting there. Needs a couple of more more hours to enable everything, especially IPC, and most of the work at this point is probably some combination of debug and tweaking things like error handling.
* Block SIGPIPE. Ewww...Garrett D'Amore2017-01-12
|
* New ISAAC pRNG. This replaces other local hacks for random data.Garrett D'Amore2017-01-08
| | | | | | Platforms must seed the pRNGs by offering an nni_plat_seed_prng() routine. Implementations for POSIX using various options (including the /dev/urandom device) are supplied.
* Change a bunch of copyrights to 2017 for work done since the 1st.Garrett D'Amore2017-01-05
|
* Fix close related races (POSIX close is a PITA).Garrett D'Amore2017-01-04
|
* Stack related fixes for valgrind platform test.Garrett D'Amore2017-01-01
|
* Final purge of old threading & synch stuff.Garrett D'Amore2017-01-01
|
* Pipe simplifications for thread management.Garrett D'Amore2017-01-01
| | | | | | | This may also address a race in closing down pipes. Now pipes are always registered with the socket. They also always have both a sender and receiver thread. If the protocol doesn't need one or the other, the stock thread just exits early.
* New thread infrastructure -- not used anywhere yet, but tested.Garrett D'Amore2017-01-01
|
* Substantial fixes for listen & dialers.Garrett D'Amore2016-12-25
| | | | | | | | | | At this point listening and dialing operations appear to function properly. As part of this I had to break the close logic up since otherwise we had a loop trying to reap a thread from itself. So there is now a separate reaper thread for pipes per-socket. I also changed lists to be a bit more rigid, and allocations now zero memory initially. (We had bugs due to uninitialized memory, and rather than hunt them all down, lets just init them to sane zero values.)
* Mix the PID into our random number seed.Garrett D'Amore2016-12-25
|
* Try to satisfy uncrustify version differences. Make test use verbose by ↵Garrett D'Amore2016-12-23
| | | | default.
* Uncrustify fixes.Garrett D'Amore2016-12-23
|
* Endpoint dialer implemented.Garrett D'Amore2016-12-22
|