| OLD | NEW |
| 1 // Copyright (c) 2007, Google Inc. | 1 // Copyright (c) 2007, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // if a whole key plus a whole value fits in an entry. Otherwise, an | 104 // if a whole key plus a whole value fits in an entry. Otherwise, an |
| 105 // entry is the high bits of a key and a value, packed together. | 105 // entry is the high bits of a key and a value, packed together. |
| 106 // E.g., a 20 bit key and a 7 bit value only require a uint16 for each | 106 // E.g., a 20 bit key and a 7 bit value only require a uint16 for each |
| 107 // entry if kHashbits >= 11. | 107 // entry if kHashbits >= 11. |
| 108 // | 108 // |
| 109 // Alternatives to this scheme will be added as needed. | 109 // Alternatives to this scheme will be added as needed. |
| 110 | 110 |
| 111 #ifndef TCMALLOC_PACKED_CACHE_INL_H_ | 111 #ifndef TCMALLOC_PACKED_CACHE_INL_H_ |
| 112 #define TCMALLOC_PACKED_CACHE_INL_H_ | 112 #define TCMALLOC_PACKED_CACHE_INL_H_ |
| 113 | 113 |
| 114 #include "config.h" | |
| 115 #ifdef HAVE_STDINT_H | |
| 116 #include <stdint.h> | |
| 117 #endif | |
| 118 #include "base/basictypes.h" // for COMPILE_ASSERT | 114 #include "base/basictypes.h" // for COMPILE_ASSERT |
| 119 #include "internal_logging.h" | 115 #include "internal_logging.h" |
| 120 | 116 |
| 121 // A safe way of doing "(1 << n) - 1" -- without worrying about overflow | 117 // A safe way of doing "(1 << n) - 1" -- without worrying about overflow |
| 122 // Note this will all be resolved to a constant expression at compile-time | 118 // Note this will all be resolved to a constant expression at compile-time |
| 123 #define N_ONES_(IntType, N) \ | 119 #define N_ONES_(IntType, N) \ |
| 124 ( (N) == 0 ? 0 : ((static_cast<IntType>(1) << ((N)-1))-1 + \ | 120 ( (N) == 0 ? 0 : ((static_cast<IntType>(1) << ((N)-1))-1 + \ |
| 125 (static_cast<IntType>(1) << ((N)-1))) ) | 121 (static_cast<IntType>(1) << ((N)-1))) ) |
| 126 | 122 |
| 127 // The types K and V provide upper bounds on the number of valid keys | 123 // The types K and V provide upper bounds on the number of valid keys |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 static const V kValueMask = N_ONES_(V, kValuebits); | 219 static const V kValueMask = N_ONES_(V, kValuebits); |
| 224 | 220 |
| 225 // array_ is the cache. Its elements are volatile because any | 221 // array_ is the cache. Its elements are volatile because any |
| 226 // thread can write any array element at any time. | 222 // thread can write any array element at any time. |
| 227 volatile T array_[1 << kHashbits]; | 223 volatile T array_[1 << kHashbits]; |
| 228 }; | 224 }; |
| 229 | 225 |
| 230 #undef N_ONES_ | 226 #undef N_ONES_ |
| 231 | 227 |
| 232 #endif // TCMALLOC_PACKED_CACHE_INL_H_ | 228 #endif // TCMALLOC_PACKED_CACHE_INL_H_ |
| OLD | NEW |