| OLD | NEW |
| 1 /* Copyright (c) 2006, Google Inc. | 1 /* Copyright (c) 2006, 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // ATTRIBUTE_SECTION(malloc_hook) for Alloc* and Free | 65 // ATTRIBUTE_SECTION(malloc_hook) for Alloc* and Free |
| 66 // are to put all callers of MallocHook::Invoke* in this module | 66 // are to put all callers of MallocHook::Invoke* in this module |
| 67 // into special section, | 67 // into special section, |
| 68 // so that MallocHook::GetCallerStackTrace can function accurately. | 68 // so that MallocHook::GetCallerStackTrace can function accurately. |
| 69 | 69 |
| 70 // Create a new arena. | 70 // Create a new arena. |
| 71 // The root metadata for the new arena is allocated in the | 71 // The root metadata for the new arena is allocated in the |
| 72 // meta_data_arena; the DefaultArena() can be passed for meta_data_arena. | 72 // meta_data_arena; the DefaultArena() can be passed for meta_data_arena. |
| 73 // These values may be ored into flags: | 73 // These values may be ored into flags: |
| 74 enum { | 74 enum { |
| 75 // Report calls to Alloc() and Free() via the MallocHook interface. | 75 // Calls to Alloc() and Free() will be reported |
| 76 // Set in the DefaultArena. | 76 // via the MallocHook interface. |
| 77 kCallMallocHook = 0x0001, | 77 // The DefaultArena() has this flag on. |
| 78 | 78 // NewArena(flags, DefaultArena()) w/o this bit in 'flags', |
| 79 // Make calls to Alloc(), Free() be async-signal-safe. Not set in | 79 // on the other hand, will not cause any MallocHook |
| 80 // DefaultArena(). | 80 // calls even during the NewArena call itself |
| 81 kAsyncSignalSafe = 0x0002, | 81 // (it will in fact use meta_data_arena different from DefaultArena()). |
| 82 | 82 kCallMallocHook = 0x0001 |
| 83 // When used with DefaultArena(), the NewArena() and DeleteArena() calls | |
| 84 // obey the flags given explicitly in the NewArena() call, even if those | |
| 85 // flags differ from the settings in DefaultArena(). So the call | |
| 86 // NewArena(kAsyncSignalSafe, DefaultArena()) is itself async-signal-safe, | |
| 87 // as well as generatating an arena that provides async-signal-safe | |
| 88 // Alloc/Free. | |
| 89 }; | 83 }; |
| 90 static Arena *NewArena(int32 flags, Arena *meta_data_arena); | 84 static Arena *NewArena(int32 flags, Arena *meta_data_arena); |
| 91 | 85 |
| 92 // Destroys an arena allocated by NewArena and returns true, | 86 // Destroys an arena allocated by NewArena and returns true, |
| 93 // provided no allocated blocks remain in the arena. | 87 // provided no allocated blocks remain in the arena. |
| 94 // If allocated blocks remain in the arena, does nothing and | 88 // If allocated blocks remain in the arena, does nothing and |
| 95 // returns false. | 89 // returns false. |
| 96 // It is illegal to attempt to destroy the DefaultArena(). | 90 // It is illegal to attempt to destroy the DefaultArena(). |
| 97 static bool DeleteArena(Arena *arena); | 91 static bool DeleteArena(Arena *arena); |
| 98 | 92 |
| 99 // The default arena that always exists. | 93 // The default arena that always exists. |
| 100 static Arena *DefaultArena(); | 94 static Arena *DefaultArena(); |
| 101 | 95 |
| 102 private: | 96 private: |
| 103 LowLevelAlloc(); // no instances | 97 LowLevelAlloc(); // no instances |
| 104 }; | 98 }; |
| 105 | 99 |
| 106 #endif | 100 #endif |
| OLD | NEW |