list *listInsertNode(list *list, listNode *old_node, void *value, int after) { listNode *node; if ((node = sys_malloc(sizeof(*node))) == NULL) return NULL; node->value = value; if (after) { node->prev = old_node; node->next = old_node->next; if (list->tail == old_node) { list->tail = node; } } else { node->next = old_node; node->prev = old_node->prev; if (list->head == old_node) { list->head = node; } } if (node->prev != NULL) { node->prev->next = node; } if (node->next != NULL) { node->next->prev = node; } list->len++; return list; }
/** ** sys_mkpath - ensure all directories in path exist ** Algorithm takes the pessimistic view and works top-down to ensure ** each directory in path exists, rather than optimistically creating ** the last element and working backwards. */ int sys_mkpath(const char *path, mode_t mode) { char *pp; char *sp; int status; char *copypath = sys_malloc(strlen(path) + 1); strcpy(copypath,path); status = 0; pp = copypath; while (status == 0 && (sp = strchr(pp, '/')) != 0) { if (sp != pp) { /* Neither root nor double slash in path */ *sp = '\0'; status = sys_mkdir(copypath, mode); *sp = '/'; } pp = sp + 1; } sys_free((void**)©path); assert(status == 0); return status; }
//---------------------------------------------------------------------------- // EXTERNAL FUNCTIONS //---------------------------------------------------------------------------- // Allocate continuous space to context, stack and local variables. DvmState *mem_allocate(dvm_state_t* dvm_st, uint8_t capsuleNum) { DVMResourceManager_state_t *s = &(dvm_st->resmgr_st); uint8_t i; int8_t script_index = -1; if (capsuleNum >= DVM_CAPSULE_NUM) return NULL; if (s->scripts[capsuleNum] == NULL) { //Try to allocate space for (i = 0; i < DVM_NUM_SCRIPT_BLOCKS; i++) { if (s->script_block_owners[i] == NULL_CAPSULE) { script_index = i; s->script_block_owners[script_index] = capsuleNum; s->scripts[capsuleNum] = s->script_block_ptr + script_index; break; } } if (script_index < 0) { s->scripts[capsuleNum] = (DvmState *)sys_malloc(DVM_STATE_SIZE); if (s->scripts[capsuleNum] == NULL) return NULL; } // If control reaches here, this means space has been successfully // allocated for context etc. } memset(s->scripts[capsuleNum], 0, DVM_STATE_SIZE); return s->scripts[capsuleNum]; }
void __attribute__((destructor)) __ibprof_exit(void) { IBPROF_ERROR status = IBPROF_ERR_NONE; UNREFERENCED_PARAMETER(status); /* check if it has been activated */ if (ibprof_obj) { IBPROF_MODULE_OBJECT *temp_module_obj = NULL; int i = 0; ibprof_obj->task_obj->wall_time = ibprof_task_wall_time(ibprof_obj->task_obj->t_start); /* Dump all gathered information */ ibprof_dump(); temp_module_obj = ibprof_obj->module_array[0]; while (temp_module_obj) { if (temp_module_obj->id != IBPROF_MODULE_INVALID) { if (temp_module_obj->exit) status = temp_module_obj->exit(temp_module_obj); } temp_module_obj = ibprof_obj->module_array[++i]; } ibprof_hash_destroy(ibprof_obj->hash_obj); ibprof_task_destroy(ibprof_obj->task_obj); DELETE_CRITICAL(&(ibprof_obj->lock)); sys_free(ibprof_obj); ibprof_obj = NULL; } if (ibprof_dump_file && ibprof_dump_file != stdout && ibprof_dump_file != stderr) { struct stat statbuf; char fd_path[255]; char *filename = sys_malloc(255); size_t ret = 0; sys_sprintf(fd_path, "/proc/self/fd/%d", fileno(ibprof_dump_file)); ret = readlink(fd_path, filename, 255); if (ret > 0) { sys_fflush(ibprof_dump_file); sys_fclose(ibprof_dump_file); if (!sys_fstat(filename, &statbuf)) if (!statbuf.st_size) ret = sys_fremove(filename); } sys_free(filename); } return ; }
PRIVATE char * rpc__svc_fmt_dbg_msg (char *format, ...) { char *bptr; va_list arg_ptr; /* * Using malloc here is ugly but necessary. The formatted * string must be passed back as a pointer return value. The * possibility of recursive calls due to evaluation of pargs * (where, e.g., one of the pargs is a call to a routine that * calls RPC_DBG_PRINTF) preclude an implementation using a * mutex to protect a static buffer. The potential for infinite * recursion precludes allocating memory using internal RPC * interfaces, since those interfaces call RPC_DBG_PRINTF. */ if( (bptr = sys_malloc(RPC__SVC_DBG_MSG_SZ*sizeof(char))) == NULL ) { /* die horribly */ abort(); } va_start (arg_ptr, format); vsprintf (bptr, format, arg_ptr); va_end (arg_ptr); return( bptr ); }
char* read_child_str(pid_t pid, long int addr) { char *tmp, *str; int i, idx = 0; int buffer_size = 256; str = sys_malloc(buffer_size); while (1) { if (idx + READ_SIZE >= buffer_size) { buffer_size *= 2; str = realloc(str, buffer_size); } tmp = read_child_data_tid(pid, READ_SIZE, addr + idx); memcpy(str + idx, tmp, READ_SIZE); sys_free((void**) &tmp); for (i = 0; i < READ_SIZE; i++) { if (str[idx + i] == '\0') { return str; } } idx += READ_SIZE; } assert(1==0); }
const char* qio_spawn_strdup(const char* str) { size_t len = strlen(str); char* ret = sys_malloc(len + 1); // note: also copies '\0' at end of string. memcpy(ret, str, len + 1); return ret; }
TrashCollector *trash_create ( int items_max, TrashRemover *remove_function ) { TrashCollector *trash = sys_malloc(sizeof(TrashCollector)); trash->first = NULL; trash->top = maxv(items_max,1); trash->count = 0; trash->delete_function = remove_function; return trash; }
void chpl_setMemFlags(void) { chpl_bool local_memTrack = false; // // Get the values of the memTracking config consts from the module. // The runtime also has the execution-time settings for these same // config consts, but if their default values are changed at compile // time only the emitted code for the module reflects that; the // runtime doesn't know about it. So, we need to get the values // from the module. // // We use local_memTrack here so that the module code doesn't store // directly to our flag and effectively turn on memory tracking too // early. In the first version of this code I passed &chpl_memTrack // itself, and for comm=gasnet we ended up tracking an extra 2 bytes // of space the comm layer allocated as a result of our own call to // chpl_memTracking_returnConfigVals(). // chpl_memTracking_returnConfigVals(&local_memTrack, &memStats, &memLeaksByType, &memLeaksByDesc, &memLeaks, &memMax, &memThreshold, &memLog, &memLeaksLog); if (local_memTrack || memStats || memLeaksByType || (memLeaksByDesc && strcmp(memLeaksByDesc, "")) || memLeaks || memMax > 0 || memLeaksLog != NULL) { chpl_memTrack = true; } if (!memLog) { memLogFile = stdout; } else { if (chpl_numNodes == 1) { memLogFile = fopen(memLog, "w"); } else { char* filename = (char*)sys_malloc((strlen(memLog)+10)*sizeof(char)); sprintf(filename, "%s.%" PRI_c_nodeid_t, memLog, chpl_nodeID); memLogFile = fopen(filename, "w"); sys_free(filename); } } if (chpl_memTrack) { hashSizeIndex = 0; hashSize = hashSizes[hashSizeIndex]; memTable = sys_calloc(hashSize, sizeof(memTableEntry*)); } }
pid_t *pid_Init(void) { pid_t *pid = sys_malloc(sizeof(pid_t)); pid->kp = (short) NOR_PID_GAIN(PID_KP_DEF); pid->ki = (short) NOR_PID_GAIN(PID_KI_DEF); pid->kd = (short) NOR_PID_GAIN(PID_KD_DEF); pid->ref = 0; pid->err_history = 0; return pid; }
void* read_child_data_checked(struct context *ctx, ssize_t size, uintptr_t addr, ssize_t *read_bytes) { //assert(check_if_mapped(ctx, addr, addr + size)); void *buf = sys_malloc(size); /* if pread fails: do the following: echo 0 > /proc/sys/kernel/yama/ptrace_scope */ *read_bytes = checked_pread(ctx,buf,size,addr); return buf; }
/* 在线程中运行的函数 */ void k_thread_b(void* arg) { void* addr1 = sys_malloc(256); void* addr2 = sys_malloc(255); void* addr3 = sys_malloc(254); console_put_str(" thread_b malloc addr:0x"); console_put_int((int)addr1); console_put_char(','); console_put_int((int)addr2); console_put_char(','); console_put_int((int)addr3); console_put_char('\n'); int cpu_delay = 100000; while(cpu_delay-- > 0); sys_free(addr1); sys_free(addr2); sys_free(addr3); while(1); }
/* 回收inode的数据块和inode本身 */ void inode_release(struct partition* part, uint32_t inode_no) { struct inode* inode_to_del = inode_open(part, inode_no); ASSERT(inode_to_del->i_no == inode_no); /* 1 回收inode占用的所有块 */ uint8_t block_idx = 0, block_cnt = 12; uint32_t block_bitmap_idx; uint32_t all_blocks[140] = {0}; //12个直接块+128个间接块 /* a 先将前12个直接块存入all_blocks */ while (block_idx < 12) { all_blocks[block_idx] = inode_to_del->i_sectors[block_idx]; block_idx++; } /* b 如果一级间接块表存在,将其128个间接块读到all_blocks[12~], 并释放一级间接块表所占的扇区 */ if (inode_to_del->i_sectors[12] != 0) { ide_read(part->my_disk, inode_to_del->i_sectors[12], all_blocks + 12, 1); block_cnt = 140; /* 回收一级间接块表占用的扇区 */ block_bitmap_idx = inode_to_del->i_sectors[12] - part->sb->data_start_lba; ASSERT(block_bitmap_idx > 0); bitmap_set(&part->block_bitmap, block_bitmap_idx, 0); bitmap_sync(cur_part, block_bitmap_idx, BLOCK_BITMAP); } /* c inode所有的块地址已经收集到all_blocks中,下面逐个回收 */ block_idx = 0; while (block_idx < block_cnt) { if (all_blocks[block_idx] != 0) { block_bitmap_idx = 0; block_bitmap_idx = all_blocks[block_idx] - part->sb->data_start_lba; ASSERT(block_bitmap_idx > 0); bitmap_set(&part->block_bitmap, block_bitmap_idx, 0); bitmap_sync(cur_part, block_bitmap_idx, BLOCK_BITMAP); } block_idx++; } /*2 回收该inode所占用的inode */ bitmap_set(&part->inode_bitmap, inode_no, 0); bitmap_sync(cur_part, inode_no, INODE_BITMAP); /****** 以下inode_delete是调试用的 ****** * 此函数会在inode_table中将此inode清0, * 但实际上是不需要的,inode分配是由inode位图控制的, * 硬盘上的数据不需要清0,可以直接覆盖*/ void* io_buf = sys_malloc(1024); inode_delete(part, inode_no, io_buf); sys_free(io_buf); /***********************************************/ inode_close(inode_to_del); }
/** *@brief read string in initialization file\n * retrieves a string from the specified section in an initialization file *@param section [in] name of the section containing the key name *@param key [in] name of the key pairs to value *@param value [in] pointer to the buffer that receives the retrieved string *@param size [in] size of result's buffer *@param default_value [in] default value of result *@param file [in] path of the initialization file *@return 1 : read success; \n 0 : read fail */ int read_profile_string( const char *section, const char *key,char *value, int size, const char *default_value, const char *file) { char *buf; int file_size; int sec_s,sec_e,key_s,key_e, value_s, value_e; //check parameters assert(section != NULL && strlen(section)); assert(key != NULL && strlen(key)); assert(value != NULL); assert(size > 0); assert(file !=NULL &&strlen(key)); buf = (char *)sys_malloc(MAX_FILE_SIZE); memset(buf,0,MAX_FILE_SIZE); if(!load_ini_file(file,buf,&file_size)) { if(default_value!=NULL) { strncpy(value,default_value, size); } sys_free(buf); return 0; } if(!parse_file(section,key,buf,&sec_s,&sec_e,&key_s,&key_e,&value_s,&value_e)) { if(default_value!=NULL) { strncpy(value,default_value, size); } sys_free(buf); return 0; //not find the key } else { int cpcount = value_e -value_s; if( size-1 < cpcount) { cpcount = size-1; } memset(value, 0, size); memcpy(value,buf+value_s, cpcount ); value[cpcount] = '\0'; sys_free(buf); return 1; } }
/* Returns a list iterator 'iter'. After the initialization every * call to listNext() will return the next element of the list. * * This function can't fail. */ listIter *listGetIterator(list *list, int direction) { listIter *iter; if ((iter = sys_malloc(sizeof(*iter))) == NULL) return NULL; if (direction == AL_START_HEAD) iter->next = list->head; else iter->next = list->tail; iter->direction = direction; return iter; }
/* * DO WHAT THE F**K YOU WANT TO PUBLIC LICENSE * Version 2, December 2004 * * Copyright (C) 2004 Sam Hocevar <*****@*****.**> * * Everyone is permitted to copy and distribute verbatim or modified * copies of this license document, and changing it is allowed as long * as the name is changed. * * DO WHAT THE F**K YOU WANT TO PUBLIC LICENSE * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION * * 0. You just DO WHAT THE F**K YOU WANT TO. * * __________________________________________________________________ * * <scene_list> * A low-level interface which acts as the base code for <scene>. * You should use the high-level interface instead, which allows you * to easily create and manage the level list yourself without extra code for * managing/navigating/destroying the doubly linked list. * * Authors: Florastamine ([email protected]) * __________________________________________________________________ */ ChapterList *ChapterListCreate() { ChapterList *this = sys_malloc(sizeof(ChapterList)); this->firstnode = NULL; this->lastnode = NULL; this->iterator = NULL; this->next_iterator = NULL; this->length = 0; return this; }
ActionInformation *actinfo_add(List *list, STRING *name) { ActionInformation *info = NULL; for(info = list_first(list); info != NULL; info = list_next(list, info)) { if(strcmp(info->actionname, _chr(name)) == 0) return NULL; } info = sys_malloc(sizeof(ActionInformation)); strcpy(info->actionname, _chr(name)); list_insert_last(list, info); return info; }
/* Create a new list. The created list can be freed with * AlFreeList(), but private value of every node need to be freed * by the user before to call AlFreeList(). * * On error, NULL is returned. Otherwise the pointer to the new list. */ list *listCreate(void) { struct list *list; if ((list = sys_malloc(sizeof(*list))) == NULL) return NULL; list->head = list->tail = NULL; list->len = 0; list->dup = NULL; list->free = NULL; list->match = NULL; return list; }
static void start_sync() { app_state_t* s = (app_state_t*)sys_get_state(); LED_DBG(LED_YELLOW_TOGGLE); tpsn_req_t* tpsn_req_ptr = (tpsn_req_t *) sys_malloc(sizeof(tpsn_req_t)); tpsn_req_ptr->type = TPSN_REQUEST; tpsn_req_ptr->seq_no = s->current_seq_no; DEBUG("TPSN_NET: Transmitting TIMESYNC packet to node %d with seq_no=%d\n", s->parent_id, tpsn_req_ptr->seq_no); sys_post_net(s->pid, MSG_TIMESTAMP, sizeof(tpsn_req_t), tpsn_req_ptr, SOS_MSG_RELEASE, s->parent_id); sys_timer_start(SYNC_TIMER_ID, 50, TIMER_ONE_SHOT); }
// 当此函数被调用是, 说明已经和 master 建立了连接 void repl_syncWithMaster(eventloop* el, int fd, void *data, int mask){ // 创建一个客户端连接 clientContext *cc = cc_createClient(fd); if (cc == NULL) goto werr; // 连接上 master 删除, 读写事件 multi_deleteFileEvent(server.el, fd, MULTI_WRITABLE|MULTI_READABLE); if(server.repl_state == REPL_NONE) { close(fd); return; } //todo //向 master 发送同步命令 //select 阻塞等待 master 相应 struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; if (repl_sendSyncRequst(&tv, fd) < 0) goto werr; int maxtries = 3; char tmpfilename[256]; int dbfd; // 创建 db 保存的临时文件 while(maxtries--){ snprintf(tmpfilename, 256,"tmp-%d-%d.db", (int)getpid(), (int)time(NULL)); dbfd = open(tmpfilename, O_CREAT|O_WRONLY|O_EXCL, 0644); if(dbfd != -1) break; } if (dbfd == -1){ xlog(LOG_WARN, "create tmpfile: 创建 tmpfile 失败 %s\n", strerror(errno)); goto werr; } // 创建 master 发送的 db 数据读取函数 if (multi_createFileEvent(server.el, fd, MULTI_READABLE, repl_syncReadDB, cc) < 0){ xlog(LOG_WARN, "add event: 创建读取 db 事件失败"); goto werr; } // 更新 server 信息 server.repl_state = REPL_TRANSFER; server.repl_transfer_fd = dbfd; server.repl_transfer_tmpfile = sys_malloc(256); memcpy(server.repl_transfer_tmpfile, tmpfilename, 256); return; werr: server.repl_state = REPL_CONNECT; close(fd); return; }
int repl_slaveof(char *host, int port){ // 如果 host 为空则表示清除 master 关系 if(host == NULL){ if(server.masterhost) sys_free(server.masterhost); server.masterhost = NULL; server.masterport = -1; if (server.master)cc_freeClient(server.master); if (server.repl_state == REPL_TRANSFER){ multi_deleteFileEvent(server.el, server.repl_transfer_s, MULTI_READABLE); close(server.repl_transfer_s); close(server.repl_transfer_fd); unlink(server.repl_transfer_tmpfile); server.repl_state = REPL_NONE; } else if (server.repl_state == REPL_CONNECTING){ multi_deleteFileEvent(server.el, server.repl_transfer_s, MULTI_WRITABLE|MULTI_READABLE); close(server.repl_transfer_s); server.repl_state = REPL_NONE; } // host 不为空, 则根据 host 连接 master } else if (host!=NULL && port!=0){ server.masterhost = sys_malloc(ADDR_MAX_LEN); memcpy(server.masterhost, host, ADDR_MAX_LEN); server.masterport = port; if(server.master) cc_freeClient(server.master); listNode *ln; // 若存在 slave 则和slave断开连接 while(listLength(server.slaves)) { ln = listFirst(server.slaves); cc_freeClient((clientContext*)ln->value); } // 若正在和某个 master 传输 db 数据, 则终止传输 // 删除 db 文件 if (server.repl_state == REPL_TRANSFER){ multi_deleteFileEvent(server.el, server.repl_transfer_s, MULTI_READABLE); close(server.repl_transfer_s); close(server.repl_transfer_fd); unlink(server.repl_transfer_tmpfile); server.repl_state = REPL_NONE; } // 置 server 状态为需要与 master 建立连接状态 server.repl_state = REPL_CONNECT; xlog(LOG_INFO, "slave connect: slave 创建 master ip=%s, port=%d\n", server.masterhost, server.masterport); } else { // 参数错误 return -1; } return 0; }
void* read_child_data(struct context *ctx, ssize_t size, uintptr_t addr) { void *buf = sys_malloc(size); /* if pread fails: do the following: echo 0 > /proc/sys/kernel/yama/ptrace_scope */ ssize_t read_bytes = checked_pread(ctx,buf,size,addr); if (read_bytes != size) { free(buf); buf = read_child_data_tid(ctx->child_tid,size,addr); printf("reading from: %x demanded: %u read %u event: %d\n", addr, size, read_bytes, ctx->event); perror("warning: reading from child process: "); printf("try the following: echo 0 > /proc/sys/kernel/yama/ptrace_scope\n"); sleep(5); } return buf; }
ChapterData *ChapterDataCreate(const char *name, const char *internal_name, const STRING *thumbnail_name, const COLOR *vsun_color, const COLOR *vfog_color, const VECTOR *vfog_range, const float vsun_light) { ASSERT(internal_name, _chr("Fatal error in ChapterDataCreate(): A null char * pointer was given to the function, cannot create the data block.")); ASSERT(strlen(internal_name) < CHAPTER_INAME_MAX_LENGTH, _chr("Fatal error in ChapterDataCreate(): Chapter name's length exceeds CHAPTER_INAME_MAX_LENGTH.")); ChapterData *data = (ChapterData *) sys_malloc(sizeof(ChapterData)); data->chapter_name = (char *) sys_malloc(CHAPTER_NAME_MAX_LENGTH * sizeof(char)); data->chapter_iname = (char *) sys_malloc(CHAPTER_INAME_MAX_LENGTH * sizeof(char)); data->pad = (float *) sys_malloc(CHAPTER_PAD_VARS_MAX_LENGTH * sizeof(float)); data->sun_light = -1.0; // The chapter name can be left blank, whilist the chapter's internal name (its scene file) // must not be blank - each ChapterData struct has to be linked to a scene in some way. if(name) if(strlen(name) <= CHAPTER_NAME_MAX_LENGTH) strcpy(data->chapter_name, name); strcpy(data->chapter_iname, internal_name); // Continue to allocate and set up any additional parameters. if(thumbnail_name) if(file_exists(thumbnail_name)) data->thumbnail = bmap_create(thumbnail_name); if(vsun_color) { data->sun_color = (COLOR *) sys_malloc(sizeof(COLOR)); vec_set(data->sun_color, vsun_color); } if(vfog_color) { data->fog_color = (COLOR *) sys_malloc(sizeof(COLOR)); vec_set(data->fog_color, vfog_color); if(vfog_range) { data->fog_range = (VECTOR *) sys_malloc(sizeof(VECTOR)); vec_set(data->fog_range, vfog_range); } } if(vsun_light >= 0.0) data->sun_light = vsun_light; return data; }
RegAction *action_register(STRING *name, void *ptr) { if(registeredActions == NULL) registeredActions = list_create(); RegAction *info = NULL; for(info = list_first(registeredActions); info != NULL; info = list_next(registeredActions, info)) { if(strcmp(info->actionname, _chr(name)) == 0) return NULL; } info = sys_malloc(sizeof(RegAction)); strcpy(info->actionname, _chr(name)); info->ptr = ptr; list_insert_last(registeredActions, info); return info; }
struct dmm_s* dmm_open(const char *name) { struct instr_s *instr = instr_open(INSTR_CLASS_DMM, name); if(instr == NULL) { return NULL; } struct dmm_s *dmm_new = instr->priv; if(dmm_new == NULL) { instr->priv = dmm_new = sys_malloc(sizeof(struct dmm_s)); sys_assert(dmm_new != NULL); dmm_new->instr = instr; } dmm_select(dmm_new); return dmm_new; }
void* read_child_data(struct context *ctx, size_t size, uintptr_t addr) { size_t bytes_read; void* data = sys_malloc(size); /* if pread cannot read all data (for whatever reason) we use ptrace * primitives to get the rest. */ if ((bytes_read = pread64(ctx->child_mem_fd, data, size, addr)) < size) { assert(bytes_read >= 0); void* rest = read_child_data_tid(ctx->child_tid, size - bytes_read, addr + bytes_read); memcpy(data + bytes_read, rest, size - bytes_read); sys_free((void**) &rest); } /* make sure we no not return more than required */ return data; }
static void userint(){ //uint16_t i; uint32_t timestamped = sys_time32(); /* for (i=0; i < sys_rand()%10000; i++) { asm volatile("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t" ::); } */ //sys_led(LED_YELLOW_TOGGLE); msg_global_time_t* msg_global_time = (msg_global_time_t*)sys_malloc(sizeof(msg_global_time_t)); msg_global_time->time = timestamped; sys_post(TPSN_NET_PID, MSG_GET_GLOBAL_TIME, sizeof(msg_global_time_t), msg_global_time, SOS_MSG_RELEASE); //sys_post(DFLT_APP_ID1, MSG_GLOBAL_TIME_REPLY, sizeof(msg_global_time_t), msg_global_time, SOS_MSG_RELEASE); }
RJ_API rj_net_m_conn_h rj_m_conn_create(uint32 s_sbl, uint32 sbl, uint32 s_rbl, uint32 rbl) { rj_net_multi_conn_t *p_m_conn = (rj_net_multi_conn_t *)sys_malloc(sizeof(rj_net_multi_conn_t));//new rj_net_multi_conn_t; assert (NULL != p_m_conn); p_m_conn->p_sys_mutex = sys_mutex_create(); p_m_conn->conn_list = rj_list_create(); assert (NULL != p_m_conn->conn_list); p_m_conn->curr_conn = rj_list_end(p_m_conn->conn_list); p_m_conn->sub_send_buf_len = s_sbl; p_m_conn->send_buf_len = sbl; p_m_conn->sub_recv_buf_len = s_rbl; p_m_conn->recv_buf_len = rbl; return (rj_net_m_conn_h)(p_m_conn); }
void trash_add ( TrashCollector *trash, TrashData *data ) { if ( trash->count < trash->top ) { TrashItem *item = trash_recover ( itTrash ); if ( item == NULL ) item = sys_malloc(sizeof(TrashItem)); item->data = data; item->next = trash->first; trash->first = item; trash->count += 1; } else { trash->delete_function ( data ); } }
//---------------------------------------------------------------------------- // HANDLER FUNCTIONS //---------------------------------------------------------------------------- // case MSG_INIT: int8_t resmanager_init(dvm_state_t* dvm_st, Message *msg) { DEBUG("RES MNGR: Start Init\n"); uint8_t i; DVMResourceManager_state_t *s = &(dvm_st->resmgr_st); s->script_block_ptr = (DvmState *)sys_malloc(DVM_DEFAULT_MEM_ALLOC_SIZE); DEBUG("script block @ addr %08x \n", (uint32_t)s->script_block_ptr); if (s->script_block_ptr == NULL) DEBUG("No space for script blocks\n"); for (i = 0; i < DVM_CAPSULE_NUM; i++) { s->scripts[i] = NULL; } for (i = 0; i < DVM_NUM_SCRIPT_BLOCKS; i++) s->script_block_owners[i] = NULL_CAPSULE; DEBUG("RES MNGR: Initialized\n"); return SOS_OK; }