• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ink_align.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 //-*-c++-*-
00025 #ifndef _ink_align_h_
00026 #define _ink_align_h_
00027 
00028 # include "ink_time.h"
00029 
00030 union Alias32 {
00031   uint8_t byte[4];
00032   int32_t i32;
00033   uint32_t u32;
00034 };
00035 
00036 union Alias64 {
00037   uint8_t byte[8];
00038   int32_t i32[2];
00039   uint32_t u32[2];
00040   int64_t i64;
00041   uint64_t u64;
00042   ink_time_t i_time;
00043 };
00044 
00045 /**
00046  * Alignment macros
00047  */
00048 
00049 #define INK_MIN_ALIGN 8
00050 /* INK_ALIGN() is only to be used to align on a power of 2 boundary */
00051 #define INK_ALIGN(size, boundary) \
00052     (((size) + ((boundary) - 1)) & ~((boundary) - 1))
00053 
00054 /** Default alignment */
00055 #define INK_ALIGN_DEFAULT(size) INK_ALIGN(size, INK_MIN_ALIGN)
00056 
00057 //
00058 // Move a pointer forward until it meets the alignment width.
00059 //
00060 static inline void *
00061 align_pointer_forward(const void *pointer_, size_t alignment)
00062 {
00063   char *pointer = (char *) pointer_;
00064   //
00065   // Round up alignment..
00066   //
00067   pointer = (char *) INK_ALIGN((ptrdiff_t) pointer, alignment);
00068 
00069   return (void *) pointer;
00070 }
00071 
00072 //
00073 // Move a pointer forward until it meets the alignment width specified,
00074 // and zero out the contents of the space you're skipping over.
00075 //
00076 static inline void *
00077 align_pointer_forward_and_zero(const void *pointer_, size_t alignment)
00078 {
00079   char *pointer = (char *) pointer_;
00080   char *aligned = (char *) INK_ALIGN((ptrdiff_t) pointer, alignment);
00081   //
00082   // Fill the skippings..
00083   //
00084   while (pointer < aligned) {
00085     *pointer = 0;
00086     pointer++;
00087   }
00088 
00089   return (void *) aligned;
00090 }
00091 
00092 //
00093 // We include two signatures for the same function to avoid error
00094 // messages concerning coercion between void* and unsigned long.
00095 // We could handle this using casts, but that's more prone to
00096 // errors during porting.
00097 //
00098 
00099 #endif

Generated by  doxygen 1.7.1