char *strdup(const char *String) { char *Copy = (char *)OS_Malloc(strlen(String) + 1); if (Copy != NULL) strcpy(Copy, String); return Copy; }
INLINE Status OS_MessageMulticastSend(const OS_List* slots_qhd_l_p, OS_Message* msg_p, const OS_TimeMs timeout, const OS_MessagePrio priority) { OS_Message* msg_inst_p = OS_NULL; Status s = S_OK; if (OS_NULL != msg_p) { if (OS_NULL != slots_qhd_l_p) { OS_ListItem* iter_li_p = OS_ListItemNextGet((OS_ListItem*)&OS_ListItemLastGet(slots_qhd_l_p)); while (OS_DELAY_MAX != OS_ListItemValueGet(iter_li_p)) { const OS_QueueHd slot_qhd = (OS_QueueHd)OS_ListItemValueGet(iter_li_p); iter_li_p = OS_ListItemNextGet(iter_li_p); if (OS_DELAY_MAX != OS_ListItemValueGet(iter_li_p)) { // if the next item is present... if (OS_TRUE != OS_SignalIs(msg_p)) { // ...and it isn't a signal... const Size msg_size = sizeof(OS_Message) + msg_p->size; msg_inst_p = OS_Malloc(msg_size); // ...make an instance of the message. OS_MemCpy(msg_inst_p, msg_p, msg_size); } } IF_STATUS(s = OS_QueueSend(slot_qhd, &msg_p, timeout, priority)) { if (OS_NULL != msg_inst_p) { OS_MessageDelete(msg_inst_p); } return s; } if (OS_NULL != msg_inst_p) { msg_p = msg_inst_p; } } } else { s = S_INVALID_PTR; }
OS_Message* OS_MessageCreate(const OS_MessageId id, const OS_MessageData data_p, const OS_MessageSize size, const OS_TimeMs timeout) { OS_Message* msg_p = OS_Malloc(size + sizeof(OS_Message)); if (OS_NULL != msg_p) { OS_MemCpy(msg_p->data, data_p, size); msg_p->id = id; msg_p->size = size; msg_p->src = OS_TaskGet(); } return msg_p; }
Status OS_StorageItemCreate(const void* data_p, const U16 size, OS_StorageItem** item_pp) { if (OS_NULL == item_pp) { return S_INVALID_PTR; } OS_StorageItem* item_p = OS_Malloc(sizeof(OS_StorageItem)); if (OS_NULL == item_p) { return S_OUT_OF_MEMORY; } item_p->mutex = OS_MutexCreate(); if (OS_NULL == item_p->mutex) { return S_INVALID_PTR; } *item_pp = item_p; item_p->data_p = (void*)data_p; item_p->size = size; item_p->owners = 1; return S_OK; }
static BalloonChunk * BalloonChunk_Create(void) { BalloonChunk *chunk; /* allocate memory, fail if unable */ chunk = OS_Malloc(sizeof *chunk); if (chunk == NULL) { return NULL; } /* initialize */ OS_MemZero(chunk, sizeof *chunk); DblLnkLst_Init(&chunk->node); return chunk; }
/* * Function: tid_t OS_TaskCreate(uint32_t _stack_size, void *_ip, uint8 _priority) * * This routine creates a new thread and returns the TCB created */ tid_t OS_TaskCreate(uint32_t *_stackaddr, uint32_t _stacksize, void *_ip, void *_arg, uint8_t _priority) { OS_task_t *task; OS_Node_t *n; // DEBUG ("(_stackaddr=%p, _stacksize=%p, _ip=%p, _arg=%p, priority=%d)", // _stackaddr, _stacksize, _ip, _arg, _priority); ASSERT (_priority <= SCHED_MIN_PRIORITY); /* get a free thread control block */ n = (OS_Node_t *) OS_ListGetNode (&tcb_list); /* assert that we really have a free tcb */ ASSERT (n != NULL); if (n == NULL) return -1; task = GET_ELEMENT(OS_task_t, n, node); TRACE (task->tid, "d"); KTRACE (KTRACE_CREATE, task->tid, _priority); /* Stablish the thread stack */ if (_stackaddr == NULL) { if (_stacksize < CONFIG_ERCOS_MIN_STACK) _stacksize = CONFIG_ERCOS_MIN_STACK; _stackaddr = OS_Malloc (_stacksize); } else { ASSERT (_stacksize >= CONFIG_ERCOS_MIN_STACK); } task->stack.size = _stacksize; task->stack.addr = (uint8_t *)_stackaddr; /* Fill the stack with the 0x5a mark */ #ifndef CONFIG_NDEBUG // unsigned i; // DEBUG ("Stack @ %p, %p bytes", _stackaddr, _stacksize); // for (i = 0; i < _stacksize; i++) ((uint8_t *) _stackaddr)[i] = 0x5a; #endif /* Init the new thread context */ ercos_hal_hwcontext_init (&(task->context), task->stack.addr, task->stack.size, 0, OS_ThreadWrapper); /* Stablish the thread status */ task->status = TS_READY; /* Stablish the thread entry point */ task->entry_point = _ip; task->arg = _arg; /* Init the pointer to the catched mutex */ task->pmutex =(OS_Mutex_t*) NULL; /* Set the thread base and temporal priorities */ task->priority = _priority; task->base_priority = _priority; /* Add the task to the correspond sched queue */ OS_SchedTaskReady(task->tid); return task->tid; }