Commit befbc2f5 authored by DEPRECATED (Jonathan Mace) (Use @JonathanMace instead)'s avatar DEPRECATED (Jonathan Mace) (Use @JonathanMace instead)
Browse files

Rearrange some of the files, to reduce the footprint of included headers

parent 90262630
#ifndef _ATOM_LAYER_H_
#define _ATOM_LAYER_H_
#ifndef _BAGGAGE_H_
#define _BAGGAGE_H_
#include <iostream>
#include <cstdint>
......@@ -7,39 +7,46 @@
#include <vector>
/*
This file defines the main interfaces (Atoms and Baggage) of the Brown Tracing Plane
Most interactions will be with Baggage and ThreadLocalBaggage
*/
// An atom is just an array of bytes
struct Atom {
std::vector<uint8_t> bytes;
Atom() : bytes(0) {}
Atom(int x) : bytes(4) {
for (unsigned i = 0; i < 4; i++) {
bytes[3-i] = (x >> (i * 8));
}
}
Atom(int size) : bytes(size) {}
Atom(std::vector<uint8_t> bytes) : bytes(bytes) {}
// Lexicographic comparison of two atoms
const int compare(const Atom& other);
friend std::ostream& operator<< ( std::ostream& os, const Atom& atom );
};
// Baggage is an array of atoms
struct Baggage {
std::vector<Atom> atoms;
Baggage() : atoms(0) {}
// Duplicates this baggage
Baggage branch();
// Lexicographic merge of two baggage instances, as defined in the Brown Tracing Plane
static Baggage merge(Baggage& a, Baggage& b);
// Serialize this baggage, as defined in the Brown Tracing Plane (length-prefix each atom in order)
std::vector<uint8_t> serialize();
// Deserialize a serialized baggage instance, as defined in the Brown Tracing Plane
static Baggage deserialize(std::vector<uint8_t> bytes);
friend std::ostream& operator<< ( std::ostream& os, const Baggage& baggage );
......@@ -47,4 +54,18 @@ struct Baggage {
};
// Helper methods for storing a baggage instance in thread-local storage. Usage is optional, but very useful
namespace ThreadLocalBaggage {
Baggage& Get(); // Get the current thread's baggage
Baggage Take(); // Get the current thread's baggage, and clear the thread-local storage
Baggage Branch(); // Get a copy of the current thread's baggage
void Delete(); // Delete the current thread's baggage
void Set(Baggage new_baggage); // Set the current thread's baggage to the provided baggage, destroying the previous baggage
void Join(Baggage &otherBaggage); // Merge the current thread's baggage with the provided baggage
}
#endif
\ No newline at end of file
#ifndef _THREAD_LOCAL_BAGGAGE_H_
#define _THREAD_LOCAL_BAGGAGE_H_
#include "atomlayer.h"
namespace ThreadLocalBaggage {
Baggage& Get(); // Get the current thread's baggage
Baggage Take(); // Get the current thread's baggage, and clear the thread-local storage
Baggage Branch(); // Get a copy of the current thread's baggage
void Delete(); // Delete the current thread's baggage
void Set(Baggage new_baggage);
void Join(Baggage &otherBaggage);
}
#endif
\ No newline at end of file
#include "atomlayer.h"
#include "baggage.h"
#include <iostream>
#include <cstdint>
......
#ifndef _BAGGAGE_PROTOCOL_H_
#define _BAGGAGE_PROTOCOL_H_
#include "atomlayer.h"
#include "baggage.h"
#include "lexvarint.h"
#define ATOM_TYPE_MASK 0x80
......
#include <iostream>
#include <vector>
#include "atomlayer.h"
#include "pubsub.h"
#include <sstream>
#include "baggage.h"
#include "pubsub.h"
#include "xtrace.h"
#include "xtrace_baggage.h"
#include "lexvarint.h"
#include "baggageprotocol.h"
#include "thread_local_baggage.h"
#include "xtrace.h"
void test_vector(std::vector<int> testv) {
testv[0] = 5;
......
#include "thread_local_baggage.h"
#include "xtrace.h"
#include "baggage.h"
thread_local Baggage current_threads_baggage;
......
......@@ -7,7 +7,8 @@
#include <chrono>
#include <time.h>
#include "thread_local_baggage.h"
#include "baggage.h"
#include "xtrace.h"
#include "xtrace.pb.h"
#include "xtrace_baggage.h"
......
......@@ -2,7 +2,7 @@
#define _XTRACE_BAGGAGE_H_
#include "thread_local_baggage.h"
#include "baggage.h"
namespace XTraceBaggage {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment