
#ifndef PLS_INTERNAL_BASE_ALIGNMENT_IMPL_H_
#define PLS_INTERNAL_BASE_ALIGNMENT_IMPL_H_

namespace pls {
namespace internal {
namespace base {
namespace alignment {

void *allocate_aligned(size_t size) {
  return aligned_alloc(system_details::CACHE_LINE_SIZE, size);
}

constexpr system_details::pointer_t next_alignment(system_details::pointer_t size) {
  return (size % system_details::CACHE_LINE_SIZE) == 0 ?
         size :
         size + (system_details::CACHE_LINE_SIZE - (size % system_details::CACHE_LINE_SIZE));
}

constexpr system_details::pointer_t previous_alignment(system_details::pointer_t size) {
  return (size % system_details::CACHE_LINE_SIZE) == 0 ?
         size :
         size - (size % system_details::CACHE_LINE_SIZE);
}

constexpr char *next_alignment(char *pointer) {
  return reinterpret_cast<char *>(next_alignment(reinterpret_cast<system_details::pointer_t >(pointer)));
}

}
}
}
}

#endif //PLS_INTERNAL_BASE_ALIGNMENT_IMPL_H_
