| OLD | NEW |
| 1 // Copyright (c) 2011, Google Inc. | 1 // Copyright (c) 2011, 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 22 matching lines...) Expand all Loading... |
| 33 // This file contains declarations of functions that implement doubly | 33 // This file contains declarations of functions that implement doubly |
| 34 // linked lists and definitions of functions that implement singly | 34 // linked lists and definitions of functions that implement singly |
| 35 // linked lists. It also contains macros to tell the SizeMap class | 35 // linked lists. It also contains macros to tell the SizeMap class |
| 36 // how much space a node in the freelist needs so that SizeMap can | 36 // how much space a node in the freelist needs so that SizeMap can |
| 37 // create large enough size classes. | 37 // create large enough size classes. |
| 38 | 38 |
| 39 #ifndef TCMALLOC_FREE_LIST_H_ | 39 #ifndef TCMALLOC_FREE_LIST_H_ |
| 40 #define TCMALLOC_FREE_LIST_H_ | 40 #define TCMALLOC_FREE_LIST_H_ |
| 41 | 41 |
| 42 #include <stddef.h> | 42 #include <stddef.h> |
| 43 #include "internal_logging.h" // For CRASH() macro. |
| 43 #include "linked_list.h" | 44 #include "linked_list.h" |
| 44 | 45 |
| 45 namespace tcmalloc { | 46 namespace tcmalloc { |
| 46 | 47 |
| 47 #ifdef TCMALLOC_USE_DOUBLYLINKED_FREELIST | 48 #ifdef TCMALLOC_USE_DOUBLYLINKED_FREELIST |
| 48 | 49 |
| 49 // size class information for common.h. | 50 // size class information for common.h. |
| 50 static const bool kSupportsDoublyLinkedList = true; | 51 static const bool kSupportsDoublyLinkedList = true; |
| 51 | 52 |
| 52 void *FL_Next(void *t); | 53 void *FL_Next(void *t); |
| 53 void FL_Init(void *t); | 54 void FL_Init(void *t); |
| 54 void FL_Push(void **list, void *element); | 55 void FL_Push(void **list, void *element); |
| 55 void *FL_Pop(void **list); | 56 void *FL_Pop(void **list); |
| 56 void FL_PopRange(void **head, int n, void **start, void **end); | 57 void FL_PopRange(void **head, int n, void **start, void **end); |
| 57 void FL_PushRange(void **head, void *start, void *end); | 58 void FL_PushRange(void **head, void *start, void *end); |
| 58 size_t FL_Size(void *head); | 59 size_t FL_Size(void *head); |
| 59 | 60 |
| 60 #else // TCMALLOC_USE_DOUBLYLINKED_FREELIST not defined | 61 #else // TCMALLOC_USE_DOUBLYLINKED_FREELIST not defined |
| 61 static const bool kSupportsDoublyLinkedList = false; | 62 static const bool kSupportsDoublyLinkedList = false; |
| 62 | 63 |
| 63 inline void *FL_Next(void *t) { | 64 inline void *FL_Next(void *t) { |
| 64 return SLL_Next(t); | 65 return SLL_Next(t); |
| 65 } | 66 } |
| 66 | 67 |
| 67 inline void FL_Init(void *t) { | 68 inline void FL_Init(void *t) { |
| 68 SLL_SetNext(t, NULL); | 69 SLL_SetNext(t, NULL); |
| 69 } | 70 } |
| 70 | 71 |
| 71 inline void FL_Push(void **list, void *element) { | 72 inline void FL_Push(void **list, void *element) { |
| 72 SLL_Push(list,element); | 73 if(*list != element) { |
| 74 SLL_Push(list,element); |
| 75 return; |
| 76 } |
| 77 CRASH("Double Free of %p detected", element); |
| 73 } | 78 } |
| 74 | 79 |
| 75 inline void *FL_Pop(void **list) { | 80 inline void *FL_Pop(void **list) { |
| 76 return SLL_Pop(list); | 81 return SLL_Pop(list); |
| 77 } | 82 } |
| 78 | 83 |
| 79 // Removes |N| elements from a linked list to which |head| points. | 84 // Removes |N| elements from a linked list to which |head| points. |
| 80 // |head| will be modified to point to the new |head|. |start| and | 85 // |head| will be modified to point to the new |head|. |start| and |
| 81 // |end| will point to the first and last nodes of the range. Note | 86 // |end| will point to the first and last nodes of the range. Note |
| 82 // that |end| will point to NULL after this function is called. | 87 // that |end| will point to NULL after this function is called. |
| 83 inline void FL_PopRange(void **head, int n, void **start, void **end) { | 88 inline void FL_PopRange(void **head, int n, void **start, void **end) { |
| 84 SLL_PopRange(head, n, start, end); | 89 SLL_PopRange(head, n, start, end); |
| 85 } | 90 } |
| 86 | 91 |
| 87 inline void FL_PushRange(void **head, void *start, void *end) { | 92 inline void FL_PushRange(void **head, void *start, void *end) { |
| 88 SLL_PushRange(head,start,end); | 93 SLL_PushRange(head,start,end); |
| 89 } | 94 } |
| 90 | 95 |
| 91 inline size_t FL_Size(void *head) { | 96 inline size_t FL_Size(void *head) { |
| 92 return SLL_Size(head); | 97 return SLL_Size(head); |
| 93 } | 98 } |
| 94 | 99 |
| 95 #endif // TCMALLOC_USE_DOUBLYLINKED_FREELIST | 100 #endif // TCMALLOC_USE_DOUBLYLINKED_FREELIST |
| 96 | 101 |
| 97 } // namespace tcmalloc | 102 } // namespace tcmalloc |
| 98 | 103 |
| 99 #endif // TCMALLOC_FREE_LIST_H_ | 104 #endif // TCMALLOC_FREE_LIST_H_ |
| OLD | NEW |