Skip to content

Commit

Permalink
While not perfect IMHO it's better #7
Browse files Browse the repository at this point in the history
  • Loading branch information
manpen committed Feb 3, 2018
1 parent 2602caa commit 3faf3f0
Show file tree
Hide file tree
Showing 52 changed files with 671 additions and 386 deletions.
2 changes: 1 addition & 1 deletion CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
filter=-legal/copyright,-whitespace/braces,-whitespace/newline,-build/c++11,-whitespace/line_length,-whitespace/indent,-runtime/references,-whitespace/comments,-runtime/int,-build/header_guard,-whitespace/operators,-readability/braces,-readability/casting,-readability/todo
filter=-legal/copyright,-whitespace/braces,-whitespace/newline,-whitespace/parens,-build/c++11,-whitespace/line_length,-whitespace/indent,-runtime/references,-whitespace/comments,-runtime/int,-build/header_guard,-whitespace/operators,-readability/braces,-readability/casting,-readability/todo
8 changes: 4 additions & 4 deletions foxxll/common/aligned_alloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ inline void * aligned_alloc(size_t size, size_t meta_info_size = 0)
#endif
char* reserve_buffer = buffer + sizeof(char*) + meta_info_size;
char* result = reserve_buffer + Alignment -
(reinterpret_cast<size_t>(reserve_buffer) % Alignment) - meta_info_size;
(reinterpret_cast<size_t>(reserve_buffer) % Alignment) - meta_info_size;
LOGC(debug_aligned_alloc) << "foxxll::aligned_alloc<" << Alignment << ">() address "
<< static_cast<void*>(result) << " lost " << (result - buffer) << " bytes";
//-tb: check that there is space for one char* before the "result" pointer
Expand All @@ -104,12 +104,12 @@ inline void * aligned_alloc(size_t size, size_t meta_info_size = 0)

*(reinterpret_cast<char**>(result) - 1) = buffer;
LOGC(debug_aligned_alloc) << "foxxll::aligned_alloc<" << Alignment << ">(), allocated at " <<
static_cast<void*>(buffer) << " returning " << static_cast<void*>(result);
static_cast<void*>(buffer) << " returning " << static_cast<void*>(result);

LOGC(debug_aligned_alloc) <<
"foxxll::aligned_alloc<" << Alignment <<
">(size = " << size << ", meta info size = " << meta_info_size <<
") => buffer = " << static_cast<void*>(buffer) << ", ptr = " << static_cast<void*>(result);
">(size = " << size << ", meta info size = " << meta_info_size <<
") => buffer = " << static_cast<void*>(buffer) << ", ptr = " << static_cast<void*>(result);

return result;
}
Expand Down
26 changes: 14 additions & 12 deletions foxxll/common/die_with_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@

