Uhhh
This commit is contained in:
parent
aa2f74c685
commit
533b6a167f
12
main.c
12
main.c
|
@ -18,7 +18,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ALLOCATE_EVERYTHING
|
#ifndef ALLOCATE_EVERYTHING
|
||||||
#define ALLOCATE_EVERYTHING 1
|
#define ALLOCATE_EVERYTHING 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +47,9 @@ void block_add(OddBlock *blk);
|
||||||
int check_is_odd(uint64_t value);
|
int check_is_odd(uint64_t value);
|
||||||
inline uint64_t get_mem_usage(void);
|
inline uint64_t get_mem_usage(void);
|
||||||
inline double get_time(void);
|
inline double get_time(void);
|
||||||
|
#if ALLOCATE_EVERYTHING
|
||||||
void *allocation_thread(void*);
|
void *allocation_thread(void*);
|
||||||
|
#endif
|
||||||
|
|
||||||
OddBlock *blocks_head = NULL;
|
OddBlock *blocks_head = NULL;
|
||||||
size_t n_blocks = 0;
|
size_t n_blocks = 0;
|
||||||
|
@ -67,15 +69,19 @@ int main(void) {
|
||||||
mg_mgr_init(&manager);
|
mg_mgr_init(&manager);
|
||||||
mg_http_listen(&manager, "0.0.0.0:8080", api_handler, NULL);
|
mg_http_listen(&manager, "0.0.0.0:8080", api_handler, NULL);
|
||||||
|
|
||||||
|
#if ALLOCATE_EVERYTHING
|
||||||
int n_threads = 4;
|
int n_threads = 4;
|
||||||
pthread_t *threads = calloc(n_threads, sizeof(pthread_t));
|
pthread_t *threads = calloc(n_threads, sizeof(pthread_t));
|
||||||
for (int i = 0; i < n_threads; i++)
|
for (int i = 0; i < n_threads; i++)
|
||||||
pthread_create(&threads[i], NULL, allocation_thread, NULL);
|
pthread_create(&threads[i], NULL, allocation_thread, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (;;) mg_mgr_poll(&manager, 1000);
|
for (;;) mg_mgr_poll(&manager, 1000);
|
||||||
|
|
||||||
|
#if ALLOCATE_EVERYTHING
|
||||||
for (int i = 0; i < n_threads; i++)
|
for (int i = 0; i < n_threads; i++)
|
||||||
pthread_join(threads[i], NULL);
|
pthread_join(threads[i], NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
mg_mgr_free(&manager);
|
mg_mgr_free(&manager);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -228,7 +234,7 @@ void api_handler(struct mg_connection *c, int ev, void *evd, void *fnd) {
|
||||||
mg_http_reply(c, 200, "", "%zd", blocks_head->start + 0x7FFFFFF);
|
mg_http_reply(c, 200, "", "%zd", blocks_head->start + 0x7FFFFFF);
|
||||||
n_requests++;
|
n_requests++;
|
||||||
} else {
|
} else {
|
||||||
mg_http_reply(c, 500, "", "Internal Server Error");
|
mg_http_reply(c, 500, "Content-Type: text/plain; charset=utf-8\r\n", "Internal Server Error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,6 +255,7 @@ double get_time(void) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ALLOCATE_EVERYTHING
|
||||||
void *allocation_thread(void*_) {
|
void *allocation_thread(void*_) {
|
||||||
while (true) {
|
while (true) {
|
||||||
next_block_number += 0x8000000;
|
next_block_number += 0x8000000;
|
||||||
|
@ -257,3 +264,4 @@ void *allocation_thread(void*_) {
|
||||||
block_add(blk);
|
block_add(blk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue