/* Returns 1 if 'string' is a palindrom, 0 otherwise. */ int isPalindrome(char *string) { int result = 0; /* set to 1 if 'string' is a palindrome */ int i; int count = 0; /* Before finishing this function, you'll need to finish sll.c */ struct sll *halfword = sll_create(); struct sll *halfword2 = sll_create(); for (i = 0; i < (int)strlen(string)/2; i++) { /* "string[i]" will retrieve the next character */ sll_push(halfword, string[i]); printf("%c", sll_top(halfword)); } printf(" "); for (i = (int)strlen(string); i > (int)strlen(string)/2; i--) { sll_push(halfword2, string[i]); printf("%c", sll_top(halfword2)); } /* This loop will help you iterate over a string one character at time */ for (i = 0; i < (int)strlen(string)/2; i++) { if (sll_top(halfword) == sll_top(halfword2)) { sll_pop(halfword); sll_pop(halfword2); count++; } } printf("\n%d\n", count); if (count == (int)strlen(string)/2) { result = 1; } else { result = 0; } return result; }
/* * sleep_process_system_tick * @return: If not NULL returns the task that is needed to be scheduled next. * This function is called by scheduler to see if there is a task that is needed * to wake-up at a given system tick. */ static TASK *sleep_process_system_tick(void) { TASK *tcb = NULL; TASK *tcb_break = NULL; for (;;) { /* Check if we need to schedule a sleeping task. */ if ( (sleep_scheduler.ready_tasks.head != tcb_break) && (current_system_tick() >= sleep_scheduler.ready_tasks.head->tick_sleep) ) { /* Schedule this sleeping task. */ tcb = (TASK *)sll_pop(&sleep_scheduler.ready_tasks, OFFSETOF(TASK, next_sleep)); /* Task is already resumed. */ if (tcb->status != TASK_SUSPENDED) { /* Lets not get this task out of sleep any time soon. */ tcb->tick_sleep = MAX_WAIT; /* Put back this task on the scheduler list. */ /* We will remove it from this list when we will resume. */ sll_push(&sleep_scheduler.ready_tasks, tcb, OFFSETOF(TASK, next_sleep)); /* Save the task at which we will need to break the search. */ tcb_break = tcb; /* This is not the task we need. */ tcb = NULL; /* Check if we can resume the next task. */ continue; } else { /* Task is being resumed from sleep. */ tcb->status = TASK_RESUME_SLEEP; } } break; } /* Return the task that is needed to be scheduled. */ return (tcb); } /* sleep_process_system_tick */
/* * sleep_task_re_enqueue * @tcb: Task's control block that is needed to be put back in the sleeping * tasks list as there is a higher priority task that is needed to run before * this task. * @from: From where this function was called. * This scheduler's yield function, for now this only called by scheduler API's * when a task is needed to put back in the scheduler list as there is an other * higher priority task. */ static void sleep_task_re_enqueue(TASK *tcb, uint8_t from) { /* Process all the cases from a task can be re/scheduled. */ switch (from) { case YIELD_CANNOT_RUN: /* Just put back this task on the scheduler list. */ sll_push(&sleep_scheduler.ready_tasks, tcb, OFFSETOF(TASK, next_sleep)); /* Task is being suspended. */ tcb->status = TASK_SUSPENDED; break; default: break; } } /* sleep_task_re_enqueue */
/* * console_register * @console: Console data. * This function will register a console. */ void console_register(CONSOLE *console) { #ifndef CONFIG_SEMAPHORE /* Lock the scheduler. */ scheduler_lock(); #else /* Obtain the global data lock. */ OS_ASSERT(semaphore_obtain(&console_data.lock, MAX_WAIT) != SUCCESS); /* Create a semaphore to protect this console device. */ memset(&console->lock, 0, sizeof(SEMAPHORE)); semaphore_create(&console->lock, 1, 1, SEMAPHORE_PRIORITY); #endif /* This utility is called by drivers for registering consoles for the * applicable devices, so no need to check for name conflicts. */ /* Just push this file system in the list. */ sll_push(&console_data.list, console, OFFSETOF(CONSOLE, fs.next)); /* Initialize console FS data. */ console->fs.get_lock = console_lock; console->fs.release_lock = console_unlock; console->fs.timeout = MAX_WAIT; /* Initialize file system condition. */ fs_condition_init(&console->fs); #ifdef CONFIG_SEMAPHORE /* Release the global data lock. */ semaphore_release(&console_data.lock); #else /* Enable scheduling. */ scheduler_unlock(); #endif } /* console_register */