Commit Graph

71 Commits

Author SHA1 Message Date
ridiculousfish
bde2f2111d Introduce debounce_t
debounce_t will be used to limit thread creation from background highlighting
and autosuggestion scenarios. This is a one-element queue backed by a
single thread. New requests displace any existing queued request; this
reflects the fact that autosuggestions and highlighting only care about
the most recent result.

A timeout allows for abandoning hung threads, which may happen if you
attempt to e.g. access a dead hard-mounted NFS server. We don't want
this to defeat autosuggestions and highlighting permanently, so allow
spawning a new thread after the timeout (here 500 ms).
2020-03-06 17:15:21 -08:00
Rosen Penev
925c7a998a [clang-tidy] mark single argument constructors explicit
Found with hicpp-explicit-conversions

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:17 +01:00
Fabian Homborg
f79ff72096 iothread: include cstdint, correctly
Yeah, this was needed in the *header*.

God I hate headers.

Fixes #6604, for real this time
2020-02-14 20:52:14 +01:00
Fabian Homborg
d80d39dd6a iothread: Include cstdint
For uint64_t.

Needed for some configurations with glibc.

Fixes #6604.
2020-02-14 20:43:05 +01:00
David Adam
696057ab57 Merge branch 'Integration_3.1.0' 2020-01-30 17:31:43 +08:00
David Adam
b313ba555a iothread: add missing #include
Closes #6553.
2020-01-30 17:21:15 +08:00
Fabian Homborg
3bb15defbb
Replace debug() with flog
PR #6511 

