[libcamera-devel] [PATCH 01/21] libcamera: utils: Provide an ALIGN macro

Kieran Bingham kieran.bingham at ideasonboard.com
Thu Sep 26 21:58:05 CEST 2019


Hi Jacopo,

On 24/09/2019 18:24, Jacopo Mondi wrote:

I know there's not much to say, but I always fear an empty commit
message :-D

> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
> ---
>  src/libcamera/include/utils.h |  2 ++
>  src/libcamera/utils.cpp       | 11 +++++++++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h
> index 52eee8ac2804..08323966b44e 100644
> --- a/src/libcamera/include/utils.h
> +++ b/src/libcamera/include/utils.h
> @@ -63,6 +63,8 @@ using time_point = std::chrono::steady_clock::time_point;
>  struct timespec duration_to_timespec(const duration &value);
>  std::string time_point_to_string(const time_point &time);
>  
> +#define ALIGN(_s, _a) (((_s) + (_a - 1)) & ~(_a - 1))
> +
>  } /* namespace utils */
>  
>  } /* namespace libcamera */
> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
> index 928db254ec67..c3188bfff03d 100644
> --- a/src/libcamera/utils.cpp
> +++ b/src/libcamera/utils.cpp
> @@ -143,6 +143,17 @@ std::string time_point_to_string(const time_point &time)
>  	return ossTimestamp.str();
>  }
>  
> +/**
> + * \def ALIGN(_s, _a)
> + * \brief Align a size to a boundary
> + * \param[in] _s The size to align
> + * \param[in] _a The boundary to align size to
> + *
> + * Align the provide size \a _s to a the provided boundary. The request
> + * alignement should be a power of 2, and the aligned size is up aligned to

s/alignement/alignment/

> + * the given boundary.
> + */

I haven't yet seen how this macro is to be used, but C++11 has alignof()
and alignas() keywords.

Have you considered them?

I guess it will depend on whether you are looking to reserve an area
where the size is a power of 2, or if you are just trying to allocate on
boundaries.

I guess that might also suggest that merging this into a patch where it
is used would clarify it's intended usage.

> +
>  } /* namespace utils */
>  
>  } /* namespace libcamera */
> 

-- 
Regards
--
Kieran


More information about the libcamera-devel mailing list