Skip to content

Commit

Permalink
✨ New ztd::tests::keep_process_awake type for preventing benchmark sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Sep 20, 2022
1 parent 500e490 commit afc7e81
Show file tree
Hide file tree
Showing 16 changed files with 586 additions and 6 deletions.
34 changes: 34 additions & 0 deletions documentation/source/api/tag.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. =============================================================================
..
.. ztd.idk
.. Copyright © 2022 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
.. Contact: opensource@soasis.org
..
.. Commercial License Usage
.. Licensees holding valid commercial ztd.idk licenses may use this file in
.. accordance with the commercial license agreement provided with the
.. Software or, alternatively, in accordance with the terms contained in
.. a written agreement between you and Shepherd's Oasis, LLC.
.. For licensing terms and conditions see your agreement. For
.. further information contact opensource@soasis.org.
..
.. Apache License Version 2 Usage
.. Alternatively, this file may be used under the terms of Apache License
.. Version 2.0 (the "License") for non-commercial use; you may not use this
.. file except in compliance with the License. You may obtain a copy of the
.. License at
..
.. https://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS,
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
.. See the License for the specific language governing permissions and
.. limitations under the License.
..
.. =============================================================================>
tag
===

.. doxygenclass:: ztd::tag
6 changes: 6 additions & 0 deletions include/ztd/idk.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@

#include <ztd/idk/version.h>

#include <ztd/idk/assert.h>
#include <ztd/idk/align.h>
#include <ztd/idk/c_span.h>
#include <ztd/idk/endian.h>
#include <ztd.idk/extent.h>
#include <ztd/idk/static_assert.h>
#include <ztd/idk/unreachable.h>

#endif // ZTD_IDK_H
1 change: 1 addition & 0 deletions include/ztd/idk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <ztd/idk/to_underlying.hpp>
#include <ztd/idk/reference_wrapper.hpp>
#include <ztd/idk/span.hpp>
#include <ztd/idk/tag.hpp>
#include <ztd/idk/type_traits.hpp>

#endif // ZTD_IDK_HPP
139 changes: 139 additions & 0 deletions include/ztd/idk/align.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// =============================================================================
//
// ztd.idk
// Copyright © 2022 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
// Contact: opensource@soasis.org
//
// Commercial License Usage
// Licensees holding valid commercial ztd.idk licenses may use this file in
// accordance with the commercial license agreement provided with the
// Software or, alternatively, in accordance with the terms contained in
// a written agreement between you and Shepherd's Oasis, LLC.
// For licensing terms and conditions see your agreement. For
// further information contact opensource@soasis.org.
//
// Apache License Version 2 Usage
// Alternatively, this file may be used under the terms of Apache License
// Version 2.0 (the "License") for non-commercial use; you may not use this
// file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ============================================================================ //

#pragma once

#ifndef ZTD_IDK_ALIGN_H
#define ZTD_IDK_ALIGN_H

#include <ztd/idk/version.h>

#if ZTD_IS_ON(ZTD_C)
#include <stddef.h>
#include <stdint.h>
#else
#include <cstddef>
#include <cstdint>
#endif

//////
/// @addtogroup ztd_idk_align Align
/// @{

//////
/// @brief A structure containing a pointer, the size required by the object at the givne pointer offset, and the amount
/// of space leftover from a ztdc_align call.
typedef struct ztdc_aligned_const_pointer {
//////
/// @brief The pointer that was aligned. If the ztdc_aligned call failed, this member will be a null pointer
/// constant.
const void* ptr;
//////
/// @brief The amount of space required at the offset of the passed-in pointer.
size_t required_space;
//////
/// @brief The amount of space leftover from the space after adjusting the pointer to its new offset, if ztdc_align
/// succeeded.
size_t leftover_space;
} ztdc_aligned_const_pointer;

