mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 15:45:08 +00:00
more wip
This commit is contained in:
parent
05af433b5a
commit
1f4f720136
@ -71,7 +71,7 @@ bool HasOption(const std::unordered_map<std::string, std::string>& options, cons
|
||||
return options.find(option) != options.end();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main5555(int argc, char** argv) {
|
||||
std::unordered_map<std::string, std::string> options = ParseOptions(argc, argv);
|
||||
|
||||
if (argc == 1 || options.find("--help") != options.end()) {
|
||||
|
@ -88,6 +88,10 @@ struct Location {
|
||||
return FileId(raw_file_id);
|
||||
}
|
||||
|
||||
explicit Location(const char* encoded) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
std::string ToString() {
|
||||
// Output looks like this:
|
||||
//
|
||||
|
15
query.h
15
query.h
@ -157,7 +157,20 @@ struct SymbolIdx {
|
||||
};
|
||||
|
||||
|
||||
|
||||
// TODO: We need to control Usr, std::vector allocation to make sure it happens on shmem. That or we
|
||||
// make IndexUpdate a POD type.
|
||||
// TODO: Instead of all of that work above, we pipe the IndexUpdate across processes as JSON.
|
||||
// We need to verify we need multiple processes first. Maybe libclang can run in a single process...
|
||||
// TODO: Compute IndexUpdates in main process, off the blocking thread. Use separate process for running
|
||||
// libclang. Solves memory worries.
|
||||
namespace foo2 {
|
||||
using Usr = size_t;
|
||||
struct UsrTable {
|
||||
size_t allocated;
|
||||
size_t used;
|
||||
const char* usrs[];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
struct IndexUpdate {
|
||||
|
@ -170,3 +170,37 @@ void Serialize(Writer& writer, IndexedFile* file) {
|
||||
writer.EndObject();
|
||||
#undef WRITE
|
||||
}
|
||||
|
||||
void Deserialize(std::string& output, rapidjson::GenericValue<rapidjson::UTF8<>>& value) {
|
||||
output = value.GetString();
|
||||
}
|
||||
|
||||
void Deserialize(optional<Location>& output, rapidjson::GenericValue<rapidjson::UTF8<>>& value) {
|
||||
if (!value.IsNull())
|
||||
output = Location(value.GetString()); // TODO: Location parsing not implemented in Location type.
|
||||
}
|
||||
|
||||
void Deserialize(Reader& reader, IndexedFile* file) {
|
||||
auto& types = reader["types"].GetArray();
|
||||
for (auto& type : types) {
|
||||
TypeId id = TypeId(type["id"].GetInt64());
|
||||
std::string usr = type["usr"].GetString();
|
||||
|
||||
IndexedTypeDef def(id, usr);
|
||||
Deserialize(def.def.short_name, type["short_name"]);
|
||||
Deserialize(def.def.qualified_name, type["qualified_name"]);
|
||||
Deserialize(def.def.definition, type["definition"]); // TODO: What happens if entry is not present?
|
||||
//SERIALIZE("short_name", def.short_name);
|
||||
//SERIALIZE("qualified_name", def.qualified_name);
|
||||
//SERIALIZE("definition", def.definition);
|
||||
//SERIALIZE("alias_of", def.alias_of);
|
||||
//SERIALIZE("parents", def.parents);
|
||||
//SERIALIZE("derived", derived);
|
||||
//SERIALIZE("types", def.types);
|
||||
//SERIALIZE("funcs", def.funcs);
|
||||
//SERIALIZE("vars", def.vars);
|
||||
//SERIALIZE("uses", uses);
|
||||
|
||||
file->types.push_back(def);
|
||||
}
|
||||
}
|
@ -6,3 +6,4 @@ using Writer = rapidjson::PrettyWriter<rapidjson::StringBuffer>;
|
||||
using Reader = rapidjson::Document;
|
||||
|
||||
void Serialize(Writer& writer, IndexedFile* file);
|
||||
void Deserialize(Reader& reader, IndexedFile* file);
|
89
shared_memory_win.cpp
Normal file
89
shared_memory_win.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
const int shmem_size = 16; // 16byte
|
||||
|
||||
void reader() {
|
||||
HANDLE shmem = INVALID_HANDLE_VALUE;
|
||||
HANDLE mutex = INVALID_HANDLE_VALUE;
|
||||
|
||||
mutex = ::CreateMutex(NULL, FALSE, "mutex_sample_name");
|
||||
|
||||
shmem = ::CreateFileMapping(
|
||||
INVALID_HANDLE_VALUE,
|
||||
NULL,
|
||||
PAGE_READWRITE,
|
||||
0,
|
||||
shmem_size,
|
||||
"shared_memory_name"
|
||||
);
|
||||
|
||||
char *buf = (char*)MapViewOfFile(shmem, FILE_MAP_ALL_ACCESS, 0, 0, shmem_size);
|
||||
|
||||
|
||||
for (unsigned int c = 0; c < 60; ++c) {
|
||||
// mutex lock
|
||||
WaitForSingleObject(mutex, INFINITE);
|
||||
|
||||
int value = buf[0];
|
||||
std::cout << "read shared memory...c=" << value << std::endl;
|
||||
|
||||
// mutex unlock
|
||||
::ReleaseMutex(mutex);
|
||||
|
||||
::Sleep(1000);
|
||||
}
|
||||
|
||||
// release
|
||||
::UnmapViewOfFile(buf);
|
||||
::CloseHandle(shmem);
|
||||
::ReleaseMutex(mutex);
|
||||
}
|
||||
|
||||
void writer() {
|
||||
HANDLE shmem = INVALID_HANDLE_VALUE;
|
||||
HANDLE mutex = INVALID_HANDLE_VALUE;
|
||||
|
||||
mutex = ::CreateMutex(NULL, FALSE, "mutex_sample_name");
|
||||
|
||||
shmem = ::CreateFileMapping(
|
||||
INVALID_HANDLE_VALUE,
|
||||
NULL,
|
||||
PAGE_READWRITE,
|
||||
0,
|
||||
shmem_size,
|
||||
"shared_memory_name"
|
||||
);
|
||||
|
||||
char *buf = (char*)::MapViewOfFile(shmem, FILE_MAP_ALL_ACCESS, 0, 0, shmem_size);
|
||||
|
||||
for (unsigned int c = 0; c < 60; ++c) {
|
||||
// mutex lock
|
||||
WaitForSingleObject(mutex, INFINITE);
|
||||
|
||||
// write shared memory
|
||||
memset(buf, c, shmem_size);
|
||||
|
||||
std::cout << "write shared memory...c=" << c << std::endl;
|
||||
|
||||
// mutex unlock
|
||||
::ReleaseMutex(mutex);
|
||||
|
||||
::Sleep(1000);
|
||||
}
|
||||
|
||||
// release
|
||||
::UnmapViewOfFile(buf);
|
||||
::CloseHandle(shmem);
|
||||
::ReleaseMutex(mutex);
|
||||
}
|
||||
|
||||
int main52525252(int argc, char** argv) {
|
||||
if (argc == 2)
|
||||
writer();
|
||||
else
|
||||
reader();
|
||||
|
||||
return 0;
|
||||
}
|
19
task.cc
19
task.cc
@ -5,13 +5,16 @@
|
||||
|
||||
#include "indexer.h"
|
||||
#include "query.h"
|
||||
|
||||
#include "optional.h"
|
||||
#include "third_party/tiny-process-library/process.hpp"
|
||||
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
// A threadsafe-queue. http://stackoverflow.com/a/16075550
|
||||
template <class T>
|
||||
class SafeQueue {
|
||||
@ -36,6 +39,18 @@ public:
|
||||
return val;
|
||||
}
|
||||
|
||||
// Get the "front"-element.
|
||||
// Returns empty if the queue is empty.
|
||||
optional<T> try_dequeue() {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
if (queue_.empty())
|
||||
return nullopt;
|
||||
|
||||
T val = queue_.front();
|
||||
queue_.pop();
|
||||
return val;
|
||||
}
|
||||
|
||||
private:
|
||||
std::queue<T> queue_;
|
||||
mutable std::mutex mutex_;
|
||||
@ -116,7 +131,7 @@ void Pump(TaskManager* tm) {
|
||||
//tm->threads[0].
|
||||
}
|
||||
|
||||
int main4(int argc, char** argv) {
|
||||
int main(int argc, char** argv) {
|
||||
TaskManager tm(5);
|
||||
|
||||
// TODO: looks like we will have to write shared memory support.
|
||||
|
Loading…
Reference in New Issue
Block a user