# error "SmallLocks.h is currently x64-only."
#endif
+#include "folly/Portability.h"
+
namespace folly {
//////////////////////////////////////////////////////////////////////
// Check if T can theoretically cross a cache line.
// NOTE: It should be alignof(std::max_align_t), but max_align_t
// isn't supported by gcc 4.6.2.
- struct MaxAlign { char c; } __attribute__((aligned));
static_assert(alignof(MaxAlign) > 0 &&
FOLLY_CACHE_LINE_SIZE % alignof(MaxAlign) == 0 &&
sizeof(T) <= alignof(MaxAlign),
class TypedIOBuf {
static_assert(std::is_standard_layout<T>::value, "must be standard layout");
public:
+ typedef T value_type;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef uint32_t size_type;
+ typedef value_type* iterator;
+ typedef const value_type* const_iterator;
+
explicit TypedIOBuf(IOBuf* buf) : buf_(buf) { }
IOBuf* ioBuf() {
uint32_t length() const {
return sdiv(buf_->length());
}
+ uint32_t size() const { return length(); }
+
uint32_t headroom() const {
return sdiv(buf_->headroom());
}
void reserve(uint32_t minHeadroom, uint32_t minTailroom) {
buf_->reserve(smul(minHeadroom), smul(minTailroom));
}
+ void reserve(uint32_t minTailroom) { reserve(0, minTailroom); }
+
+ const T* cbegin() const { return data(); }
+ const T* cend() const { return tail(); }
+ const T* begin() const { return cbegin(); }
+ const T* end() const { return cend(); }
+ T* begin() { return writableData(); }
+ T* end() { return writableTail(); }
+
+ const T& front() const {
+ assert(!empty());
+ return *begin();
+ }
+ T& front() {
+ assert(!empty());
+ return *begin();
+ }
+ const T& back() const {
+ assert(!empty());
+ return end()[-1];
+ }
+ T& back() {
+ assert(!empty());
+ return end()[-1];
+ }
/**
* Simple wrapper to make it easier to treat this TypedIOBuf as an array of
void push(const T& data) {
push(&data, &data + 1);
}
+ void push_back(const T& data) { push(data); }
/**
* Append multiple elements in a sequence; will call distance().