result_t can_aerospace_init(const neutron_parameters_t *params, bool init_mode) { handle_t task_id; result_t result; hardware_revision = params->hardware_revision; software_revision = params->software_revision; node_id = params->node_id; if (failed(result = deque_create(sizeof(canmsg_t), params->tx_length == 0 ? DEFAULT_TX_QUEUE_SIZE : params->tx_length, &can_tx_queue))) { trace_error("Cannot create can_txt_queue"); return result; } if (failed(result = deque_create(sizeof(canmsg_t), params->rx_length == 0 ? DEFAULT_RX_QUEUE_SIZE : params->rx_length, &can_rx_queue))) { trace_error("Cannot create can_rx_queue"); return result; } if (failed(result = task_create("CAN_TX", params->tx_stack_length, can_tx_task, 0, NORMAL_PRIORITY, &task_id))) { trace_error("Cannot create the can_tx task"); return result; } if (failed(result = task_create("CAN_RX", params->rx_stack_length, can_rx_task, 0, NORMAL_PRIORITY + 1, &task_id))) { trace_error("Cannot create the can_rx task"); return result; } if(failed(result = neutron_init(params, init_mode))) return result; // start the can driver running. return bsp_can_init(can_rx_queue); }
// split dl after k int deque_split(const uint32_t k, deque_t *dl, deque_t **dl2) { if (dl->len < k) return -1; uint32_t i; *dl2 = deque_create(); list_t *l; if (k <= dl->len/2) { l = dl->start; for (i=0; i<k; i++) l = l->next; } else { l = dl->end; for (i=dl->len; i>k+1; i--) l = l->prev; } (*dl2)->len = dl->len - k; dl->end = l->prev; dl->len = k; l->prev = NULL; (*dl2)->start = l; (*dl2)->end = dl->end; l = dl->end; l->next = NULL; return 0; }
pth_pool_t * pth_pool_new (pth_attri_t *attrs, CAF_PT_PROTOTYPE(rtn), int count) { pth_pool_t *ptp = (pth_pool_t *)NULL; pthread_t *thr = (pthread_t *)NULL; int rc = 0; int c = 0; if (attrs != (pth_attri_t *)NULL) { ptp = (pth_pool_t *)xmalloc (CAF_PT_POOL_SZ); if (ptp != (pth_pool_t *)NULL && count > 0) { ptp->attri = attrs; ptp->rtn = rtn; ptp->threads = deque_create (); for (c = 1; c <= count; c++) { thr = (pthread_t *)xmalloc (sizeof(pthread_t)); if (thr != (pthread_t *)NULL) { if ((deque_push (ptp->threads, thr)) != (deque_t *)NULL) { rc++; } } } ptp->count = rc; } } return ptp; }
int main(int argc, char* argv[]) { deque_t q = deque_create(); deque_test_enqueue_dequeue(q, deque_push_front, deque_pop_front, 34352, 0.10234); deque_test_enqueue_dequeue(q, deque_push_front, deque_pop_rear, 454523, 1.3022); deque_test_enqueue_dequeue(q, deque_push_rear, deque_pop_front, 78797, 0.17672); deque_test_enqueue_dequeue(q, deque_push_rear, deque_pop_rear, 56239, 1.7987); deque_delete(&q); return 0; }
caf_dsm_t * caf_dsm_new (int id, int cycle) { caf_dsm_t *r = (caf_dsm_t *)NULL; if (id > 0) { r = (caf_dsm_t *)xmalloc (CAF_DSM_SZ); if (r != (caf_dsm_t *)NULL) { r->m_state = deque_create (); if (r->m_state != (deque_t *)NULL) { r->m_id = id; r->m_cycle = cycle; } else { xfree (r); r = (caf_dsm_t *)NULL; } } } return r; }
/** * Recursive iteration for file finding * * @param __dir - directory to search file in * @param __rel_dir - relative director name to search file in * @param __options - finding options * @param __res_wnd - window with results * @return zero on success, non-zero otherwise */ static int find_iteration (const wchar_t *__dir, const wchar_t *__rel_dir, const action_find_options_t *__options, action_find_res_wnd_t *__res_wnd) { int i, j, count; vfs_dirent_t **eps = NULL; size_t fn_len; wchar_t *format, *full_name; vfs_stat_t stat; vfs_stat_proc stat_proc; deque_t *dirs; wchar_t **dir_data; __res_wnd->dir_opened = FALSE; /* Get listing of directory */ /* * TODO: Add separately displaying of directories and files */ count = vfs_scandir (__dir, &eps, 0, vfs_alphasort); if (count < 0) { /* Error getting listing */ return ACTION_ERR; } if (TEST_FLAG(__options->flags, AFF_FIND_RECURSIVELY)) { dirs = deque_create (); } /* Get function for stat'ing */ if (TEST_FLAG(__options->flags, AFF_FOLLOW_SYMLINKS)) { stat_proc = vfs_stat; } else { stat_proc = vfs_lstat; } /* Allocate memory for full file name */ fn_len = wcslen (__dir) + MAX_FILENAME_LEN + 1; full_name = malloc ((fn_len + 1) * sizeof (wchar_t)); /* Get format mask for correct directory drilling */ if (__dir[wcslen (__dir) - 1] == '/') { format = L"%ls%ls"; } else { format = L"%ls/%ls"; } for (i = 0; i < count; ++i) { if (IS_PSEUDODIR (eps[i]->name)) { vfs_free_dirent (eps[i]); continue; } set_searching_status (__res_wnd, L"Searching in", __rel_dir); /* Get full file name */ swprintf (full_name, fn_len, format, __dir, eps[i]->name); /* Stat current node of FS */ if (!stat_proc (full_name, &stat) == VFS_OK) { /* Error getting status of file */ vfs_free_dirent (eps[i]); continue; } if (S_ISREG (stat.st_mode)) { if (check_regular_file (eps[i]->name, full_name, __options, __res_wnd)) { append_result (__rel_dir, eps[i]->name, stat, __res_wnd); ++__res_wnd->found_files; } } else if (S_ISDIR (stat.st_mode)) { /* Of user wants directories to be found... */ if (TEST_FLAG(__options->flags, AFF_FIND_DIRECTORIES)) { if (check_directory (eps[i]->name, full_name, __options, __res_wnd)) { append_result (__rel_dir, eps[i]->name, stat, __res_wnd); ++__res_wnd->found_dirs; } } if (TEST_FLAG(__options->flags, AFF_FIND_RECURSIVELY)) { dir_data = malloc (2 * sizeof (wchar_t)); dir_data[0] = wcsdup (eps[i]->name); dir_data[1] = wcsdup (full_name); deque_push_back (dirs, (void*)dir_data); } } else { if (check_special_file (eps[i]->name, full_name, __options, __res_wnd)) { append_result (__rel_dir, eps[i]->name, stat, __res_wnd); ++__res_wnd->found_files; } } vfs_free_dirent (eps[i]); hook_call (L"switch-task-hook", NULL); if (ACTION_PERFORMED (__res_wnd)) { /* Free remain dirents */ for (j = i + 1; j < count; ++j) { vfs_free_dirent (eps[j]); } break; } } SAFE_FREE (eps); free (full_name); if (TEST_FLAG(__options->flags, AFF_FIND_RECURSIVELY) && !ACTION_PERFORMED (__res_wnd)) { void *data; wchar_t *rel_name; if (__rel_dir[wcslen (__rel_dir) - 1] == '/') { format = L"%ls%ls"; } else { format = L"%ls/%ls"; } fn_len = wcslen (__dir) + MAX_FILENAME_LEN + 1; rel_name = malloc ((fn_len + 1) * sizeof (wchar_t)); deque_foreach (dirs, data); /* Drill relative file name */ dir_data = data; if (!ACTION_PERFORMED (__res_wnd)) { swprintf (rel_name, fn_len, format, __rel_dir, dir_data[0]); find_iteration (dir_data[1], rel_name, __options, __res_wnd); } free (dir_data); deque_foreach_done }