chore: namespace runtime state

main
Sean McBride 5 years ago
parent 81b5d3b00d
commit 7f858d69dd

@ -1,8 +1,10 @@
#ifndef SFRT_CURRENT_SANDBOX_H #ifndef SFRT_CURRENT_SANDBOX_H
#define SFRT_CURRENT_SANDBOX_H #define SFRT_CURRENT_SANDBOX_H
#include <sandbox.h> #include "sandbox.h"
#include <types.h> #include "types.h"
extern http_parser_settings runtime__http_parser_settings;
/** /**
* Getter for the current sandbox executing on this thread * Getter for the current sandbox executing on this thread
@ -65,7 +67,6 @@ current_sandbox__initialize_io_handle_and_set_file_descriptor(int file_descripto
return sandbox__initialize_io_handle_and_set_file_descriptor(sandbox, file_descriptor); return sandbox__initialize_io_handle_and_set_file_descriptor(sandbox, file_descriptor);
} }
extern http_parser_settings global__http_parser_settings;
int sandbox__parse_http_request(struct sandbox *sandbox, size_t l); int sandbox__parse_http_request(struct sandbox *sandbox, size_t l);
/** /**

@ -8,10 +8,10 @@
#include "sandbox.h" #include "sandbox.h"
#include "types.h" #include "types.h"
extern int epoll_file_descriptor; extern int runtime__epoll_file_descriptor;
extern struct deque_sandbox *global_deque; extern struct deque_sandbox *runtime__global_deque;
extern pthread_mutex_t global_deque_mutex; extern pthread_mutex_t runtime__global_deque_mutex;
extern __thread uv_loop_t uvio_handle; extern __thread uv_loop_t runtime__uvio_handle;
void alloc_linear_memory(void); void alloc_linear_memory(void);
void expand_memory(void); void expand_memory(void);
@ -62,7 +62,7 @@ get_memory_string(u32 offset)
static inline uv_loop_t * static inline uv_loop_t *
get_thread_libuv_handle(void) get_thread_libuv_handle(void)
{ {
return &uvio_handle; return &runtime__uvio_handle;
} }
#endif /* SFRT_RUNTIME_H */ #endif /* SFRT_RUNTIME_H */

@ -1,11 +1,11 @@
#ifndef SFRT_SANDBOX_REQUEST_H #ifndef SFRT_SANDBOX_REQUEST_H
#define SFRT_SANDBOX_REQUEST_H #define SFRT_SANDBOX_REQUEST_H
#include "types.h"
#include "deque.h" #include "deque.h"
#include "types.h"
extern struct deque_sandbox *global_deque; extern struct deque_sandbox *runtime__global_deque;
extern pthread_mutex_t global_deque_mutex; extern pthread_mutex_t runtime__global_deque_mutex;
struct sandbox_request { struct sandbox_request {
struct module * module; struct module * module;
@ -28,11 +28,11 @@ sandbox_request__add_to_global_dequeue(sandbox_request_t *sandbox_request)
int return_code; int return_code;
#if NCORES == 1 #if NCORES == 1
pthread_mutex_lock(&global_deque_mutex); pthread_mutex_lock(&runtime__global_deque_mutex);
#endif #endif
return_code = deque_push_sandbox(global_deque, &sandbox_request); return_code = deque_push_sandbox(runtime__global_deque, &sandbox_request);
#if NCORES == 1 #if NCORES == 1
pthread_mutex_unlock(&global_deque_mutex); pthread_mutex_unlock(&runtime__global_deque_mutex);
#endif #endif
return return_code; return return_code;
@ -73,11 +73,11 @@ sandbox_request__pop_from_global_dequeue(sandbox_request_t **sandbox_request)
int return_code; int return_code;
#if NCORES == 1 #if NCORES == 1
pthread_mutex_lock(&global_deque_mutex); pthread_mutex_lock(&runtime__global_deque_mutex);
#endif #endif
return_code = deque_pop_sandbox(global_deque, sandbox_request); return_code = deque_pop_sandbox(runtime__global_deque, sandbox_request);
#if NCORES == 1 #if NCORES == 1
pthread_mutex_unlock(&global_deque_mutex); pthread_mutex_unlock(&runtime__global_deque_mutex);
#endif #endif
return return_code; return return_code;
} }
@ -94,7 +94,7 @@ sandbox_request__steal_from_global_dequeue(void)
#if NCORES == 1 #if NCORES == 1
sandbox_request__pop_from_global_dequeue(&sandbox_request); sandbox_request__pop_from_global_dequeue(&sandbox_request);
#else #else
int r = deque_steal_sandbox(global_deque, &sandbox_request); int r = deque_steal_sandbox(runtime__global_deque, &sandbox_request);
if (r) sandbox_request = NULL; if (r) sandbox_request = NULL;
#endif #endif

@ -50,7 +50,7 @@ module__initialize_as_server(struct module *module)
struct epoll_event accept_evt; struct epoll_event accept_evt;
accept_evt.data.ptr = (void *)module; accept_evt.data.ptr = (void *)module;
accept_evt.events = EPOLLIN; accept_evt.events = EPOLLIN;
if (epoll_ctl(epoll_file_descriptor, EPOLL_CTL_ADD, module->socket_descriptor, &accept_evt) < 0) assert(0); if (epoll_ctl(runtime__epoll_file_descriptor, EPOLL_CTL_ADD, module->socket_descriptor, &accept_evt) < 0) assert(0);
} }
/*************************************** /***************************************

@ -19,10 +19,10 @@
* Shared Process State * * Shared Process State *
**************************/ **************************/
struct deque_sandbox *global_deque; struct deque_sandbox *runtime__global_deque;
pthread_mutex_t global_deque_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t runtime__global_deque_mutex = PTHREAD_MUTEX_INITIALIZER;
int epoll_file_descriptor; int runtime__epoll_file_descriptor;
http_parser_settings global__http_parser_settings; http_parser_settings runtime__http_parser_settings;
/****************************************** /******************************************
* Shared Process / Listener Thread Logic * * Shared Process / Listener Thread Logic *
@ -34,22 +34,22 @@ http_parser_settings global__http_parser_settings;
void void
initialize_runtime(void) initialize_runtime(void)
{ {
epoll_file_descriptor = epoll_create1(0); runtime__epoll_file_descriptor = epoll_create1(0);
assert(epoll_file_descriptor >= 0); assert(runtime__epoll_file_descriptor >= 0);
// Allocate and Initialize the global deque // Allocate and Initialize the global deque
global_deque = (struct deque_sandbox *)malloc(sizeof(struct deque_sandbox)); runtime__global_deque = (struct deque_sandbox *)malloc(sizeof(struct deque_sandbox));
assert(global_deque); assert(runtime__global_deque);
// Note: Below is a Macro // Note: Below is a Macro
deque_init_sandbox(global_deque, SBOX_MAX_REQS); deque_init_sandbox(runtime__global_deque, SBOX_MAX_REQS);
// Mask Signals // Mask Signals
softint__mask(SIGUSR1); softint__mask(SIGUSR1);
softint__mask(SIGALRM); softint__mask(SIGALRM);
// Initialize http_parser_settings global // Initialize http_parser_settings global
http_parser_settings__initialize(&global__http_parser_settings); http_parser_settings__initialize(&runtime__http_parser_settings);
http_parser_settings__register_callbacks(&global__http_parser_settings); http_parser_settings__register_callbacks(&runtime__http_parser_settings);
} }
/******************************** /********************************
@ -63,7 +63,7 @@ initialize_runtime(void)
* @return NULL * @return NULL
* *
* Used Globals: * Used Globals:
* epoll_file_descriptor - the epoll file descriptor * runtime__epoll_file_descriptor - the epoll file descriptor
* *
*/ */
void * void *
@ -73,7 +73,7 @@ listener_thread_main(void *dummy)
int total_requests = 0; int total_requests = 0;
while (true) { while (true) {
int request_count = epoll_wait(epoll_file_descriptor, epoll_events, EPOLL_MAX, -1); int request_count = epoll_wait(runtime__epoll_file_descriptor, epoll_events, EPOLL_MAX, -1);
u64 start_time = util__rdtsc(); u64 start_time = util__rdtsc();
for (int i = 0; i < request_count; i++) { for (int i = 0; i < request_count; i++) {
if (epoll_events[i].events & EPOLLERR) { if (epoll_events[i].events & EPOLLERR) {
@ -151,7 +151,7 @@ __thread arch_context_t *next_context = NULL;
__thread arch_context_t base_context; __thread arch_context_t base_context;
// libuv i/o loop handle per sandboxing thread! // libuv i/o loop handle per sandboxing thread!
__thread uv_loop_t uvio_handle; __thread uv_loop_t runtime__uvio_handle;
// Flag to signify if the thread is currently running callbacks in the libuv event loop // Flag to signify if the thread is currently running callbacks in the libuv event loop
static __thread unsigned int in_callback; static __thread unsigned int in_callback;
@ -419,7 +419,7 @@ worker_thread_main(void *return_code)
softint__unmask(SIGALRM); softint__unmask(SIGALRM);
softint__unmask(SIGUSR1); softint__unmask(SIGUSR1);
#endif #endif
uv_loop_init(&uvio_handle); uv_loop_init(&runtime__uvio_handle);
in_callback = 0; in_callback = 0;
while (true) { while (true) {

@ -47,14 +47,14 @@ current_sandbox__setup_arguments(i32 argument_count)
* @param length The size of the request_response_data that we want to parse * @param length The size of the request_response_data that we want to parse
* @returns 0 * @returns 0
* *
* Globals: global__http_parser_settings * Globals: runtime__http_parser_settings
**/ **/
int int
sandbox__parse_http_request(struct sandbox *sandbox, size_t length) sandbox__parse_http_request(struct sandbox *sandbox, size_t length)
{ {
// Why is our start address sandbox->request_response_data + sandbox->request_response_data_length? // Why is our start address sandbox->request_response_data + sandbox->request_response_data_length?
// it's like a cursor to keep track of what we've read so far // it's like a cursor to keep track of what we've read so far
http_parser_execute(&sandbox->http_parser, &global__http_parser_settings, sandbox->request_response_data + sandbox->request_response_data_length, length); http_parser_execute(&sandbox->http_parser, &runtime__http_parser_settings, sandbox->request_response_data + sandbox->request_response_data_length, length);
return 0; return 0;
} }

Loading…
Cancel
Save