Commit Graph
1875 Commits
Author SHA1 Message Date
Carl Lerche fa9743f0d4 macros: scoped_thread_local should be private (#2470)
Do not export the `scoped_thread_local` macro outside of the Tokio
crate. This is not considered a breaking change as the macro never
worked if used from outside of the crate due to the generated code
referencing crate-private types.
2020-04-30 14:32:47 -07:00
Hanif Ariffin 7a89d66513 io: add get_mut, get_ref and into_inner to Lines (#2450) 2020-04-30 12:44:19 +02:00
Eliza Weisman 45773c5641 mutex: add OwnedMutexGuard for Arc<Mutex<T>>s (#2455)
This PR adds a new `OwnedMutexGuard` type and `lock_owned` and
`try_lock_owned` methods for `Arc<Mutex<T>>`.  This is pretty much the
same as the similar APIs added in #2421. 

I've also corrected some existing documentation that incorrectly
implied that the existing `lock` method cloned an internal `Arc` — I
think this may be a holdover from `tokio` 0.1's `Lock` type?

Signed-off-by: Eliza Weisman <[email protected]>
2020-04-29 15:48:08 -07:00
Matthijs Brobbel c52b78b792 chore: fix a typo (#2461) 2020-04-29 13:06:40 -07:00
Jonathan Foote 1d28060836 chore: add initial security policy (#2360)
Adds an initial security policy based on email discussions with @carllerche,
@hawkw, and co.
2020-04-29 12:37:09 -07:00
Thomas Whiteway 947045b944 time: notify when resetting a Delay to a time in the past (#2290)
If a Delay has been polled, then the task that polled it may be waiting
for a notification.  If the delay gets reset to a time in the past, then
it immediately becomes elapsed, so it should notify the relevant task.
2020-04-29 18:03:44 +02:00
John-John Tedro 2c53bebe56 runtime: mem::forget instead of keeping track of dropped state (#2451) 2020-04-29 08:24:55 -07:00
Carl Lerche 0f4287ac2b chore: prepare v0.2.20 release. (#2458) tokio-0.2.20 2020-04-28 16:32:09 -07:00
Carl Lerche 1bf1928088 rt: fix default thread number logic (#2457)
Previously, the function picking the default number of threads for the
threaded runtime did not factor in `max_threads`. Instead, it only used
the value returned by `num_cpus`. However, if `num_cpus` returns a value
greater than `max_threads`, then the function would panic.

This patch fixes the function by limiting the default number of threads
by `max_threads`.

Fixes #2452
2020-04-28 15:04:41 -07:00
Alice Ryhl a26d3aec96 net: mention that bind sets SO_REUSEADDR (#2454) 2020-04-28 19:44:33 +02:00
Kevin Leimkuhler a819584849 sync: fix slow receivers in broadcast (#2448)
Broadcast uses a ring buffer to store values sent to the channel. In order to
deal with slow receivers, the oldest values are overwritten with new values
once the buffer wraps. A receiver should be able to calculate how many values
it has missed.

Additionally, when the broadcast closes, a final value of `None` is sent to
the channel. If the buffer has wrapped, this value overwrites the oldest
value.

This is an issue mainly in a single capacity broadcast when a value is sent
and then the sender is dropped. The original value is immediately overwritten
with `None` meaning that receivers assume they have lagged behind.

**Solution**

A value of `None` is no longer sent to the channel when the final sender has
been dropped. This solves the single capacity broadcast case by completely
removing the behavior of overwriting values when the channel is closed.

Now, when the final sender is dropped a closed bit is set on the next slot
that the channel is supposed to send to.

In the case of a fast receiver, if it finds a slot where the closed bit is
set, it knows the channel is closed without locking the tail.

In the case of a slow receiver, it must first find out if it has missed any
values. This is similar to before, but must be able to account for channel
closure.

If the channel is not closed, the oldest value may be located at index `n`. If
the channel is closed, the oldest value is located at index `n - 1`.

Knowing the index where the oldest value is located, a receiver can calculate
how many values it may have missed and starts to catch up.

Closes #2425
2020-04-27 21:04:47 -07:00
John-John Tedro 70ed3c7f04 rt: reduce usage of ManuallyDrop (#2449) 2020-04-27 14:45:39 -07:00
Carl Lerche ce9eabfdd1 chore: prepare v0.2.19 release (#2441) tokio-0.2.19 2020-04-24 15:13:55 -07:00
Alice Ryhl 894eb8b83f runtime: improve runtime and handle doc (#2440)
Refs: #2437
2020-04-24 21:05:10 +02:00
Alice Ryhl 3572ba5a7b task: update doc on spawn_blocking and block_in_place (#2436) 2020-04-24 10:16:46 -04:00
Dan Burkert d8139fef7a Add Handle::block_on method (#2437) 2020-04-24 15:25:48 +03:00
Alice Ryhl 9bcb50660e docs: make it easier to discover extension traits (#2434)
Refs: #2307
2020-04-23 15:11:49 -07:00
Alice Ryhl a3aab864d7 io: track rustfmt/clippy changes (#2431)
Refs: rust-lang/rustfmt#4140
2020-04-23 13:07:53 -07:00
Mikail Bagishov 236629d1be stream: fix panic in Merge and Chain size_hint (#2430) 2020-04-23 20:19:56 +02:00
Palash Ahuja f83f6388c4 task: link to lib.rs in spawn_blocking documentation (#2426) 2020-04-23 16:04:43 +02:00
Pythonidea 13974068f9 io: fix typo on AsyncWrite doc (#2427) 2020-04-22 19:18:48 +02:00
6349efd237 sync: improve mutex documentation (#2405)
Co-authored-by: Taiki Endo <[email protected]>
Co-authored-by: Alice Ryhl <[email protected]>
2020-04-21 20:36:13 +02:00
Geoffry Song 2da15b5f24 io: remove unsafe from ReadToString (#2384) 2020-04-21 19:41:41 +02:00
Taiki Endo 7e88b56be5 test: remove unnecessary unsafe code (#2424) 2020-04-22 02:34:55 +09:00
damienrg 43bbbf61a2 Remove relative link when possible and fix invalid links (#2423)
The link to tokio::main was relative to tokio_macros crate in the source
directory. This is why it worked in local build of documentation and not
in doc.rs.

Refs: #1473
2020-04-21 13:08:07 +02:00
Jon Gjengset 282b00cbe8 Be more principled about when blocking is ok (#2410)
This enables `block_in_place` to be used in more contexts. Specifically,
it allows you to block whenever you are off the tokio runtime (like if
you are not using tokio, are in a `spawn_blocking` closure, etc.), and
in the threaded scheduler's `block_on`. Blocking in `LocalSet` and the
basic scheduler's` block_on` is still disallowed.

Fixes #2327.
Fixes #2393.
2020-04-20 19:18:47 -04:00
Alice Ryhl 5a548044d7 sync: add owned semaphore permit (#2421) 2020-04-20 22:59:25 +02:00
Alice RyhlandEliza Weisman a748da1031 io: rewrite stdin documentation (#2420)
Co-authored-by: Eliza Weisman <[email protected]>
2020-04-20 20:44:08 +02:00
Gardner Vickers 6edc64afc7 task: Ensure the visibility modifier is propagated when constructing a task local (#2416) 2020-04-20 12:40:14 -04:00
Alice Ryhl 8f3a265972 net: introduce owned split on TcpStream (#2270) 2020-04-19 19:00:44 +02:00
Alice Ryhl 800574b4e0 doc: mention CPU-bound code lib.rs (#2414) 2020-04-18 18:46:51 -07:00
Lucio Franco 19a87e090e test: Add Future and Stream impl for Spawn. (#2412) 2020-04-17 15:37:59 -04:00
Nikolai Vazquez 6f00d7158b Link PRs in CHANGELOG files (#2383)
Allows for simply clicking on the PR number to view the corresponding
changes made.
2020-04-17 11:23:13 -04:00
Jon Gjengset 67c4cc0391 Support nested block_in_place (#2409) 2020-04-16 16:40:11 -04:00
Carl Lerche 8381dff39b chore: link mini-redis in examples (#2407) 2020-04-15 15:30:03 -07:00
xliiv 9553355c27 doc: fix a few broken links (#2400) 2020-04-13 17:25:28 +02:00
Taiki Endo 770d0ec452 ci: fix FreeBSD CI (#2403) 2020-04-13 14:41:42 +02:00
Alice Ryhl 5376f9181f chore: prepare to release 0.2.18 (#2399) tokio-0.2.18 2020-04-12 20:40:34 -07:00
Alice Ryhl 4fc2adae4f task: make LocalSet non-Send (#2398)
This does not count as a breaking change as it fixes a
regression and a soundness bug.
2020-04-12 14:55:37 -07:00
xliiv f39c15334e docs: replace some html links with rustdoc paths (#2381)
Included changes
- all simple references like `<type>.<name>.html` for these types
    - enum
    - fn
    - struct
    - trait
    - type
- simple references for methods, like struct.DelayQueue.html#method.poll

Refs: #1473
2020-04-12 10:25:55 -07:00
shuoandlishuo 060d22bd10 io: report error on zero-write in write_int (#2334)
* tokio-io: make write_i* same behavior as write_all when poll_write returns Ok(0)

Fixes: #2329

Co-authored-by: lishuo <[email protected]>
2020-04-12 16:05:03 +02:00
Nikita Baksalyar 8118f8f117 docs: fix incorrect documentation links & formatting (#2332)
The streams documentation referred to module-level 'split' doc which is no longer there
2020-04-12 15:59:37 +02:00
Max Inden 1e679748ec docs: remove duplicate "a listener" (#2395) 2020-04-12 15:41:14 +02:00
Eliza Weisman 3137c6f07d chore: prepare to release 0.2.17 (#2392)
# 0.2.17 (April 9, 2020)

### Fixes
- rt: bug in work-stealing queue (#2387) 

### Changes 
- rt: threadpool uses logical CPU count instead of physical by default
  (#2391)


Signed-off-by: Eliza Weisman <[email protected]>
tokio-0.2.17
2020-04-09 13:49:19 -07:00
Sean McArthur d294c992e7 Use logical CPUs instead of physical by default (#2391)
Some reasons to prefer logical count as the default:

- Chips reporting many logical CPUs vs physical, such as via
hyperthreading, probably know better than us about the workload the CPUs
can handle.
- The logical count (`num_cpus::get()`) takes into consideration
schedular affinity, and cgroups CPU quota, in case the user wants to
limit the amount of CPUs a process can use.

Closes #2269
2020-04-09 12:42:46 -07:00
Carl Lerche 58ba45a38c rt: fix bug in work-stealing queue (#2387)
Fixes a couple bugs in the work-stealing queue introduced as
part of #2315. First, the cursor needs to be able to represent more
values than the size of the buffer. This is to be able to track if
`tail` is ahead of `head` or if they are identical. This bug resulted in
the "overflow" path being taken before the buffer was full.

The second bug can happen when a queue is being stolen from concurrently
with stealing into. In this case, it is possible for buffer slots to be
overwritten before they are released by the stealer. This is harder to
happen in practice due to the first bug preventing the queue from
filling up 100%, but could still happen. It triggered an assertion in
`steal_into`. This bug slipped through due to a bug in loom not
correctly catching the case. The loom bug is fixed as part of
tokio-rs/loom#119.

Fixes: #2382
2020-04-09 11:35:16 -07:00
nasa de8326a5a4 doc: Sort methods on mpsc::Sender in doc (#2379) 2020-04-06 22:49:10 +02:00
Vojtech Kral d65bf3805b doc: add error explanation for UnboundedSender::send() (#2372) 2020-04-04 19:36:12 +02:00
Alice Ryhl 7c1bc460f7 test: add Send/Sync tests for all async fns (#2377)
Also updates Empty and Pending to be unconditionally Send and Sync.
2020-04-04 19:02:26 +02:00
Eliza Weisman d883ac0fa0 chore: prepare tokio 0.2.16 release
# 0.2.16 (April 3, 2020)

### Fixes

- sync: fix a regression where `Mutex`, `Semaphore`, and `RwLock` futures no
  longer implement `Sync` (#2375)
- fs: fix `fs::copy` not copying file permissions (#2354)

### Added

- time: added `deadline` method to `delay_queue::Expired` (#2300)
- io: added `StreamReader` (#2052) 

Signed-off-by: Eliza Weisman <[email protected]>
tokio-0.2.16
2020-04-03 17:00:42 -07:00