Commit Graph

18 Commits

Author SHA1 Message Date
Avi Kivity
692ee47456 deleter: introduce make_object_deleter
When we have an object acting as resource guard for memory, we can convert
it into a deleter using

  make_deleter([obj = std::move(obj)] {})

introduce a simpler interface

  make_object_deleter(std::move(obj))

for doing the same thing.
2014-12-16 14:55:02 +02:00
Avi Kivity
9ae2075d54 deleter: remove bad/unused interfaces 2014-12-09 20:37:44 +02:00
Avi Kivity
7708627144 deleter: improve make_free_deleter() with null input
While make_free_deleter(nullptr) will function correctly,
deleter::operator bool() on the result will not.

Fix by checking for null, and avoiding the free deleter optimization in
that case -- it doesn't help anyway.
2014-12-09 20:37:16 +02:00
Avi Kivity
15dd8ed1bb deleter: mark as final class
Prevent accidental inheritance.
2014-12-09 20:24:35 +02:00
Tomasz Grabiec
e720f53c22 deleter: add chaining make_free_deleter() overload 2014-12-04 13:37:35 +01:00
Tomasz Grabiec
8e38cb4159 deleter: introduce append()
It's to help chaining up deleters when appending a fragment with anq
already created deleter.
2014-12-04 13:37:35 +01:00
Avi Kivity
8b632ca2fb Revert bogus allocator/deleter commits
Reverts:
e0df395124
   "Add make_free_deleter"
cfd8a1f997
   "core: special-case deleter for raw memory""
5eaecc8805
   "Use default allocator"

Introduced accidentally.
2014-11-25 12:06:13 +02:00
Asias He
e0df395124 Add make_free_deleter 2014-11-24 18:16:25 +08:00
Asias He
cfd8a1f997 Revert "core: special-case deleter for raw memory"
This reverts commit f75d1822cc.
2014-11-24 18:16:25 +08:00
Avi Kivity
f75d1822cc core: special-case deleter for raw memory
In many cases, a deleter is used to protect raw memory (e.g. a char array,
not something with a destructor).  In that case we can simply free() it,
so, the deleter need not remember which destructor needs to be called.

It does need to remember whether it's a raw object or not, so we take over
the least significant bit and use it as a marker, and store the pointer
to the object in the deleter, instead of using a proxy impl object to
control actual deletion.

If the deleter is subsequently share()d, we have to convert it back to
the standard form, since the reference count lives in the impl object.
2014-10-21 11:20:12 +03:00
Avi Kivity
a1f3708fab packet: optimize sharing
Move reference counting into the deleter core, instead of relegating it
to a shared_deleter (which has to be allocated) and an external reference
counted (also allocated).  This dramatically reduces dynamic allocations.
2014-09-23 18:57:11 +03:00
Avi Kivity
26d713e341 Remove internal_deleter 2014-09-23 18:10:10 +03:00
Avi Kivity
e223f748ec core: great deleter rename
deleter::share() is causing massive amounts of allocation.  First,
since usually a packet's deleter is not a shared_deleter, we need to
allocate that shared_deleter.  Second, we need an external reference
count which requires yet another allocation.

Making reference counting part of the deleter class would solve both of
these problems, but we cannot easily do that, since users hold
std::unique_ptr<deleter> which is clearly not sharable.

We could do a massive s/unique_ptr/shared_ptr/ here, but that would have
the side effect of making sharing "too easy" - you simply copy the pointer.
We'd like to keep it explicit.

So to make the change easier, rename the existing unique_ptr<deleter> as
plain "deleter", whereas the old "deleter" becomes deleter::impl:

  old name              new name
  --------              --------
  deleter               deleter::impl
  unique_ptr<deleter>   deleter

with exactly the same semantics.  A later patch can then add explicit sharing.
2014-09-23 11:15:31 +03:00
Avi Kivity
812ac77d2f net: spit out packet class into its own files 2014-09-16 10:13:09 +03:00
Avi Kivity
d06508927e core: add a share() helper for deleter class 2014-09-08 21:20:25 +03:00
Avi Kivity
2cc4728325 core: fix shared_ptr memory leak 2014-09-08 21:20:00 +03:00
Avi Kivity
be5e75b6a6 core: disable shared_ptr assignments (until implemented) 2014-09-08 21:19:36 +03:00
Avi Kivity
b91389b1d5 core: extract packet::deleter into a core class
Useful everywhere zero-copy can be used.
2014-09-04 13:28:51 +03:00