//////
/// @brief A structure containing a pointer, the size required by the object at the givne pointer offset, and the amount
/// of space leftover from a ztdc_align call.
typedef struct ztdc_aligned_mutable_pointer {
//////
/// @brief The pointer that was aligned. If the ztdc_aligned call failed, this member will be a null pointer
/// constant.
void* ptr;
//////
/// @brief The amount of space required at the offset of the passed-in pointer.
size_t required_space;
//////
/// @brief The amount of space leftover from the space after adjusting the pointer to its new offset, if ztdc_align
/// succeeded.
size_t leftover_space;
} ztdc_aligned_mutable_pointer;

//////
/// @brief Aligns a pointer according to the given `alignment` and `size`, within the available `space` bytes.
///
/// @param alignment The desired alignment for object that will be put at the (new aligned) pointer's location.
/// @param size The size of the object that will be put at the (newly aligned) pointer's location, in bytes.
/// @param ptr The pointer to align.
/// @param space The amount of available space within which this alignment pay be performed, in bytes.
ZTD_C_LANGUAGE_LINKAGE_I_ ZTD_IDK_API_LINKAGE_I_ inline ztdc_aligned_const_pointer ztdc_align_const(
size_t alignment, size_t size, const void* ptr, size_t space) ZTD_NOEXCEPT_IF_CXX_I_ {
const uintptr_t initial = (uintptr_t)(ptr);
const uintptr_t offby = (uintptr_t)(initial % alignment);
const uintptr_t padding = (alignment - offby) % alignment;
const size_t required_space = size + padding;
if (space < required_space) {
return { nullptr, required_space, space };
}
const void* const aligned_ptr = (const void*)((const char*)(ptr) + padding);
const size_t leftover_space = space - padding;
return { aligned_ptr, required_space, leftover_space };
}

//////
/// @brief Aligns a pointer according to the given `alignment` and `size`, within the available `space` bytes.
///
/// @param alignment The desired alignment for object that will be put at the (new aligned) pointer's location.
/// @param size The size of the object that will be put at the (newly aligned) pointer's location, in bytes.
/// @param ptr The pointer to align.
/// @param space The amount of available space within which this alignment pay be performed, in bytes.
ZTD_C_LANGUAGE_LINKAGE_I_ ZTD_IDK_API_LINKAGE_I_ inline ztdc_aligned_mutable_pointer ztdc_align_mutable(
size_t alignment, size_t size, void* ptr, size_t space) ZTD_NOEXCEPT_IF_CXX_I_ {
const uintptr_t initial = (uintptr_t)(ptr);
const uintptr_t offby = (uintptr_t)(initial % alignment);
const uintptr_t padding = (alignment - offby) % alignment;
const size_t required_space = size + padding;
if (space < required_space) {
return { nullptr, required_space, space };
}
void* const aligned_ptr = (void*)((char*)(ptr) + padding);
const size_t leftover_space = space - padding;
return { aligned_ptr, required_space, leftover_space };
}

//////
/// @brief Aligns a pointer according to the given `alignment` and `size`, within the available `space` bytes.
///
/// @param _ALIGN The desired alignment for object that will be put at the (new aligned) pointer's location.
/// @param _SIZE The size of the object that will be put at the (newly aligned) pointer's location, in bytes.
/// @param _PTR The pointer to align.
/// @param _SPACE The amount of available space within which this alignment pay be performed, in bytes.
#define ztdc_align(_ALIGN, _SIZE, _PTR, _SPACE) \
_Generic(_PTR, const void* : ztdc_align_const, void* : ztdc_align_mutable)(_ALIGN, _SIZE, _PTR, _SPACE)

//////
/// @}

#endif // ZTD_IDK_ALIGN_H
55 changes: 55 additions & 0 deletions include/ztd/idk/ckd_int.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// =============================================================================
//
// ztd.idk
// Copyright © 2022 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
// Contact: opensource@soasis.org
//
// Commercial License Usage
// Licensees holding valid commercial ztd.idk licenses may use this file in
// accordance with the commercial license agreement provided with the
// Software or, alternatively, in accordance with the terms contained in
// a written agreement between you and Shepherd's Oasis, LLC.
// For licensing terms and conditions see your agreement. For
// further information contact opensource@soasis.org.
//
// Apache License Version 2 Usage
// Alternatively, this file may be used under the terms of Apache License
// Version 2.0 (the "License") for non-commercial use; you may not use this
// file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ============================================================================ //

