1/*
2 * Copyright 2011, Michael Lotz <mmlr@mlotz.ch>.
3 * Copyright 2011, Ingo Weinhold <ingo_weinhold@gmx.de>.
4 *
5 * Distributed under the terms of the MIT License.
6 */
7#ifndef ALLOCATION_TRACKING_H
8#define ALLOCATION_TRACKING_H
9
10
11#include <debug.h>
12#include <tracing.h>
13
14
15namespace BKernel {
16
17class AllocationTrackingInfo {
18public:
19	AbstractTraceEntryWithStackTrace*	traceEntry;
20	bigtime_t							traceEntryTimestamp;
21
22public:
23	void Init(AbstractTraceEntryWithStackTrace* entry)
24	{
25		traceEntry = entry;
26		traceEntryTimestamp = entry != NULL ? entry->Time() : -1;
27			// Note: this is a race condition, if the tracing buffer wrapped and
28			// got overwritten once, we would access an invalid trace entry
29			// here. Obviously this is rather unlikely.
30	}
31
32	void Clear()
33	{
34		traceEntry = NULL;
35		traceEntryTimestamp = 0;
36	}
37
38	bool IsInitialized() const
39	{
40		return traceEntryTimestamp != 0;
41	}
42
43	AbstractTraceEntryWithStackTrace* TraceEntry() const
44	{
45		return traceEntry;
46	}
47
48	bool IsTraceEntryValid() const
49	{
50		return tracing_is_entry_valid(traceEntry, traceEntryTimestamp);
51	}
52};
53
54}	// namespace BKernel
55
56
57using BKernel::AllocationTrackingInfo;
58
59
60#endif	// ALLOCATION_TRACKING_H
61