//! Check condition X and die miserably if false. Same as die_if()
//! except user additionally pass message
#define die_with_message_if(X, msg) \
do { \
if ((X)) { \
die_with_sstream( \
"DIE: Assertion \"" #X "\" succeeded!\n " << msg << "\n"); \
} \
#define die_with_message_if(X, msg) \
do { \
if ((X)) { \
die_with_sstream( \
"DIE: Assertion \"" #X "\" succeeded!\n " << msg << "\n" \
); \
} \
} while (false)

//! Check condition X and die miserably if false. Same as die_unless()
//! except user additionally pass message
#define die_with_message_unless(X, msg) \
do { \
if (!(X)) { \
die_with_sstream( \
"DIE: Assertion \"" #X "\" failed!\n " << msg << "\n"); \
} \
#define die_with_message_unless(X, msg) \
do { \
if (!(X)) { \
die_with_sstream( \
"DIE: Assertion \"" #X "\" failed!\n " << msg << "\n" \
); \
} \
} while (false)

#endif // !FOXXLL_COMMON_DIE_WITH_MESSAGE_HEADER
27 changes: 17 additions & 10 deletions foxxll/common/error_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,31 @@ namespace foxxll {

//! Throws exception_type with "Error in [function] : [error_message]"
#define FOXXLL_THROW(exception_type, error_message) \
FOXXLL_THROW2(exception_type, \
FOXXLL_PRETTY_FUNCTION_NAME, \
error_message)
FOXXLL_THROW2( \
exception_type, \
FOXXLL_PRETTY_FUNCTION_NAME, \
error_message \
)

//! Throws exception_type with "Error in [function] : [error_message] : [errno_value message]"
#define FOXXLL_THROW_ERRNO2(exception_type, error_message, errno_value) \
FOXXLL_THROW2(exception_type, \
FOXXLL_PRETTY_FUNCTION_NAME, \
error_message << " : " << strerror(errno_value))
FOXXLL_THROW2( \
exception_type, \
FOXXLL_PRETTY_FUNCTION_NAME, \
error_message << " : " << strerror(errno_value) \
)

//! Throws exception_type with "Error in [function] : [error_message] : [errno message]"
#define FOXXLL_THROW_ERRNO(exception_type, error_message) \
FOXXLL_THROW_ERRNO2(exception_type, error_message, errno)

//! Throws std::invalid_argument with "Error in [function] : [error_message]"
#define FOXXLL_THROW_INVALID_ARGUMENT(error_message) \
FOXXLL_THROW2(std::invalid_argument, \
FOXXLL_PRETTY_FUNCTION_NAME, \
error_message)
FOXXLL_THROW2( \
std::invalid_argument, \
FOXXLL_PRETTY_FUNCTION_NAME, \
error_message \
)

//! Throws exception_type if (expr) with "Error in [function] : [error_message]"
#define FOXXLL_THROW_IF(expr, exception_type, error_message) \
Expand Down Expand Up @@ -97,7 +103,8 @@ namespace foxxll {
nullptr, dw, \
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
(LPTSTR)&lpMsgBuf, \
0, nullptr); \
0, nullptr \
); \
std::ostringstream msg; \
msg << "Error in " << FOXXLL_PRETTY_FUNCTION_NAME \
<< " : " << error_message \
Expand Down
5 changes: 3 additions & 2 deletions foxxll/common/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ static inline double timestamp()
{
return static_cast<double>(
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now().time_since_epoch()).count()) / 1e6;
std::chrono::steady_clock::now().time_since_epoch()
).count()) / 1e6;
}

/*!
Expand Down Expand Up @@ -257,7 +258,7 @@ class scoped_print_timer
<< m_message
<< " after " << m_timer.seconds() << " seconds. "
<< "Processed " << tlx::format_iec_units(m_bytes) << "B"
<< " @ " << tlx::format_iec_units(static_cast<uint64_t>(bps)) << "B/s";
<< " @ " << tlx::format_iec_units(static_cast<uint64_t>(bps)) << "B/s";
}
}

Expand Down
2 changes: 1 addition & 1 deletion foxxll/common/tmeta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SWITCH
using type = typename std::conditional<found,
typename Case::Type,
typename SWITCH<Tag, NextCase>::type
>::type;
>::type;
};

template <int Tag>
Expand Down
30 changes: 20 additions & 10 deletions foxxll/common/uint_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,20 @@ class uint_pair
uint_pair()
{
// compile-time assertions about size of low_type
static_assert(8 * sizeof(low_type) == 32,
"8 * sizeof(low_type) == 32");
static_assert(
8 * sizeof(low_type) == 32,
"8 * sizeof(low_type) == 32"
);
// compile-time assertions about size of our data structure, this tests
// packing of structures by the compiler
static_assert(sizeof(uint_pair) == bytes,
"sizeof(uint_pair) == bytes");
static_assert(sizeof(uint_pair) == digits / 8,
"sizeof(uint_pair) == digits / 8");
static_assert(
sizeof(uint_pair) == bytes,
"sizeof(uint_pair) == bytes"
);
static_assert(
sizeof(uint_pair) == digits / 8,
"sizeof(uint_pair) == digits / 8"
);
static_assert(digits / 8 == bytes, "digits / 8 == bytes");
}

Expand Down Expand Up @@ -223,15 +229,19 @@ class uint_pair
//! return an uint_pair instance containing the smallest value possible
static uint_pair min()
{
return uint_pair(std::numeric_limits<low_type>::min(),
std::numeric_limits<high_type>::min());
return uint_pair(
std::numeric_limits<low_type>::min(),
std::numeric_limits<high_type>::min()
);
}

//! return an uint_pair instance containing the largest value possible
static uint_pair max()
{
return uint_pair(std::numeric_limits<low_type>::max(),
std::numeric_limits<high_type>::max());
return uint_pair(
std::numeric_limits<low_type>::max(),
std::numeric_limits<high_type>::max()
);
}
}
#if FOXXLL_MSVC
Expand Down
42 changes: 28 additions & 14 deletions foxxll/io/create_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,17 @@ file_ptr create_file(disk_config& cfg, int mode, int disk_allocator_id)
{
tlx::counting_ptr<ufs_file_base> result =
tlx::make_counting<syscall_file>(
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id);
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id
);
result->lock();

// if marked as device but file is not -> throw!
if (cfg.raw_device && !result->is_device())
{
FOXXLL_THROW(io_error, "Disk " << cfg.path << " was expected to be "
"a raw block device, but it is a normal file!");
FOXXLL_THROW(
io_error, "Disk " << cfg.path << " was expected to be "
"a raw block device, but it is a normal file!"
);
}

// if is raw_device -> get size and remove some flags.
Expand All @@ -102,15 +105,17 @@ file_ptr create_file(disk_config& cfg, int mode, int disk_allocator_id)
{
tlx::counting_ptr<fileperblock_file<syscall_file> > result =
tlx::make_counting<fileperblock_file<syscall_file> >(
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id);
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id
);
result->lock();
return result;
}
else if (cfg.io_impl == "memory")
{
tlx::counting_ptr<memory_file> result =
tlx::make_counting<memory_file>(
cfg.queue, disk_allocator_id, cfg.device_id);
cfg.queue, disk_allocator_id, cfg.device_id
);
result->lock();
return result;
}
Expand All @@ -124,15 +129,18 @@ file_ptr create_file(disk_config& cfg, int mode, int disk_allocator_id)
tlx::counting_ptr<ufs_file_base> result =
tlx::make_counting<linuxaio_file>(
cfg.path, mode, cfg.queue, disk_allocator_id,
cfg.device_id, cfg.queue_length);
cfg.device_id, cfg.queue_length
);

result->lock();

// if marked as device but file is not -> throw!
if (cfg.raw_device && !result->is_device())
{
FOXXLL_THROW(io_error, "Disk " << cfg.path << " was expected to be "
"a raw block device, but it is a normal file!");
FOXXLL_THROW(
io_error, "Disk " << cfg.path << " was expected to be "
"a raw block device, but it is a normal file!"
);
}

// if is raw_device -> get size and remove some flags.
Expand All @@ -154,7 +162,8 @@ file_ptr create_file(disk_config& cfg, int mode, int disk_allocator_id)
{
tlx::counting_ptr<ufs_file_base> result =
tlx::make_counting<mmap_file>(
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id);
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id
);
result->lock();

if (cfg.unlink_on_open)
Expand All @@ -166,7 +175,8 @@ file_ptr create_file(disk_config& cfg, int mode, int disk_allocator_id)
{
tlx::counting_ptr<fileperblock_file<mmap_file> > result =
tlx::make_counting<fileperblock_file<mmap_file> >(
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id);
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id
);
result->lock();
return result;
}
Expand All @@ -176,22 +186,26 @@ file_ptr create_file(disk_config& cfg, int mode, int disk_allocator_id)
{
tlx::counting_ptr<wfs_file_base> result =
tlx::make_counting<wincall_file>(
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id);
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id
);
result->lock();
return result;
}
else if (cfg.io_impl == "fileperblock_wincall")
{
tlx::counting_ptr<fileperblock_file<wincall_file> > result =
tlx::make_counting<fileperblock_file<wincall_file> >(
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id);
cfg.path, mode, cfg.queue, disk_allocator_id, cfg.device_id
);
result->lock();
return result;
}
#endif

FOXXLL_THROW(std::runtime_error,
"Unsupported disk I/O implementation '" << cfg.io_impl << "'.");
FOXXLL_THROW(
std::runtime_error,
"Unsupported disk I/O implementation '" << cfg.io_impl << "'."
);
}

} // namespace foxxll
Expand Down
6 changes: 4 additions & 2 deletions foxxll/io/disk_queued_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ request_ptr disk_queued_file::aread(
const completion_handler& on_complete)
{
request_ptr req = tlx::make_counting<serving_request>(
on_complete, this, buffer, offset, bytes, request::READ);
on_complete, this, buffer, offset, bytes, request::READ
);

disk_queues::get_instance()->add_request(req, get_queue_id());

Expand All @@ -37,7 +38,8 @@ request_ptr disk_queued_file::awrite(
const completion_handler& on_complete)
{
request_ptr req = tlx::make_counting<serving_request>(
on_complete, this, buffer, offset, bytes, request::WRITE);
on_complete, this, buffer, offset, bytes, request::WRITE
);

disk_queues::get_instance()->add_request(req, get_queue_id());

Expand Down
3 changes: 2 additions & 1 deletion foxxll/io/disk_queues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void disk_queues::add_request(request_ptr& req, disk_id_type disk)
#if FOXXLL_HAVE_LINUXAIO_FILE
if (dynamic_cast<linuxaio_request*>(req.get()))
q = queues_[disk] = new linuxaio_queue(
dynamic_cast<linuxaio_file*>(req->get_file())->get_desired_queue_length());
dynamic_cast<linuxaio_file*>(req->get_file())->get_desired_queue_length()
);
else
#endif
q = queues_[disk] = new request_queue_impl_qwqr();
Expand Down
3 changes: 2 additions & 1 deletion foxxll/io/fileperblock_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void fileperblock_file<base_file_type>::lock()
if (!lock_file_)
{
lock_file_ = tlx::make_counting<base_file_type>(
filename_prefix_ + "_fpb_lock", mode_, get_queue_id());
filename_prefix_ + "_fpb_lock", mode_, get_queue_id()
);

//create lock file and fill it with one page, an empty file cannot be locked
const int page_size = BlockAlignment;
Expand Down
Loading

0 comments on commit 3faf3f0

Please sign in to comment.