/* ** The public interface to sqlite3Realloc. Make sure that the memory subsystem is initialized prior to invoking systemRealloc. */ void *system_realloc(void *pOld, int n) { #ifndef SYSTEM_OMIT_AUTOINIT if (system_initialize()) return 0; #endif return systemRealloc(pOld, n); }
/* ** This version of the memory allocation is for use by the application. First make sure the memory subsystem is initialized, then do the ** allocation. */ void *system_malloc(int n) { #ifndef SYSTEM_OMIT_AUTOINIT if (system_initialize()) return 0; #endif return systemMalloc(n); }
void main(void) { system_initialize(); for(;;) { system_main(); } }
void main( void ) { system_initialize(); // initialize your own I/O and peripherals for (;;) { // TODO test timing main loop system_tasks(); // TODO what if USB gets detached in the meantime? monitor state? // scan your inputs, update outputs } }
/* ** This routine is the same as the parse_complete() routine described above, except that the parameter is required to be UTF-16 encoded, not UTF-8. */ int parse_complete16(const void *zSql) { system_value *pVal; char const *zSql8; int rc = SYSTEM_NOMEM; #ifndef SYSTEM_OMIT_AUTOINIT rc = system_initialize(); if (rc) return rc; #endif pVal = systemValueNew(0); systemValueSetStr(pVal, -1, zSql, SYSTEM_UTF16NATIVE, SYSTEM_STATIC); zSql8 = systemValueText(pVal, SYSTEM_UTF8); if (zSql8) rc = parse_complete(zSql8); else rc = SYSTEM_NOMEM; systemValueFree(pVal); return systemApiExit(0, rc); }
/* ** Set the soft heap-size limit for the library. Passing a zero or negative value indicates no limit. */ i64 system_soft_heap_limit64(i64 n) { i64 priorLimit; i64 excess; #ifndef SYSTEM_OMIT_AUTOINIT system_initialize(); #endif system_mutex_enter(mem0.mutex); priorLimit = mem0.alarmThreshold; system_mutex_leave(mem0.mutex); if (n < 0) return priorLimit; if (n > 0) systemMemoryAlarm(softHeapLimitEnforcer, 0, n); else systemMemoryAlarm(0, 0, 0); excess = system_memory_used() - n; if (excess > 0) system_release_memory((int)(excess & 0x7fffffff)); return priorLimit; }
event_manager* mgr_init(node_id_t node_id, const char* config_path, const char* log_path){ event_manager* ev_mgr = (event_manager*)malloc(sizeof(event_manager)); if(NULL==ev_mgr){ err_log("EVENT MANAGER : Cannot Malloc Memory For The ev_mgr.\n"); goto mgr_exit_error; } memset(ev_mgr, 0, sizeof(event_manager)); ev_mgr->node_id = node_id; if(mgr_read_config(ev_mgr,config_path)){ err_log("EVENT MANAGER : Configuration File Reading Error.\n"); goto mgr_exit_error; } int build_log_ret = 0; if(log_path==NULL){ log_path = "."; }else{ if((build_log_ret=mkdir(log_path,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))!=0){ if(errno!=EEXIST){ err_log("EVENT MANAGER : Log Directory Creation Failed,No Log Will Be Recorded.\n"); }else{ build_log_ret = 0; } } } if(!build_log_ret){ char* sys_log_path = (char*)malloc(sizeof(char)*strlen(log_path)+50); memset(sys_log_path,0,sizeof(char)*strlen(log_path)+50); if(NULL!=sys_log_path){ sprintf(sys_log_path,"%s/node-%u-mgr-sys.log",log_path,ev_mgr->node_id); ev_mgr->sys_log_file = fopen(sys_log_path,"w"); free(sys_log_path); } if(NULL==ev_mgr->sys_log_file && (ev_mgr->sys_log || ev_mgr->stat_log)){ err_log("EVENT MANAGER : System Log File Cannot Be Created.\n"); } char* req_log_path = (char*)malloc(sizeof(char)*strlen(log_path)+50); memset(req_log_path,0,sizeof(char)*strlen(log_path)+50); if(NULL!=req_log_path){ sprintf(req_log_path,"%s/node-%u-mgr-req.log",log_path,ev_mgr->node_id); ev_mgr->req_log_file = fopen(req_log_path,"w"); free(req_log_path); } if(NULL==ev_mgr->req_log_file && ev_mgr->req_log){ err_log("EVENT MANAGER : Request Log File Cannot Be Created.\n"); } } ev_mgr->db_ptr = initialize_db(ev_mgr->db_name,0); if(ev_mgr->db_ptr==NULL){ err_log("EVENT MANAGER : Cannot Set Up The Database.\n"); goto mgr_exit_error; } ev_mgr->leader_tcp_map = NULL; ev_mgr->replica_tcp_map = NULL; ev_mgr->leader_udp_map = NULL; ev_mgr->con_node = system_initialize(&ev_mgr->node_id,config_path,log_path,update_state,check_point_condtion,get_mapping_fd,ev_mgr->db_ptr,ev_mgr); if(NULL==ev_mgr->con_node){ err_log("EVENT MANAGER : Cannot Initialize Consensus Component.\n"); goto mgr_exit_error; } mgr_on_process_init(ev_mgr); return ev_mgr; mgr_exit_error: if(NULL!=ev_mgr){ if(NULL!=ev_mgr->con_node){ } free(ev_mgr); } return NULL; }