LCOV - code coverage report
Current view: top level - sal/rtl/source - alloc_impl.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 29 30 96.7 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 24 95.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef INCLUDED_RTL_ALLOC_IMPL_HXX
      30                 :            : #define INCLUDED_RTL_ALLOC_IMPL_HXX
      31                 :            : 
      32                 :            : #include "sal/types.h"
      33                 :            : 
      34                 :            : /** Alignment macros
      35                 :            :  */
      36                 :            : #if SAL_TYPES_ALIGNMENT4 > 1
      37                 :            : #define RTL_MEMORY_ALIGNMENT_4 SAL_TYPES_ALIGNMENT4
      38                 :            : #else
      39                 :            : #define RTL_MEMORY_ALIGNMENT_4 sizeof(int)
      40                 :            : #endif /* SAL_TYPES_ALIGNMENT4 */
      41                 :            : 
      42                 :            : #if SAL_TYPES_ALIGNMENT8 > 1
      43                 :            : #define RTL_MEMORY_ALIGNMENT_8 SAL_TYPES_ALIGNMENT8
      44                 :            : #else
      45                 :            : #define RTL_MEMORY_ALIGNMENT_8 sizeof(void*)
      46                 :            : #endif /* SAL_TYPES_ALIGNMENT8 */
      47                 :            : 
      48                 :            : #if 0  /* @@@ */
      49                 :            : #define RTL_MEMORY_ALIGNMENT_1 8
      50                 :            : #define RTL_MEMORY_ALIGNMENT_2 (sizeof(void*) * 2)
      51                 :            : #endif /* @@@ */
      52                 :            : 
      53                 :            : #define RTL_MEMORY_ALIGN(value, align) (((value) + ((align) - 1)) & ~((align) - 1))
      54                 :            : 
      55                 :            : #define RTL_MEMORY_ISP2(value) (((value) & ((value) - 1)) == 0)
      56                 :            : #define RTL_MEMORY_P2ALIGN(value, align) ((value) & -(sal_IntPtr)(align))
      57                 :            : 
      58                 :            : #define RTL_MEMORY_P2ROUNDUP(value, align) \
      59                 :            :     (-(-(sal_IntPtr)(value) & -(sal_IntPtr)(align)))
      60                 :            : #define RTL_MEMORY_P2END(value, align) \
      61                 :            :     (-(~(sal_IntPtr)(value) & -(sal_IntPtr)(align)))
      62                 :            : 
      63                 :            : 
      64                 :            : /** Function inlining macros
      65                 :            :  *  (compiler dependent)
      66                 :            :  */
      67                 :            : #ifndef RTL_MEMORY_INLINE
      68                 :            : #if defined(__GNUC__)
      69                 :            : #define RTL_MEMORY_INLINE __inline__
      70                 :            : #elif defined(_MSC_VER)
      71                 :            : #define RTL_MEMORY_INLINE __inline
      72                 :            : #else
      73                 :            : #define RTL_MEMORY_INLINE
      74                 :            : #endif /* __GNUC__ || _MSC_VER */
      75                 :            : #endif /* RTL_MEMORY_INLINE */
      76                 :            : 
      77                 :            : 
      78                 :            : /** printf() format specifier(s)
      79                 :            :  *  (from C90 <sys/int_fmtio.h>)
      80                 :            :  */
      81                 :            : #ifndef PRIu64
      82                 :            : #if defined(_MSC_VER)
      83                 :            : #define PRIu64 "I64u"
      84                 :            : #else  /* !_MSC_VER */
      85                 :            : #define PRIu64 "llu"
      86                 :            : #endif /* !_MSC_VER */
      87                 :            : #endif /* PRIu64 */
      88                 :            : 
      89                 :            : 
      90                 :            : /** highbit(): log2() + 1
      91                 :            :  *  (complexity O(1))
      92                 :            :  */
      93                 :            : static RTL_MEMORY_INLINE int
      94                 :    1719497 : highbit(sal_Size n)
      95                 :            : {
      96                 :    1719497 :   int k = 1;
      97                 :            : 
      98         [ -  + ]:    1719497 :   if (n == 0)
      99                 :          0 :     return (0);
     100                 :            : #if SAL_TYPES_SIZEOFLONG == 8
     101                 :            :   if (n & 0xffffffff00000000ul)
     102                 :            :     k |= 32, n >>= 32;
     103                 :            : #endif
     104         [ +  + ]:    1719497 :   if (n & 0xffff0000)
     105                 :      13906 :     k |= 16, n >>= 16;
     106         [ +  + ]:    1719497 :   if (n & 0xff00)
     107                 :    1491677 :     k |= 8, n >>= 8;
     108         [ +  + ]:    1719497 :   if (n & 0xf0)
     109                 :    1056939 :     k |= 4, n >>= 4;
     110         [ +  + ]:    1719497 :   if (n & 0x0c)
     111                 :    1229909 :     k |= 2, n >>= 2;
     112         [ +  + ]:    1719497 :   if (n & 0x02)
     113                 :     877240 :     k++;
     114                 :            : 
     115                 :    1719497 :   return (k);
     116                 :            : }
     117                 :            : 
     118                 :            : #if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
     119                 :            : #pragma inline(highbit)
     120                 :            : #endif /* __SUNPRO_C */
     121                 :            : 
     122                 :            : 
     123                 :            : /** lowbit(): find first bit set
     124                 :            :  *  (complexity O(1))
     125                 :            :  */
     126                 :            : static RTL_MEMORY_INLINE int
     127                 :     714703 : lowbit(sal_Size n)
     128                 :            : {
     129                 :     714703 :   int k = 1;
     130                 :            : 
     131         [ +  + ]:     714703 :   if (n == 0)
     132                 :     213050 :     return (0);
     133                 :            : #if SAL_TYPES_SIZEOFLONG == 8
     134                 :            :   if (!(n & 0xffffffff))
     135                 :            :     k |= 32, n >>= 32;
     136                 :            : #endif
     137         [ +  + ]:     501653 :   if (!(n & 0xffff))
     138                 :       1012 :     k |= 16, n >>= 16;
     139         [ +  + ]:     501653 :   if (!(n & 0xff))
     140                 :     500641 :     k |= 8, n >>= 8;
     141         [ +  + ]:     501653 :   if (!(n & 0xf))
     142                 :     388814 :     k |= 4, n >>= 4;
     143         [ +  + ]:     501653 :   if (!(n & 0x3))
     144                 :     418083 :     k |= 2, n >>= 2;
     145         [ +  + ]:     501653 :   if (!(n & 0x1))
     146                 :     357286 :     k++;
     147                 :     714703 :   return (k);
     148                 :            : }
     149                 :            : 
     150                 :            : #if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
     151                 :            : #pragma inline(lowbit)
     152                 :            : #endif /* __SUNPRO_C */
     153                 :            : 
     154                 :            : 
     155                 :            : /** Queue manipulation macros
     156                 :            :  *  (doubly linked circular list)
     157                 :            :  *  (complexity O(1))
     158                 :            :  */
     159                 :            : #define QUEUE_STARTED_NAMED(entry, name) \
     160                 :            :   (((entry)->m_##name##next == (entry)) && ((entry)->m_##name##prev == (entry)))
     161                 :            : 
     162                 :            : #define QUEUE_START_NAMED(entry, name) \
     163                 :            : { \
     164                 :            :   (entry)->m_##name##next = (entry); \
     165                 :            :   (entry)->m_##name##prev = (entry); \
     166                 :            : }
     167                 :            : 
     168                 :            : #define QUEUE_REMOVE_NAMED(entry, name) \
     169                 :            : { \
     170                 :            :   (entry)->m_##name##prev->m_##name##next = (entry)->m_##name##next; \
     171                 :            :   (entry)->m_##name##next->m_##name##prev = (entry)->m_##name##prev; \
     172                 :            :   QUEUE_START_NAMED(entry, name); \
     173                 :            : }
     174                 :            : 
     175                 :            : #define QUEUE_INSERT_HEAD_NAMED(head, entry, name) \
     176                 :            : { \
     177                 :            :   (entry)->m_##name##prev = (head); \
     178                 :            :   (entry)->m_##name##next = (head)->m_##name##next; \
     179                 :            :   (head)->m_##name##next = (entry); \
     180                 :            :   (entry)->m_##name##next->m_##name##prev = (entry); \
     181                 :            : }
     182                 :            : 
     183                 :            : #define QUEUE_INSERT_TAIL_NAMED(head, entry, name) \
     184                 :            : { \
     185                 :            :   (entry)->m_##name##next = (head); \
     186                 :            :   (entry)->m_##name##prev = (head)->m_##name##prev; \
     187                 :            :   (head)->m_##name##prev = (entry); \
     188                 :            :   (entry)->m_##name##prev->m_##name##next = (entry); \
     189                 :            : }
     190                 :            : 
     191                 :            : 
     192                 :            : /** rtl_memory_lock_type
     193                 :            :  *  (platform dependent)
     194                 :            :  */
     195                 :            : #if defined(SAL_UNX)
     196                 :            : 
     197                 :            : #include <unistd.h>
     198                 :            : #include <pthread.h>
     199                 :            : 
     200                 :            : typedef pthread_mutex_t rtl_memory_lock_type;
     201                 :            : 
     202                 :            : #define RTL_MEMORY_LOCK_INIT(lock)    pthread_mutex_init((lock), NULL)
     203                 :            : #define RTL_MEMORY_LOCK_DESTROY(lock) pthread_mutex_destroy((lock))
     204                 :            : 
     205                 :            : #define RTL_MEMORY_LOCK_ACQUIRE(lock) pthread_mutex_lock((lock))
     206                 :            : #define RTL_MEMORY_LOCK_RELEASE(lock) pthread_mutex_unlock((lock))
     207                 :            : 
     208                 :            : #elif defined(SAL_W32)
     209                 :            : 
     210                 :            : #define WIN32_LEAN_AND_MEAN
     211                 :            : #ifdef _MSC_VER
     212                 :            : #pragma warning(push,1) /* disable warnings within system headers */
     213                 :            : #endif
     214                 :            : #include <windows.h>
     215                 :            : #ifdef _MSC_VER
     216                 :            : #pragma warning(pop)
     217                 :            : #endif
     218                 :            : 
     219                 :            : typedef CRITICAL_SECTION rtl_memory_lock_type;
     220                 :            : 
     221                 :            : #define RTL_MEMORY_LOCK_INIT(lock)    InitializeCriticalSection((lock))
     222                 :            : #define RTL_MEMORY_LOCK_DESTROY(lock) DeleteCriticalSection((lock))
     223                 :            : 
     224                 :            : #define RTL_MEMORY_LOCK_ACQUIRE(lock) EnterCriticalSection((lock))
     225                 :            : #define RTL_MEMORY_LOCK_RELEASE(lock) LeaveCriticalSection((lock))
     226                 :            : 
     227                 :            : #else
     228                 :            : #error Unknown platform
     229                 :            : #endif /* SAL_UNX | SAL_W32 */
     230                 :            : 
     231                 :            : 
     232                 :            : /** Cache creation flags.
     233                 :            :  *  @internal
     234                 :            :  */
     235                 :            : #define RTL_CACHE_FLAG_NOMAGAZINE   (1 << 13) /* w/o magazine layer */
     236                 :            : #define RTL_CACHE_FLAG_QUANTUMCACHE (2 << 13) /* used as arena quantum cache */
     237                 :            : 
     238                 :            : typedef enum { AMode_CUSTOM, AMode_SYSTEM, AMode_UNSET } AllocMode;
     239                 :            : 
     240                 :            : extern AllocMode alloc_mode;
     241                 :            : 
     242                 :            : #endif /* INCLUDED_RTL_ALLOC_IMPL_HXX */
     243                 :            : 
     244                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10