refactor: Shift sandbox_request to new file

main
Sean McBride 5 years ago
parent ea888ddbb3
commit 1d724f04e8

@ -77,19 +77,6 @@ struct sandbox {
char request_response_data[1]; // of rr_data_sz, following sandbox mem.. char request_response_data[1]; // of rr_data_sz, following sandbox mem..
} PAGE_ALIGNED; } PAGE_ALIGNED;
struct sandbox_request {
struct module * module;
char * arguments;
int socket_descriptor;
struct sockaddr *socket_address;
u64 start_time; // cycles
};
typedef struct sandbox_request sandbox_request_t;
DEQUE_PROTOTYPE(sandbox, sandbox_request_t *);
static inline int add_sandbox_request_to_global_dequeue(sandbox_request_t *sandbox_request);
// a runtime resource, malloc on this! // a runtime resource, malloc on this!
struct sandbox *allocate_sandbox(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, u64 start_time); struct sandbox *allocate_sandbox(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, u64 start_time);
// should free stack and heap resources.. also any I/O handles. // should free stack and heap resources.. also any I/O handles.
@ -101,30 +88,6 @@ extern __thread arch_context_t *next_context;
typedef struct sandbox sandbox_t; typedef struct sandbox sandbox_t;
/**
* Allocates a new Sandbox Request and places it on the Global Deque
* @param module the module we want to request
* @param arguments the arguments that we'll pass to the serverless function
* @param socket_descriptor
* @param socket_address
* @param start_time the timestamp of when we receives the request from the network (in cycles)
* @return the new sandbox request
**/
static inline sandbox_request_t *
allocate_sandbox_request(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, u64 start_time)
{
sandbox_request_t *sandbox_request = malloc(sizeof(sandbox_request_t));
assert(sandbox_request);
sandbox_request->module = module;
sandbox_request->arguments = arguments;
sandbox_request->socket_descriptor = socket_descriptor;
sandbox_request->socket_address = (struct sockaddr *)socket_address;
sandbox_request->start_time = start_time;
debuglog("[%p: %s]\n", sandbox_request, sandbox_request->module->name);
add_sandbox_request_to_global_dequeue(sandbox_request);
return sandbox_request;
}
/** /**
* Getter for the current sandbox executing on this thread * Getter for the current sandbox executing on this thread
@ -224,68 +187,6 @@ void sandbox_response(void);
// should have been called with stack allocated and get_current_sandbox() set! // should have been called with stack allocated and get_current_sandbox() set!
void sandbox_main(void); void sandbox_main(void);
void exit_current_sandbox(void); void exit_current_sandbox(void);
extern struct deque_sandbox *global_deque;
extern pthread_mutex_t global_deque_mutex;
/**
* Pushes a sandbox request to the global deque
* @param sandbox_request
**/
static inline int
add_sandbox_request_to_global_dequeue(sandbox_request_t *sandbox_request)
{
int return_code;
#if NCORES == 1
pthread_mutex_lock(&global_deque_mutex);
#endif
return_code = deque_push_sandbox(global_deque, &sandbox_request);
#if NCORES == 1
pthread_mutex_unlock(&global_deque_mutex);
#endif
return return_code;
}
/**
* Pops a sandbox request from the global deque
* @param sandbox_request the pointer which we want to set to the sandbox request
**/
static inline int
pop_sandbox_request_from_global_dequeue(sandbox_request_t **sandbox_request)
{
int return_code;
#if NCORES == 1
pthread_mutex_lock(&global_deque_mutex);
#endif
return_code = deque_pop_sandbox(global_deque, sandbox_request);
#if NCORES == 1
pthread_mutex_unlock(&global_deque_mutex);
#endif
return return_code;
}
/**
* TODO: What does this do?
* @returns A Sandbox Request or NULL
**/
static inline sandbox_request_t *
steal_sandbox_request_from_global_dequeue(void)
{
sandbox_request_t *sandbox_request = NULL;
#if NCORES == 1
pop_sandbox_request_from_global_dequeue(&sandbox_request);
#else
// TODO: check! is there a sandboxing thread on same core as udp-server thread?
int r = deque_steal_sandbox(global_deque, &sandbox_request);
if (r) sandbox_request = NULL;
#endif
return sandbox_request;
}
/** /**
* Initializes and returns an IO handle on the current sandbox ready for use * Initializes and returns an IO handle on the current sandbox ready for use

@ -0,0 +1,108 @@
#ifndef SFRT_SANDBOX_REQUEST_H
#define SFRT_SANDBOX_REQUEST_H
#include "types.h"
#include "deque.h"
extern struct deque_sandbox *global_deque;
extern pthread_mutex_t global_deque_mutex;
struct sandbox_request {
struct module * module;
char * arguments;
int socket_descriptor;
struct sockaddr *socket_address;
u64 start_time; // cycles
};
typedef struct sandbox_request sandbox_request_t;
DEQUE_PROTOTYPE(sandbox, sandbox_request_t *);
static inline int add_sandbox_request_to_global_dequeue(sandbox_request_t *sandbox_request);
/**
* Allocates a new Sandbox Request and places it on the Global Deque
* @param module the module we want to request
* @param arguments the arguments that we'll pass to the serverless function
* @param socket_descriptor
* @param socket_address
* @param start_time the timestamp of when we receives the request from the network (in cycles)
* @return the new sandbox request
**/
static inline sandbox_request_t *
allocate_sandbox_request(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, u64 start_time)
{
sandbox_request_t *sandbox_request = (sandbox_request_t *)malloc(sizeof(sandbox_request_t));
assert(sandbox_request);
sandbox_request->module = module;
sandbox_request->arguments = arguments;
sandbox_request->socket_descriptor = socket_descriptor;
sandbox_request->socket_address = (struct sockaddr *)socket_address;
sandbox_request->start_time = start_time;
debuglog("[%p: %s]\n", sandbox_request, sandbox_request->module->name);
add_sandbox_request_to_global_dequeue(sandbox_request);
return sandbox_request;
}
/**
* Pushes a sandbox request to the global deque
* @param sandbox_request
**/
static inline int
add_sandbox_request_to_global_dequeue(sandbox_request_t *sandbox_request)
{
int return_code;
#if NCORES == 1
pthread_mutex_lock(&global_deque_mutex);
#endif
return_code = deque_push_sandbox(global_deque, &sandbox_request);
#if NCORES == 1
pthread_mutex_unlock(&global_deque_mutex);
#endif
return return_code;
}
/**
* Pops a sandbox request from the global deque
* @param sandbox_request the pointer which we want to set to the sandbox request
**/
static inline int
pop_sandbox_request_from_global_dequeue(sandbox_request_t **sandbox_request)
{
int return_code;
#if NCORES == 1
pthread_mutex_lock(&global_deque_mutex);
#endif
return_code = deque_pop_sandbox(global_deque, sandbox_request);
#if NCORES == 1
pthread_mutex_unlock(&global_deque_mutex);
#endif
return return_code;
}
/**
* TODO: What does this do?
* @returns A Sandbox Request or NULL
**/
static inline sandbox_request_t *
steal_sandbox_request_from_global_dequeue(void)
{
sandbox_request_t *sandbox_request = NULL;
#if NCORES == 1
pop_sandbox_request_from_global_dequeue(&sandbox_request);
#else
// TODO: check! is there a sandboxing thread on same core as udp-server thread?
int r = deque_steal_sandbox(global_deque, &sandbox_request);
if (r) sandbox_request = NULL;
#endif
return sandbox_request;
}
#endif /* SFRT_SANDBOX_REQUEST_H */

@ -11,6 +11,8 @@
#include <uv.h> #include <uv.h>
#include <http_api.h> #include <http_api.h>
#include "sandbox_request.h"
/*************************** /***************************
* Shared Process State * * Shared Process State *
**************************/ **************************/

Loading…
Cancel
Save