#pragma once

#ifndef ZTD_IDK_CKD_INT_H
#define ZTD_IDK_CKD_INT_H

#include <ztd/idk/version.h>

#include <ztd/prologue.hpp>

#define ZTD_DIV_OVERFLOW(_LEFT, _RIGHT, _PTR)


#if ZTD_IS_ON(ZTD_COMPILER_CLANG) || ZTD_IS_ON(ZTD_COMPILER_GC)
#define ztdc_ckd_add(_PTR, _LEFT, _RIGHT) __builtin_add_overflow(_LEFT, _RIGHT, _PTR)
#define ztdc_ckd_sub(_PTR, _LEFT, _RIGHT) __builtin_sub_overflow(_LEFT, _RIGHT, _PTR)
#define ztdc_ckd_mul(_PTR, _LEFT, _RIGHT) __builtin_mul_overflow(_LEFT, _RIGHT, _PTR)
#else
#define ztdc_ckd_add(_PTR, _LEFT, _RIGHT)
#define ztdc_ckd_add(_PTR, _LEFT, _RIGHT)
#define ztdc_ckd_add(_PTR, _LEFT, _RIGHT)
#endif

#include <ztd/epilogue.hpp>

#endif // ZTD_IDK_CKD_INT_H
2 changes: 1 addition & 1 deletion include/ztd/idk/contiguous_iterator_tag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace ztd {
} // namespace __idk_detail

//////
/// @brief Either a typedef or a polyfill of the contiguous iterator text_tag, only standardized in C++20.
/// @brief Either a typedef or a polyfill of the contiguous iterator tag, only standardized in C++20.
///
//////
using contiguous_iterator_tag =
Expand Down
4 changes: 2 additions & 2 deletions include/ztd/idk/hijack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/// @brief A token to derive from, which in some cases allows external members to place customization points and
/// extension functions in the global namespace. This is useful for enabling functionality against C-like types.
//////
template <typename>
template <typename...>
class ztd_hijack_global_token { };

namespace ztd { namespace hijack {
Expand All @@ -56,7 +56,7 @@ namespace ztd { namespace hijack {
/// extension functions in the hijack namespace. Extension points would be defined in the "namespace ztd {
/// namespace hijack { /* here */ }}" area.
//////
template <typename>
template <typename...>
class token { };

}} // namespace ztd::hijack
Expand Down
62 changes: 62 additions & 0 deletions include/ztd/idk/tag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// =============================================================================
//
// ztd.idk
// Copyright © 2022 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
// Contact: opensource@soasis.org
//
// Commercial License Usage
// Licensees holding valid commercial ztd.idk licenses may use this file in
// accordance with the commercial license agreement provided with the
// Software or, alternatively, in accordance with the terms contained in
// a written agreement between you and Shepherd's Oasis, LLC.
// For licensing terms and conditions see your agreement. For
// further information contact opensource@soasis.org.
//
// Apache License Version 2 Usage
// Alternatively, this file may be used under the terms of Apache License
// Version 2.0 (the "License") for non-commercial use; you may not use this
// file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ============================================================================ //

#pragma once

#ifndef ZTD_IDK_TAG_HPP
#define ZTD_IDK_TAG_HPP

#include <ztd/idk/version.hpp>

#include <ztd/prologue.hpp>

//////
/// @addtogroup ztd_idk_tags Tags
/// @{
//////

namespace ztd {

//////
/// @brief A tag type which can hold arbitrarily many types. Useful as an anchor for overload resolution on
/// specific entities, extension point anchors, and more. Not related to the ztd::tag_invoke infrastructure.
//////
template <typename...>
class tag { };

} // namespace ztd

/// @}
//////


#include <ztd/epilogue.hpp>

#endif // ZTD_IDK_TAG_HPP

0 comments on commit afc7e81

Please sign in to comment.