133c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris/* 233c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * Copyright (C) 2015 The Android Open Source Project 333c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * 433c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * Licensed under the Apache License, Version 2.0 (the "License"); 533c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * you may not use this file except in compliance with the License. 633c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * You may obtain a copy of the License at 733c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * 833c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * http://www.apache.org/licenses/LICENSE-2.0 933c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * 1033c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * Unless required by applicable law or agreed to in writing, software 1133c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * distributed under the License is distributed on an "AS IS" BASIS, 1233c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1333c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * See the License for the specific language governing permissions and 1433c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris * limitations under the License. 1533c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris */ 1633c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 1733c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris#ifndef _MEMORY_REPLAY_POINTERS_H 1833c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris#define _MEMORY_REPLAY_POINTERS_H 1933c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 2033c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris#include <stdatomic.h> 2133c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris#include <stdint.h> 2233c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 2333c03d38298ff359d8829aea91bb02b26caab245Christopher Ferrisstruct pointer_data { 2433c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris std::atomic_uintptr_t key_pointer; 2533c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris void* pointer; 2633c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris}; 2733c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 2833c03d38298ff359d8829aea91bb02b26caab245Christopher Ferrisclass Pointers { 2933c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris public: 3033c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris Pointers(size_t max_allocs); 3133c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris virtual ~Pointers(); 3233c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 3333c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris void Add(uintptr_t key_pointer, void* pointer); 3433c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 3533c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris void* Remove(uintptr_t key_pointer); 3633c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 3733c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris size_t max_pointers() { return max_pointers_; } 3833c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 3933c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris void FreeAll(); 4033c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 4133c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris private: 4233c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris pointer_data* FindEmpty(uintptr_t key_pointer); 4333c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris pointer_data* Find(uintptr_t key_pointer); 4433c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris size_t GetHash(uintptr_t key_pointer); 4533c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 4633c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris pointer_data* pointers_ = nullptr; 4733c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris size_t pointers_size_ = 0; 4833c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris size_t max_pointers_ = 0; 4933c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris}; 5033c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris 5133c03d38298ff359d8829aea91bb02b26caab245Christopher Ferris#endif // _MEMORY_REPLAY_POINTERS_H 52