Allow enable_shared_from_this<T>::shared_from_this() to return
a shared_ptr<const T> when called on a const object.
Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
The foreign_ptr wrapper needs 'element_type' to be present in
shared_ptr to be able to access the data.
Fixes the following compilation failure when trying to use shared_ptr
with foreign_ptr:
In file included from tests/foreign_ptr_test.cc:24:0:
./core/distributed.hh: In instantiation of ‘class foreign_ptr<shared_ptr<basic_sstring<char, unsigned int, 15u> > >’:
tests/foreign_ptr_test.cc:28:54: required from here
./core/distributed.hh:272:56: error: no type named ‘element_type’ in ‘class shared_ptr<basic_sstring<char, unsigned int, 15u> >’
using element_type = typename PtrType::element_type;
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
small_pools, which are responsible for allocations up to 16kB, aren't able
to provide a buffer with alignment stricter than a page. This results
in aligned allocations being broken for buffers in the range 4kB - 16kB.
This patch make sure that if the alignment requirement is too big for
small_pool to handle allocate_large_aligned() is used instead.
Fixes#36.
Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
The proper way to test whether posix_memalign() failed is to check its
return value, not the content of the pointer.
This also silences "ignoring return value of 'posix_memalign()'" diagnostic
messages.
Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
OSv does not supported timer_create/timer_settime and thread based signal handling.
This patch implements timer function using OSv native timer and timer handler thread witch pinned to the CPU same as reactor thread.
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
If the callback throws the program will segfault and GDB will be
useless in diagnosing the failure:
gdb$ run
...
thread_get_info_callback: cannot get thread info: generic error
gdb$
So let's fail in a better way.
Added to make clang happy, but causes compilation failure with more than
one bound value in value list. Using paranthesis instead.
Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
The current code assumes that the sstring will have the same char_type as the
output_stream. That was working well, until I was forced to change the type of
my basic_sstring to another one that is backed by signed chars.
Of course, the best solution for this would be to change the output_stream (as
well as the input_stream), to take a signed char as well.
And oh boy, have I tried. The data_sink assumes a char type, and when it tries
to allocate a new buffer from it, the buffer will have no other choice than to
be of a char type. Fix that one, and another one appears.
I eventually gave up when the code wouldn't compile because struct fragment has
a char type - and both using a template for such a simple struct, as well as
sprinkling casts all over the place where it is used, sounded like horrible
ideas to me.
It's true that quitters never win, and winners never quit. But for now, my
proposal would be to generalize the write code to accept basic_sstrings of
general types. At least the cast lives in a single place.
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
All basic_sstring writes the same way. Using sstring as the signature would
require other users that are using other variants of basic_sstring to add their
own signatures.
This general version will cover those use cases as well.
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Latest DPDK(which will be v2.1.0) causes compile error when referencing RTE_MBUF_REFCNT because it defained as "#pragma GCC poison RTE_MBUF_REFCNT".
And that configuration entry is not available v2.0.0 or later.
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
This variant is intended to simplify do_for_each idiom where the
iterators begin() and end() will be implicit.
Allowing the user to do something as follow:
return do_for_each(map, [] { ... });
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
This do a clean up in the sstring replace method, it also uses a
std::move for optimization.
The missing cbeging and cend method were edded to return a
const_iterator
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
The boost::replace_all uses insert and erase to perform a change, those
method are missing from sstring.
Following the std:string implemntation the implementation of both
functionalities is based on the replace method, either as c string
replace or with templated iterators.
Not all the variation of insert, replace and erase where added, but it
will be possible to add them in the future if needed by calling the
existing functionality.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Add a convenient function do_with(rvalue, func) which ensures that a
(moved copy of) rvalue will live until the future returned by func
concludes, and that func is passed this object.
Needing to do this is a recurring idiom in Seastar applications.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
[avi: mark inline]
This method check the file type and retrun an optional value, if the
file does not exists no value is return.
On other errors an exception will be thrown.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This adds the back method that return a reference or const reference to
the last char in an sstring.
find_last_of, which return the index of the last occurance of a char in
the string.
And append with append C string to a string.
The logic and definition are similiar to the std::string.
Note that following the std::string definition, calling back on an empty
string is forbiden and the results are undefined.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Trimmers may request buffers smaller than n_pages, the original value
passed to allocate_large_and_trim(). That's why t.nr_page should be
used as a final size of the allocated span.
Another issue with the handling of span trimming is the order of operations
when pages from the beginning of the buffer are trimmed. In such case
span is updated to point to the actual beginning of the requested buffer,
but afterwards it is used to retrieve span->span_size value which is expected
to be the size of the originally allocated page span. Because the span
pointer was changed the value is invalid and the trimming doesn't free
all trimmed pages.
Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
distributed::stop() passes the pointer to the instance being destroyed
by reference, in an attempt to keep things clean (by nulling the pointer
after deleting it). This is illegal, however, since the lambda is moved
in the bowels of submit_to(). In release mode this is optimized away so
the code works, but in debug mode it leads to a crash.
Fix by capturing by value instead (could also have been fixed by switching
the enclosing capture to a reference).
Credit to Gleb for identifying the problem.
Seastar applications obviously cannot use the Posix sleep() function, or
the entire thread will block. This patch implements future<> sleep(duration)
where as expected, the future becomes ready when the given duration passes.
For example, one can do:
sleep(1s).then([] { std::cout << "Done.\n"; });
This can be useful as an example of futures and continuations in the
Seastar tutorial, and people might find other uses for it.
This sleep() is implemented in terms of timer<>. sleep() is easier to use
and more aligned with the rest of Seastar (it uses then() for the
continuation instead of a set_callback() method). The downside of sleep()
compared to a timer is that it cannot be canceled once started.
In this version, sleep() is implemented without shared_ptr, making the
implementation a tiny bit more efficient. There is still a heap allocation
(this is unavoidable because std::function requires a copyable type)
but no reference counting. Unfortunately, this requires us to use bare
"new" and "delete".
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
engine_exit() without a parameter is meant to do engine().exit(0).
We do this, but forget to return from this function, so after calling
engine().exit(0), it continued on and crashed.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
This patch adds a new header file, "core/unaligned.hh", which defines a
new operation, unaligned_cast<T*>(p). This works exctly like
reinterpret_cast<T*>(p) except it is safe to use even when the address
of p is not a multiple of alignof(T).
A long comment in the header file explains why this unaligned_cast<>
is necessary on some esoteric architectures and to quiet gcc's
-fsanitize=alignment.
The header file also defines a new template for holding an unaligned
version of type - unaligned<T>. unaligned<T> is almost identical to our
existing net::packed<>, so the next patch will implement net::packed
in terms of unaligned<>.
The unaligned_cast<> and unaligned<> templates are of course generally
useful outside the network code, which is why I wanted them out of the
networking header files and namespace.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>