Commit Graph

8 Commits

Author SHA1 Message Date
Stanislau Hlebik
9ba06ebc3c asyncmemo: remove entry with the same key before inserting new one
Summary:
There was a bug when if the entry with the same key is present in the hash and
the hash is full, then some entry will be evicted even though it's not
necessary.
It adds one hash map lookup, but it shouldn't be a big problem

Reviewed By: jsgf

Differential Revision: D6702001

fbshipit-source-id: 1c8cadc5e4bad6f6d95279b21edf00ed99f62c49
2018-01-19 01:10:27 -08:00
Stanislau Hlebik
45f1fbdd4e asyncmemo: use spawn() in tests
Summary:
In the next diff we'll `task::current()` inside MemoFuture. It fails if no
task exists. Let's use spawn to create a Task for each future.

Reviewed By: jsgf

Differential Revision: D6611510

fbshipit-source-id: 95a825dff9714579e9b16e74f355c54d8fa83a24
2017-12-22 03:41:22 -08:00
Stanislau Hlebik
79c6006853 rust: asyncmemo rustfmt
Summary: rustfmt

Reviewed By: jsgf

Differential Revision: D6611512

fbshipit-source-id: 84c8306015e961ea283341fc1a52c153f3db2a49
2017-12-22 03:41:22 -08:00
Stanislau Hlebik
e734b3f9be asyncmemo: fix hash size calculation
Summary: Previously inserting the same key twice will add size of this key twice.  This diff fixes it.

Reviewed By: jsgf

Differential Revision: D6602501

fbshipit-source-id: eb8f785296945bca1df4b6cd33bd3050a48e2174
2017-12-22 03:41:22 -08:00
Jeremy Fitzhardinge
8c457e731c rust: asyncmemo: add failure test
Summary: Add a unit test for failing to compute a value.

Reviewed By: Imxset21

Differential Revision: D5717910

fbshipit-source-id: cb5b1560a539f4b99d87dc2f8fc0afd37f4b5b97
2017-08-29 12:36:18 -07:00
Jeremy Fitzhardinge
9501d33699 rust: asyncmemo: allow fill function to be recursive
Summary:
Pass a reference to the cache to the fill function. This allows the
function to be recursive based on memoized values.

This also required quite a bit of restructuring to make sure that locks
and ownership are handled properly during recursive calls. Specifically,
a new `Slot` state - `Polling` - is used to indicate when a thread/task
is currently calling `.poll()` on the future. This contains a list of
futures Tasks which are interested in the state of the slot which can be
notified when it changes state.

Also removed unused Entry API code.

Reviewed By: sid0

Differential Revision: D5652704

fbshipit-source-id: 29cd3fe37d4eb9316235872b7e2e228bf10a016f
2017-08-29 12:36:18 -07:00
Jeremy Fitzhardinge
08b847a0b9 rust: asyncmemo: implement Debug
Summary: Implement Debug for Asyncmemo where possible.

Reviewed By: sid0

Differential Revision: D5652740

fbshipit-source-id: c04e3972ade1b7120d273c1500b3e2650b2a8c34
2017-08-22 15:05:03 -07:00
facebook-github-bot
2b6af6b941 Initial commit
fbshipit-source-id: f75baa4ff6aa71973f677b752d7aba582cf4927f
2017-07-27 18:00:19 -07:00