aboutsummaryrefslogtreecommitdiff
path: root/tools/gator/daemon/Buffer.h
blob: f820cfd851e32399a4108511bf0b81180a17ada0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
 * Copyright (C) ARM Limited 2013. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef BUFFER_H
#define BUFFER_H

#include <stddef.h>
#include <stdint.h>
#include <semaphore.h>

class Sender;

class Buffer {
public:
	static const size_t MAXSIZE_PACK32 = 5;
	static const size_t MAXSIZE_PACK64 = 10;

	Buffer (int32_t core, int32_t buftype, const int size, sem_t *const readerSem);
	~Buffer ();

	void write (Sender * sender);

	int bytesAvailable () const;
	void commit (const uint64_t time);
	void check (const uint64_t time);

	void frame ();

	bool eventHeader (uint64_t curr_time);
	void event (int32_t key, int32_t value);
	void event64 (int64_t key, int64_t value);

	void setDone ();
	bool isDone () const;

private:
	bool commitReady () const;
	bool checkSpace (int bytes);

	void packInt (int32_t x);
	void packInt64 (int64_t x);

	const int32_t core;
	const int32_t buftype;
	const int size;
	int readPos;
	int writePos;
	int commitPos;
	bool available;
	bool done;
	char *const buf;
	uint64_t commitTime;
	sem_t *const readerSem;
};

#endif // BUFFER_H