Fix bugs on stored procedures and threaded GC

This commit is contained in:
2022-12-02 21:09:59 +08:00
parent 957e53eb70
commit 853b129343
10 changed files with 72 additions and 35 deletions
+1
View File
@@ -1,3 +1,4 @@
#pragma once
#ifndef __AQ_USE_THREADEDGC__
#include <atomic>
class GC {
+2 -2
View File
@@ -456,14 +456,14 @@ void GC::reg(void* v, uint32_t sz, void(*f)(void*)) { //~ 40ns expected v. free
++alive_cnt;
current_size += sz;
auto _slot = (slot_pos += 1);
_q[_slot] = {v, f};
_q[_slot-1] = {v, f};
--alive_cnt;
running = true;
}
#endif
GC* GC::gc_handle = nullptr;
inline GC* GC::gc_handle = nullptr;
#include "dragonbox/dragonbox_to_chars.hpp"
-1
View File
@@ -4,7 +4,6 @@
#ifdef __INTELLISENSE__
#define __AQUERY_ITC_USE_SEMPH__
#define THREADING
#define __AQ_THREADED_GC__
#endif
#include <unordered_map>
+33 -15
View File
@@ -285,10 +285,10 @@ int dll_main(int argc, char** argv, Context* cxt){
aq_timer timer;
Config *cfg = reinterpret_cast<Config *>(argv[0]);
std::unordered_map<std::string, void*> user_module_map;
std::string pwd = std::filesystem::current_path().c_str();
auto sep = std::filesystem::path::preferred_separator;
std::string pwd = (char*)(std::filesystem::current_path().string().c_str());
char sep = std::filesystem::path::preferred_separator;
pwd += sep;
std::string procedure_root = pwd + "procedures" + sep;
std::string procedure_root = (pwd + "procedures") + sep;
std::string procedure_name = "";
StoredProcedure current_procedure;
vector_type<char *> recorded_queries;
@@ -296,6 +296,18 @@ int dll_main(int argc, char** argv, Context* cxt){
bool procedure_recording = false,
procedure_replaying = false;
uint32_t procedure_module_cursor = 0;
try {
if (!std::filesystem::is_directory(procedure_root)) {
if (std::filesystem::exists(procedure_root))
std::filesystem::remove_all(procedure_root);
}
if (!std::filesystem::exists(procedure_root)) {
std::filesystem::create_directory(procedure_root);
}
}
catch (std::filesystem::filesystem_error& e) {
printf("Failed to create directory %s: %s\n", procedure_root.c_str(), e.what());
}
if (cxt->module_function_maps == nullptr)
cxt->module_function_maps = new std::unordered_map<std::string, void*>();
@@ -351,6 +363,12 @@ start:
recorded_queries.emplace_back(copy_lpstr("N"));
}
handle = dlopen(proc_name, RTLD_NOW);
#ifndef __AQ_USE_THREADEDGC__
{
typedef void (*aq_gc_init_t) (Context*);
((aq_gc_init_t)dlsym(handle, "__AQ_Init_GC__"))(cxt);
}
#endif
if (procedure_recording) {
recorded_libraries.emplace_back(handle);
}
@@ -380,6 +398,7 @@ start:
recorded_queries.emplace_back(copy_lpstr(n_recvd[i]));
}
code_snippet c = reinterpret_cast<code_snippet>(dlsym(handle, n_recvd[i]+1));
printf("%p", dlsym(handle, n_recvd[i] + 1));
timer.reset();
c(cxt);
cfg->stats.postproc_time += timer.elapsed();
@@ -543,6 +562,7 @@ start:
n_recv = current_procedure.cnt;
n_recvd = current_procedure.queries;
load_modules(current_procedure);
procedure_replaying = true;
goto start; // yes, I know, refactor later!!
}
}
@@ -568,12 +588,7 @@ start:
break;
}
}
if(handle &&
!procedure_replaying && !procedure_recording) {
printf("Destroy %p\n", handle);
dlclose(handle);
handle = nullptr;
}
printf("%lld, %lld", cfg->stats.monet_time, cfg->stats.postproc_time);
cxt->end_session();
n_recv = 0;
@@ -591,7 +606,13 @@ start:
code_snippet c = reinterpret_cast<code_snippet>(dlsym(handle, "dllmain"));
c(cxt);
}
if (handle) dlclose(handle);
if (handle &&
!procedure_replaying && !procedure_recording) {
printf("Destroy %p\n", handle);
dlclose(handle);
handle = nullptr;
}
procedure_replaying = false;
cfg->new_query = 0;
}
//puts(cfg->running? "true": "false");
@@ -624,7 +645,7 @@ int launcher(int argc, char** argv){
str = std::string("cd ") + pwd + std::string("&& python3 ./prompt.py ") + str;
return system(str.c_str());
}
#if !( defined(_MSC_VER) && defined(_DEBUG) )
#if true || !( defined(_MSC_VER) && defined(_DEBUG) )
extern "C" int __DLLEXPORT__ main(int argc, char** argv) {
#ifdef __AQ_BUILD_LAUNCHER__
return launcher(argc, argv);
@@ -639,9 +660,6 @@ extern "C" int __DLLEXPORT__ main(int argc, char** argv) {
cxt->thread_pool = tp;
#endif
#ifdef __AQ_THREADED_GC__
cxt->gc_thread = new std::thread(gc_thread, cxt);
#endif
const char* shmname;
if (argc < 0)
return dll_main(argc, argv, cxt);
@@ -678,4 +696,4 @@ extern "C" int __DLLEXPORT__ main(int argc, char** argv) {
return 0;
}
#endif // MSCDBG
#endif // MSCDBG
+2 -2
View File
@@ -15,7 +15,7 @@
#include <iostream>
#include "hasher.h"
#include "types.h"
#include "gc.h"
#pragma pack(push, 1)
template<class T>
struct vector_base {};
@@ -325,7 +325,7 @@ public:
inline vector_type<_Ty> subvec_deep(uint32_t start = 0) const { return subvec_deep(start, size); }
vector_type<_Ty> getRef() { return vector_type<_Ty>(container, size); }
~vector_type() {
if (capacity > 0) free(container);
if (capacity > 0) GC::gc_handle->reg(container, sizeof(_Ty) * capacity);//free(container);
container = 0; size = capacity = 0;
}
#define Compare(_op) \