Added CPU, mutex, process, thread, timer

This commit is contained in:
Hamish Milne 2019-08-12 17:01:33 +01:00 committed by zhupengfei
parent 06891d9454
commit f557d26b40
20 changed files with 299 additions and 41 deletions

View file

@ -91,6 +91,7 @@ add_library(common STATIC
scm_rev.h
scope_exit.h
serialization/atomic.h
serialization/boost_flat_set.h
serialization/boost_vector.hpp
string_util.cpp
string_util.h

View file

@ -0,0 +1,37 @@
#pragma once
#include "common/common_types.h"
#include <boost/container/flat_set.hpp>
#include <boost/serialization/split_free.hpp>
namespace boost::serialization {
template <class Archive, class T>
void save(Archive& ar, const boost::container::flat_set<T>& set, const unsigned int file_version)
{
ar << static_cast<u64>(set.size());
for (auto &v : set) {
ar << v;
}
}
template <class Archive, class T>
void load(Archive& ar, boost::container::flat_set<T>& set, const unsigned int file_version)
{
u64 count{};
ar >> count;
set.clear();
for (auto i = 0; i < count; i++) {
T value{};
ar >> value;
set.insert(value);
}
}
template <class Archive, class T>
void serialize(Archive& ar, boost::container::flat_set<T>& set, const unsigned int file_version)
{
boost::serialization::split_free(ar, set, file_version);
}
}

View file

@ -6,6 +6,9 @@
#include <array>
#include <deque>
#include <boost/serialization/deque.hpp>
#include <boost/serialization/split_member.hpp>
#include "common/common_types.h"
namespace Common {
@ -156,6 +159,34 @@ private:
Queue* first;
// The priority level queues of thread ids.
std::array<Queue, NUM_QUEUES> queues;
friend class boost::serialization::access;
template <class Archive>
void save(Archive& ar, const unsigned int file_version) const
{
s32 idx = first == UnlinkedTag() ? -1 : static_cast<s32>(first - &queues[0]);
ar << idx;
for (auto i = 0; i < NUM_QUEUES; i++) {
s32 idx1 = first == UnlinkedTag() ? -1 : static_cast<s32>(queues[i].next_nonempty - &queues[0]);
ar << idx1;
ar << queues[i].data;
}
}
template <class Archive>
void load(Archive& ar, const unsigned int file_version)
{
s32 idx;
ar >> idx;
first = idx < 0 ? UnlinkedTag() : &queues[idx];
for (auto i = 0; i < NUM_QUEUES; i++) {
ar >> idx;
queues[i].next_nonempty = idx < 0 ? UnlinkedTag() : &queues[idx];
ar >> queues[i].data;
}
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
} // namespace Common