/* thread_create : task를 생성하는 함수로 taskinfo 구조체를 할당하고 구성한다. */ TaskInfo thread_create(TaskFunc callback, void *context) { TaskInfo taskinfo; // task를 위한 공간 할당 taskinfo = malloc(sizeof(*taskinfo)); memset(taskinfo, 0x00, sizeof(*taskinfo)); { struct frame *f = (struct frame *)&taskinfo->stack[THREAD_STACKSIZE - sizeof(struct frame)/4]; // taskinfo로 할당된 공간 중 stack부분 뒤쪽에 frame을 위한 공간으로 할당 // 이에 task가 수행되면서 stack공간을 활용 int i; for(i = 0; i < THREAD_STACKSIZE; ++i) { // stack overflow check taskinfo->stack[i] = i; } memset(f, 0, sizeof(struct frame)); f->retaddr = (unsigned long)callback; f->retaddr2 = (unsigned long)thread_kill; f->data = (unsigned long)context; taskinfo->sp = (unsigned long)&f->flags; f->ebp = (unsigned long)&f->eax; } // task 생성에 따라 gh_sch에 child task가 늘었음을 표시 gh_sch.child_task ++; // gh_sch.child_task 값으로 task_id 할당 taskinfo->task_id = gh_sch.child_task; // task 생성시 TASK_READY로 상태를 설정함 taskinfo->status = TASK_READY; // taskinfo구조체들의 linkedlist에 새 thread의 taskinfo 구조체를 삽입 task_insert(taskinfo); return taskinfo; }
void FATR sched_grp_insert_task_(Integer *task_list, Integer *tskid, Integer *nproc) { task_list_t *tlist = (task_list_t *)task_list; task_insert(tlist, *tskid, *nproc); }
int DllExport _nidaq_open (char* name) { int id ,status; char buf[256]; TaskHandle handle; sTask *pTask; sDataChain *pData; status = DAQmxLoadTask (name, &handle); if (status) { DAQmxGetErrorString (status, buf, 256); printf("%s\n",buf); return status; } id = task_insert(handle); pTask = tasks.item + id; /* # of channels */ DAQmxGetReadAttribute (handle, DAQmx_Read_NumChans, &pTask->numChannels); DAQmxGetTimingAttribute (handle, DAQmx_SampTimingType, &pTask->type); if (pTask->type== DAQmx_Val_OnDemand) { pData = malloc(sizeof(sDataChain)); pData->data = malloc(NBUF * pTask->numChannels * sizeof(short)); pData->num = 0; pData->next = 0; pTask->current = pData; pTask->start = pData; pTask->num = 0; } return id; }
STATIC void kernel() { //Create an idle-task task_insert(&idletask, idle, Low); //enable watchdog wdt_enable(WDTO_2S); //init user specific stuff init_user_environment(); //start scheduler task_schedule(); while(1) { /* this should never been reached */ } }
void task_add(void *task_list, int tskid, int nproc) { task_list_t *tlist = (task_list_t *)task_list; task_insert(tlist, tskid, nproc); }
/* Function: import_ical (bask_core* tcore, struct bask_task** first, char* filename); Description: Imports tasks from a ical formated file. InitVersion: 0.0.1 */ short import_ical (bask_core* tcore, struct bask_task** first, char* filename) { unsigned int tid; short tactive, tpriority, tstate; char line[200], today[T_S_DUE], tadded[T_S_ADDED], tdue[T_S_DUE], tfinished[T_S_FINISHED], tproject[T_S_PROJECT], tdescription[T_S_DESCRIPTION]; char tt_tmp[50]; char saveptr[200]; FILE* importfile; tid = tpriority = tstate = 0; tactive = TRUE; strcpy (tt_tmp, " "); strcpy (tadded, " "); strcpy (tdue, " "); strcpy (tfinished, " "); strcpy (tproject, " "); strcpy (tdescription, " "); time_get_str (today, sizeof (today)); importfile = fopen (filename, "r"); if (importfile == NULL) { errors_filenotopened (filename); return -1; } while (fgets (line, sizeof (line), importfile) != NULL) { if (parser_get_str (line, "END:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0) { if (utils_streq (tt_tmp, "VTODO") == 0) { if (tid == 0) { tcore->baskbin_uid++; tid = tcore->baskbin_uid; } /* TODO: Put that into a function! */ if (BITGET (tcore->t_options, T_O_AUTODUETODAY) == TRUE && utils_streq (tdue, "NONE") != 0 && ( time_get_day (today) == time_get_day (tdue) && time_get_month (today) == time_get_month (tdue) && time_get_year (today) == time_get_year (tdue))) { tpriority = 2; } task_insert (first, tcore->tc_amount, tid, tactive, tpriority, tstate, tadded, tdue, tfinished, tproject, tdescription); tcore->tc_amount++; tid = tpriority= 0; /* If there is no clue to tactive we enable it by default. */ tactive = TRUE; tstate = FALSE; } } else { parser_get_int (line, "UID:", &tid, ICALSEP, saveptr); /* Try multiple ways to find the data. */ if (parser_get_str (line, "CREATED:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0) { import_ical_getdatestr (tadded, tt_tmp); } else if (parser_get_str (line, "DTSTART:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0) { import_ical_getdatestr (tadded, tt_tmp); } else if (parser_get_str (line, "COMPLETED:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0) { if (import_ical_getdatestr (tfinished, tt_tmp) == -1) { strcpy (tfinished, "NONE"); tstate = FALSE; } else { tstate = TRUE; } } else if (parser_get_str (line, "DTEND:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0) { if (import_ical_getdatestr (tfinished, tt_tmp) == -1) { strcpy (tfinished, "NONE"); tstate = FALSE; } else { tstate = TRUE; } } else if (parser_get_str (line, "DUE:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0) { if (import_ical_getdatestr (tdue, tt_tmp) == -1) { strcpy (tdue, "NONE"); } } parser_get_short (line, "PRIORITY:", &tpriority, ICALSEP, saveptr); parser_get_str (line, "DESCRIPTION:", tdescription, sizeof (tdescription), ICALSEP, saveptr); parser_get_str (line, "SUMMARY:", tproject, sizeof (tproject), ICALSEP, saveptr); if (parser_get_str (line, "STATUS:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0) { if (utils_streq (tt_tmp, "IN-PROCESS") == 0) { tactive = TRUE; } else if (utils_streq (tt_tmp, "NEEDS-ACTION") == 0) { tactive = FALSE; } } } } fclose (importfile); return 0; }
/* Function: import_baskbin (bask_core* tcore, struct bask_task** first, char* filename); Description: Imports the tasks from a baskbin formated file. InitVersion: 0.0.1 */ short import_baskbin (bask_core* tcore, struct bask_task** first, char* filename) { unsigned int tid; int tstate, bb_state; short tactive, tpriority; char line[200], today[T_S_DUE], tadded[T_S_ADDED], tdue[T_S_DUE], tfinished[T_S_FINISHED], tproject[T_S_PROJECT], tdescription[T_S_DESCRIPTION]; char saveptr[200]; FILE* importfile; bb_state = tid = tactive = tpriority = tstate = 0; strcpy (tadded, "NONE"); strcpy (tdue, "NONE"); strcpy (tfinished, "NONE"); strcpy (tproject, " "); strcpy (tdescription, " "); time_get_str (today, sizeof (today)); importfile = fopen (filename, "r"); if (importfile == NULL) { errors_filenotopened (filename); return -1; } while (fgets (line, sizeof (line), importfile) != NULL) { if (utils_streq (line, "BASKBIN\n") == 0) { bb_state = TRUE; } else if (utils_streq (line, "BBEND\n") == 0) { bb_state = FALSE; } if (bb_state == TRUE) { parser_get_int (line, "bbuid=", &tcore->baskbin_uid, BASKSEP, saveptr); } else if (utils_streq (line, "END\n") == 0) { /* TODO: Put that into a function! */ if (BITGET (tcore->t_options, T_O_AUTODUETODAY) == TRUE && utils_streq (tdue, "NONE") != 0 && ( time_get_day (today) == time_get_day (tdue) && time_get_month (today) == time_get_month (tdue) && time_get_year (today) == time_get_year (tdue))) { tpriority = 2; } task_insert (first, tcore->tc_amount, tid, tactive, tpriority, tstate, tadded, tdue, tfinished, tproject, tdescription); tcore->tc_amount++; } else { parser_get_int (line, "tid=", &tid, BASKSEP, saveptr); parser_get_short (line, "tactive=", &tactive, BASKSEP, saveptr); parser_get_short (line, "tpriority=", &tpriority, BASKSEP, saveptr); parser_get_str (line, "tadded=", tadded, sizeof (tadded), BASKSEP, saveptr); parser_get_str (line, "tdue=", tdue, sizeof (tdue), BASKSEP, saveptr); if (parser_get_str (line, "tfinished=", tfinished, sizeof (tfinished), BASKSEP, saveptr) == 0) { /* Use this instead of tstate because this tells us already the state. */ if (strlen (tfinished) == F_BB_S_DATE-1) { tstate = TRUE; } else { tstate = FALSE; } } parser_get_str (line, "tproject=", tproject, sizeof (tproject), BASKSEP, saveptr); parser_get_str (line, "tdescription=", tdescription, sizeof (tdescription), BASKSEP, saveptr); } } fclose (importfile); return 0; }
/* Function: import_csv_parser (bask_core* tcore, struct bask_task** first, char* token, char* today, char* saveptr); Description: Parses a task data line from a csv formated file. InitVersion: 0.0.1 */ void import_csv_parser (bask_core* tcore, struct bask_task** first, char* token, char* today, char* saveptr) { unsigned int tid; int tstate; short tactive, tpriority; char tadded[T_S_ADDED], tdue[T_S_DUE], tfinished[T_S_FINISHED], tproject[T_S_PROJECT], tdescription[T_S_DESCRIPTION]; char tmp[200]; tid = tactive = tpriority = tstate = 0; tid = atoi (token); token = strtok_r (NULL, ";", &saveptr); utils_atos (&tactive, token); token = strtok_r (NULL, ";", &saveptr); utils_atos (&tpriority, token); token = strtok_r (NULL, ";", &saveptr); /* Subtracting 2 byte for the " chars. */ if (strlen (token)-2 < T_S_ADDED) { strcpy (tmp, token); if (tmp[0] == '"') { strcpy (tadded, &tmp[1]); } else { strcpy (tadded, tmp); } if (tadded[strlen (tadded)-1] == '"') { tadded[strlen (tadded)-1] = '\0'; } } else { strcpy (tadded, "NONE"); } token = strtok_r (NULL, ";", &saveptr); /* Subtracting 2 byte for the " chars. */ if (strlen (token)-2 < T_S_DUE) { strcpy (tmp, token); if (tmp[0] == '"') { strcpy (tdue, &tmp[1]); } else { strcpy (tdue, tmp); } if (tdue[strlen (tdue)-1] == '"') { tdue[strlen (tdue)-1] = '\0'; } } else { strcpy (tdue, "NONE"); } token = strtok_r (NULL, ";", &saveptr); /* Subtracting 2 byte for the " chars. */ if (strlen (token)-2 < T_S_FINISHED) { strcpy (tmp, token); if (tmp[0] == '"') { strcpy (tfinished, &tmp[1]); } else { strcpy (tfinished, tmp); } if (tfinished[strlen (tfinished)-1] == '"') { tfinished[strlen (tfinished)-1] = '\0'; } /* If the string isnt set to NONE its finished. */ if (strlen (tfinished) > 4) { tstate = TRUE; } } else { strcpy (tfinished, "NONE"); } token = strtok_r (NULL, ";", &saveptr); /* Subtracting 2 byte for the " chars. */ if (strlen (token)-2 < T_S_PROJECT) { strcpy (tmp, token); if (tmp[0] == '"') { strcpy (tproject, &tmp[1]); } else { strcpy (tproject, tmp); } if (tproject[strlen (tproject)-1] == '"') { tproject[strlen (tproject)-1] = '\0'; } } else { strcpy (tproject, " "); } token = strtok_r (NULL, ";\n", &saveptr); /* Subtracting 2 byte for the " chars. */ if (strlen (token)-2 < T_S_DESCRIPTION) { strcpy (tmp, token); if (tmp[0] == '"') { strcpy (tdescription, &tmp[1]); } else { strcpy (tdescription, tmp); } if (tdescription[strlen (tdescription)-1] == '"') { tdescription[strlen (tdescription)-1] = '\0'; } } else { strcpy (tdescription, " "); } /* TODO: Put that into a function! */ if (BITGET (tcore->t_options, T_O_AUTODUETODAY) == TRUE && utils_streq (tdue, "NONE") != 0 && ( time_get_day (today) == time_get_day (tdue) && time_get_month (today) == time_get_month (tdue) && time_get_year (today) == time_get_year (tdue))) { tpriority = 2; } tcore->baskbin_uid++; task_insert (first, tcore->tc_amount, tid, tactive, tpriority, tstate, tadded, tdue, tfinished, tproject, tdescription); tcore->tc_amount++; }