/* Available in: irq. */ void __tt_schedule (void) { unsigned int priority; #ifdef TT_SUPPORT_STACK_CHECK /* Check if thread stack is healty */ tt_check_stack(g_thread_current); #endif // TT_SUPPORT_STACK_CHECK __tt_wakeup (); for (priority = g_athread_high_priorty; priority < TT_THREAD_PRIORITY_NUM; g_athread_high_priorty = ++priority) { if (listGetNext (&g_athread_running[priority]) != &g_athread_running[priority]) { /* Run next thread. */ LIST_T *next = listGetNext (&g_athread_running[priority]); g_thread_next = GetParentAddr (next, TT_THREAD_T, list_schedule); goto end; } } /* Run to here means no thread is running! */ g_thread_next = NULL; //g_thread_next = (TT_THREAD_T *) TCB_AT(g_thread_nop_buffer, sizeof (g_thread_nop_buffer)); //sysSafePrintf ("current: (%08x) %s\n", g_thread_current, g_thread_current->name); //sysSafePrintf ("%08x %08x %08x\n", g_thread_current->uPC, g_thread_current->uLR, g_thread_current->uSP); end: if (g_thread_current != g_thread_next) SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk; }
void tt_dump_threads (void (*func_dump) (TT_THREAD_T *thread, void *arg), void *arg) { LIST_T *list; tt_disable_irq (); for (list = listGetNext (&g_all_threads); list != &g_all_threads; list = listGetNext (list)) { TT_THREAD_T *thread = GetParentAddr (list, TT_THREAD_T, list_threads); (*func_dump) (thread, arg); } tt_enable_irq (); }
/** * Creates a copy of target list. * * The new copy will contain all the elements from the source list in the same * order and will use the same functions as the original list for copying and * freeing elements. * * @param list The target list to copy * @return * NULL if a NULL was sent or a memory allocation failed. * A List containing the same elements with same order as list otherwise. */ List listCopy(List list) { List copy = NULL; if (list != NULL) { copy = listCreate(list->copyElementFunc, list->freeElementFunc); } if ((copy != NULL) && (list->First != NULL)) { ListItem item_to_copy = list->First; while ((item_to_copy != NULL) && (copy != NULL)) { if (listInsertLast(copy, item_to_copy->Element) == LIST_SUCCESS) { if (list->Current == item_to_copy){ int size = GetListLength(copy); listGetFirst(copy); for (int i = 1; i < size; i++) { listGetNext(copy); } } item_to_copy = item_to_copy->Next; } else { listDestroy(copy); copy = NULL; } } } return copy; }
static int connectionMakeGetRequest(connectionContext_t* pCContext){ int count = listGetSize(pCContext->currentRequests); if (count < 1) { return 0; } request_t* pCurrent = listGetFirst(pCContext->currentRequests); int estimatedBufferSize = 0; while (pCurrent) { estimatedBufferSize = strlen(pCurrent->key) + 1; pCurrent = listGetNext(pCContext->currentRequests, pCurrent); } estimatedBufferSize -= 1; //don't need space after last key estimatedBufferSize += 4 + 2; // strlen("get ") + strlen("\r\n") u_int32_t offset = 0; char* buffer = 0; int written = 0; buffer = connectionGetBuffer(pCContext->connection, pCContext->fallocator, estimatedBufferSize, &offset); if (buffer) { request_t* pCurrent = listGetFirst(pCContext->currentRequests); strncpy(buffer+offset, "get ", 4); written += 4; while (pCurrent) { request_t* pNext = listGetNext(pCContext->currentRequests, pCurrent); int keyLength = strlen(pCurrent->key); strncpy(buffer+offset+written, pCurrent->key, keyLength); written+= keyLength; if (pNext) { strncpy(buffer+offset+written, " ", 1); written+= 1; } pCurrent = pNext; } strncpy(buffer+offset+written, "\r\n", 2); written += 2; LOG(DEBUG, "created request %.*s", written, buffer+offset); dataStreamAppendData(pCContext->writeStream, buffer, offset, written); //TODO : check return value } return written; }
static void __tt_wq_set_event (void *arg) { TT_WQ_T *wait_queue = (TT_WQ_T *)arg; while (!listIsEmpty (&wait_queue->list)) { LIST_T *list = listGetNext (&wait_queue->list); TT_THREAD_T *thread = GetParentAddr (list, TT_THREAD_T, list_schedule); /* Append the thread to running thread */ tt_set_thread_running (thread); __tt_schedule_yield (NULL); } }
/* Return: NULL, failed other, the message poped. Return pointer just indicates if a message was popped. Do not use it for other purpose. */ static TT_BMSG_T *tt_bmsg_pop (TT_BMSG_QUEUE_T *msg_queue, void **msg_data) { LIST_T *msg_node = listGetNext (&msg_queue->queue.msg_used); if (msg_node == &msg_queue->queue.msg_used) return NULL; else { TT_BMSG_T *msg = GetParentAddr (msg_node, TT_BMSG_T, list); listDetach (msg_node); if (msg_data != NULL) *msg_data = msg->msg_data; return msg; } }
/* Return: NULL, failed other, the message poped. Return pointer just indicates if a message was popped. Do not use it for other purpose. */ static TT_MSG_T *tt_msg_pop (TT_MSG_QUEUE_T *msg_queue, FUN_TT_MSG_PROC *msg_proc, void **msg_data) { LIST_T *msg_node = listGetNext (&msg_queue->msg_used); if (msg_node == &msg_queue->msg_used) return NULL; else { TT_MSG_T *msg = GetParentAddr (msg_node, TT_MSG_T, list); listDetach (msg_node); if (msg_proc != NULL) *msg_proc = msg->msg_proc; if (msg_data != NULL) *msg_data = msg->msg_data; memDel (msg_queue->msg_buffer, msg_node); return msg; } }
List listCopy(List list) { if (!list) { return NULL; } assert(list->copyElement); assert(list->freeElement); List newList = listCreate(list->copyElement,list->freeElement); VERIFY_ALLOCATION_RETURN_PTR(newList); newList->current = newList->head; Node current = NULL; FOREACH(ptr,list) { ListResult listResult = listInsertAfterCurrent(newList, ptr->data); if (listResult == LIST_OUT_OF_MEMORY) { listDestroy(newList); return NULL; } assert(listResult == LIST_SUCCESS); listGetNext(newList); if (ptr == list->current) { current = newList->current; } }
static bool testClientsManagerGetSortedPayments(){ Email email = NULL, mail1 = NULL ,mail2 = NULL, mail3 = NULL; emailCreate("gaba@ganosh", &email); emailCreate("baba@gash", &mail1); emailCreate("baba@gash2", &mail2); emailCreate("baaa@gash", &mail3); ClientsManager manager = clientsManagerCreate(); clientsManagerAdd( manager, email, 1, 1, 200); clientsManagerAdd( manager, mail1, 1, 2, 1000); clientsManagerAdd( manager, mail2, 1, 2, 1000); clientsManagerAdd( manager, mail3, 1, 2, 1000); List clients_list = NULL; ASSERT_TEST( clientsManagerGetSortedPayments(NULL, &clients_list) == CLIENT_MANAGER_INVALID_PARAMETERS); ASSERT_TEST( clientsManagerGetSortedPayments(manager,NULL) == CLIENT_MANAGER_INVALID_PARAMETERS); ASSERT_TEST( clientsManagerGetSortedPayments(manager, &clients_list) == CLIENT_MANAGER_SUCCESS); ASSERT_TEST( listGetSize(clients_list) == 0); listDestroy(clients_list); clientsManagerExecutePurchase( manager, email, 330); ASSERT_TEST( clientsManagerGetSortedPayments(manager, &clients_list) == CLIENT_MANAGER_SUCCESS); ASSERT_TEST( listGetSize(clients_list) == 1); listDestroy(clients_list); clientsManagerExecutePurchase( manager, mail1, 900); ASSERT_TEST( clientsManagerGetSortedPayments(manager, &clients_list) == CLIENT_MANAGER_SUCCESS); ASSERT_TEST( listGetSize(clients_list) == 2); ClientPurchaseBill top_bill = listGetFirst(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(top_bill), mail1)); ClientPurchaseBill second_bill = listGetNext(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(second_bill), email)); listDestroy(clients_list); clientsManagerExecutePurchase( manager, mail2, 900); ASSERT_TEST( clientsManagerGetSortedPayments(manager, &clients_list) == CLIENT_MANAGER_SUCCESS); ASSERT_TEST( listGetSize(clients_list) == 3); top_bill = listGetFirst(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(top_bill), mail1)); second_bill = listGetNext(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(second_bill), mail2)); second_bill = listGetNext(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(second_bill), email)); listDestroy(clients_list); clientsManagerExecutePurchase( manager, mail3, 900); ASSERT_TEST( clientsManagerGetSortedPayments(manager, &clients_list) == CLIENT_MANAGER_SUCCESS); ASSERT_TEST( listGetSize(clients_list) == 4); top_bill = listGetFirst(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(top_bill), mail3)); second_bill = listGetNext(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(second_bill), mail1)); second_bill = listGetNext(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(second_bill), mail2)); second_bill = listGetNext(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(second_bill), email)); listDestroy(clients_list); clientsManagerExecutePurchase(manager, email, 900); ASSERT_TEST( clientsManagerGetSortedPayments(manager, &clients_list) == CLIENT_MANAGER_SUCCESS); ASSERT_TEST( listGetSize(clients_list) == 4); top_bill = listGetFirst(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(top_bill), email)); second_bill = listGetNext(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(second_bill), mail3)); second_bill = listGetNext(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(second_bill), mail1)); second_bill = listGetNext(clients_list); ASSERT_TEST( emailAreEqual( clientPurchaseBillGetClientEmail(second_bill), mail2)); listDestroy(clients_list); emailDestroy(email); emailDestroy(mail1); emailDestroy(mail2); emailDestroy(mail3); clientsManagerDestroy(manager); return true; }