Flog has the advantage of having *categories*, not severities, so it'll be easier to get output for a certain subsystem now.
2020-01-26 14:13:17 +01:00
ridiculousfish
e398f66772 Run clang-format 2020-01-21 14:43:17 -08:00
Fabian Homborg
4cb3ce0314 Add a 5 debug to the iothread flog 2020-01-19 14:55:39 +01:00
ridiculousfish
c14d54032f Add a cant_wait parameter to iothread_perform
Sometimes we must spawn a new thread, to avoid the risk of deadlock.
Ensure we always spawn a thread in those cases. In particular this
includes the fillthread.
2020-01-18 11:51:13 -08:00
Fabian Homborg
018e51c935 Just hardcode a thread limit of 1024
64 is too low (it's actually reachable), and every sensible system should have a limit above
this.

On OpenBSD and FreeBSD it's ULONG_MAX, on my linux system it's 61990.

Plus we currently fail by hanging if our limit is reached, so this
should improve things regardless.

On my linux system _POSIX_THREAD_THREADS_MAX works out to 64 here,
which is just too low, even tho the system can handle more.

Fixes #6503 harder.
2020-01-18 10:30:32 +01:00
Fabian Homborg
ca08cc331b Use PTHREAD_THREADS_MAX if available
Stops us deadlocking on OpenBSD if we need more than 4 threads.

Fixes #6503
2020-01-18 09:07:31 +01:00
ridiculousfish
8bf9f52461 Always detach new pthreads
There are no longer any calls to pthread_join. Just make all pthreads
detached.
2019-12-16 14:08:46 -08:00
Rosen Penev
6f4a9d527c [clang-tidy] Use C++ using instead of C typedef
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
ridiculousfish
106af5f56a Migrate some iothread functions into member functions of thread_pool_t
This reintroduces commits 22230a1a0d
and 9d7d70c204, now with the bug fixed.

The problem was when there was one thread waiting in the pool. We enqueue
an item onto the pool and attempt to wake up the thread. But before the
thread runs, we enqueue another item - this second enqueue will see the
thread waiting and attempt to wake it up as well. If the two work items
were dependent (reader/writer) then we would have a deadlock.

The fix is to check if the number of waiting threads is at least as large
as the queue. If the number of enqueued items exceeds the number of waiting
threads, then spawn a new thread always.
2019-11-27 12:03:56 -08:00
Rosen Penev
1055ff321c [clang-tidy] Replace NULL with nullptr
Found with modernize-use-nullptr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:23:03 -08:00
ridiculousfish
80a4898e75 Revert "Migrate some iothread functions into member functions of thread_pool_t"
This reverts commit 22230a1a0d.
Also 9d7d70c204

There's some subtle bug here, needs to be tracked down and tested.
2019-11-23 23:35:34 -08:00
ridiculousfish
22230a1a0d Migrate some iothread functions into member functions of thread_pool_t 2019-11-23 14:05:26 -08:00
ridiculousfish
9d7d70c204 Clean up some iothreads
Improve the iothread behavior by enabling an iothread to stick around for
a while waiting for work. This reduces the amount of iothread churn, which
is useful on platforms where threads are expensive.

Also do other modernization like clean up the locking discipline and use
FLOG.
2019-11-23 13:44:27 -08:00
ridiculousfish
3fb9159b09 Rename spawn_request_t to work_request_t and clean up the API a bit 2019-11-23 12:13:30 -08:00
ridiculousfish
82eca4bc86 Run clang-format on all files
The main change here is to reorder headers.
2019-10-13 15:50:48 -07:00
ridiculousfish
d1fc8d5f71 Improve the iothread port structure
Mark both fds in the ioport as non-blocking, and allow bulk reads.
2019-06-03 16:42:51 -07:00
Fabian Homborg
87971e1f2e Widen the rest of the FLOGs
Fixes #5900.
2019-05-30 13:08:35 +02:00
Fabian Homborg
d73ee4d54b More using FLOGF when formatting is needed
sed-patched, every time a "%" is used in a call to `FLOG`, we use
`FLOGF` instead.
2019-05-30 11:54:09 +02:00
ridiculousfish
0863c237b0 Make thread_id a visible thing
Every thread now has a non-recyclable thread id. This will be an aid in
debugging.
2019-05-29 12:34:11 -07:00
ridiculousfish
ea9d1ad82f Convert debug(0) calls to FLOG 2019-05-27 17:31:17 -07:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
ridiculousfish
fe68287cb0 Make miscellaneous variables thread-safe 2019-05-04 20:58:35 -07:00
ridiculousfish
ec522e5978 Migrate s_main_thread_request_queue to owning_lock 2019-05-04 20:42:56 -07:00
Aaron Gyes
aaacdb89b6 Switches over to cstring from string.h. 2019-03-12 15:09:36 -07:00
Aaron Gyes
d5ac239f68 This commit changes wchar.h includes to cwchar, and uses std::
for everything it provides.
2019-03-12 15:09:36 -07:00
Fabian Homborg
7508865374 Include string.h where we use memset
This is needed on Solaris/Illumos/OpenIndiana/SunOS.

Presumably it's harmless elsewhere.
2019-02-13 13:27:20 +01:00
ridiculousfish
ec29a5b913 Introduce make_pthread
This allows creating a pthread directly, which can be joined.
iothread_spawn wraps this.
2019-02-03 01:58:49 -08:00
ridiculousfish
6ba0d4c88a Revert io_bufferfill_t stack
This reverts commit 88dc484858 onwards.
2019-02-02 17:53:40 -08:00
ridiculousfish
6e0dd06f43 Introduce make_pthread
This allows creating a pthread directly, which can be joined.
iothread_spawn wraps this.
2019-02-02 14:21:46 -08:00
Mahmoud Al-Qudsi
bfe08a471d Remove fish_mutex_t wrapper around std::mutex
@ridiculousfish had introduced this in 3a45cad12e
to work around an issue with Coverity Scan where it couldn't tell the
mutex was correctly locked, but even with the `fish_mutex_t` hack, it
still emits the same warnings, so there's no pointing in keeping it.
2018-12-30 20:37:36 -06:00
ridiculousfish
051605b593 Cleap up owning_lock interface
Use some operator overloading to avoid the weird interface of acquired_lock.
2018-09-01 13:11:42 -07:00
ridiculousfish
74e6a82849 Remove explicit 'void' parameters. 2018-02-18 19:12:45 -08:00
ridiculousfish
3a45cad12e Introduce fish_mutex_t wrapping std::mutex
Add a fish-specific wrapper around std::mutex that records whether it is
locked in a bool. This is to make ASSERT_IS_LOCKED() simpler (it can just
check the boolean instead of relying on try_lock) which will make Coverity
Scan happier.

Some details: Coverity Scan was complaining about an apparent double-unlock
because it's unaware of the semantics of try_lock(). Specifically fish
asserts that a lock is locked by asserting that try_lock fails; if it
succeeds fish prints an error and then unlocks the lock (so as not to leave
it locked). This unlock is of course correct, but it confused Coverity Scan.
2018-02-08 22:18:59 -08:00
Peter Ammon
1413e20ed4 Fix thread sanitizer errors in iothread
This uses an atomic bool for main_thread_request_t::done.

Fixes #3895
2017-09-11 15:50:41 -07:00
Mahmoud Al-Qudsi
e76c1fd139 Remove custom lock types in favor of native C++11 mutexes
No longer using RAII wrappers around pthread_mutex_t and pthread_cond_t
in favor of the C++11 std::mutex, std::recursive_mutex, and
std::condition_variable data types.
2017-08-18 23:09:31 -05:00
Kurtis Rader
82f5fb507d fix echo -h
In addition to fixing `echo -h` this includes some debugging related
cleanups I made while investigating the issue.

Fixes #4120
2017-06-18 22:10:19 -07:00
Kurtis Rader
4ad5b756e4 more sanity involving fatal errors
This folds the "VOMIT_*" family of macros into the assert and DIE
family.

Another change related to issue #3276.
2017-02-14 21:09:15 -08:00
Kurtis Rader
509ee64fc9 implement our own assert() function
I recently upgraded the software on my macOS server and was dismayed to
see that cppcheck reported a huge number of format string errors due to
mismatches between the format string and its arguments from calls to
`assert()`. It turns out they are due to the macOS header using `%lu`
for the line number which is obviously wrong since it is using the C
preprocessor `__LINE__` symbol which evaluates to a signed int.

I also noticed that the macOS implementation writes to stdout, rather
than stderr. It also uses `printf()` which can be a problem on some
platforms if the stream is already in wide mode which is the normal case
for fish.

So implement our own `assert()` implementation. This also eliminates
double-negative warnings that we get from some of our calls to
`assert()` on some platforms by oclint.

Also reimplement the `DIE()` macro in terms of our internal
implementation.

Rewrite `assert(0 && msg)` statements to `DIE(msg)` for clarity and to
eliminate oclint warnings about constant expressions.

Fixes #3276, albeit not in the fashion I originally envisioned.
2017-02-14 18:48:27 -08:00
Kurtis Rader
7fc1994339 some trivial lint cleanups 2017-02-13 18:48:59 -08:00
Kurtis Rader
4ffb0adb78 lint cleanups 2017-02-11 21:30:38 -08:00
ridiculousfish
4ac2cfba61 Adopt owning_lock in iothread.cpp 2017-01-29 21:06:46 -08:00
Kurtis Rader
5b6cc5af6d time for another make style-all
Gotta keep the entropy (i.e., disorder) from increasing.
2017-01-26 20:05:46 -08:00
ridiculousfish
1efb81456b Use std::move instead of swap in a few places where it improves clarity 2017-01-26 16:14:50 -08:00
ridiculousfish
a3dbca90d5 g++-friendly 'Rework iothread_perform for void return types'
Allows iothread_perform to work with void return types on both
g++ and clang

This reverts commit 1040b255c7
and reintroduces ac9a0f0dbf
2017-01-26 09:40:17 -08:00