From c4fe370b1c4a8b9c2aeffc2a027b67d6f64b4ba9 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Tue, 22 Sep 2015 19:40:52 +1000 Subject: [PATCH] Test threaded version --- test/gmttest.cpp | 85 ++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/test/gmttest.cpp b/test/gmttest.cpp index 691bdda..a9a9f78 100644 --- a/test/gmttest.cpp +++ b/test/gmttest.cpp @@ -9,15 +9,59 @@ int print_func(FILE* fd, const char* str) std::cout<<"PRINT: "<(x); + char c='\n'; + + unshare(CLONE_FILES); + dup2(p->fd,1); + write(1,&c,1); // Use this instead of mutex + p->ret=GMT_Call_Module(p->api,p->module,GMT_MODULE_OPT,p->opts); + close(1); + close(p->fd); + return 0; +} + +int callgmtmodule(void *api, const char *module, void *opts, std::string& res) { int pipefd[2]; - int savefd; + ssize_t br; + char buffer[4096]; + pthread_t wthr; + struct gmtworkthreadpars p; + + pipe(pipefd); + p.api=api; + p.module=module; + p.opts=opts; + p.fd=pipefd[1]; + pthread_create(&wthr,0,&gmtworkthread,&p); + res.erase(); + read(pipefd[0],buffer,1); + close(pipefd[1]); + do + { + br=read(pipefd[0],buffer,4096); + std::cout<