-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.cpp
More file actions
49 lines (38 loc) · 1.28 KB
/
submit.cpp
File metadata and controls
49 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <chrono>
#include <cmath>
#include <iostream>
#include "Configuration.h"
#include "Help.h"
#include "Semaphore.h"
#include "SharedMemory.h"
extern "C" void submit(char* reply, const char* source) {
auto* code = new SharedMemory(NAME_MEMORY_CODE, SIZE_MEMORY_CODE);
auto* submit = new Semaphore(NAME_SEMAPHORE_SUBMIT);
auto* compile = new Semaphore(NAME_SEMAPHORE_COMPILE);
using std::chrono::duration;
using std::chrono::high_resolution_clock;
using std::chrono::time_point;
time_point<high_resolution_clock> then = high_resolution_clock::now();
// TRACE("source: %s\n", source);
submit->wait();
snprintf(static_cast<char*>(code->memory()), SIZE_MEMORY_CODE - 1, "%s",
source);
compile->post();
compile->wait();
snprintf(reply, 100, "%s", static_cast<char*>(code->memory()));
submit->post();
// TRACE("reply: %s\n", reply);
duration<double> time = high_resolution_clock::now() - then;
snprintf(reply, 100, "%lf", time.count());
delete submit;
delete compile;
delete code;
}
//
// There was benchmarking code here once. It tested the semaphores
// only from submit to clavm to tcc and back. It showed something
// like this:
//
// 1000000 round trip. 8s ellapsed. mean: 0.000009s
// 1000000 individual. mean: 0.000009s stddev: 0.000002
//