Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/main/shutdown.c

    rbab75df6 rf35749e  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2007 Martin Decky
    34 * All rights reserved.
     
    3738
    3839#include <arch.h>
    39 #include <proc/task.h>
     40#include <errno.h>
    4041#include <halt.h>
    4142#include <log.h>
     43#include <main/main.h>
     44#include <main/shutdown.h>
     45#include <proc/task.h>
     46#include <proc/thread.h>
     47
     48static thread_t *reboot_thrd = NULL;
     49SPINLOCK_INITIALIZE(reboot_lock);
    4250
    4351void reboot(void)
    4452{
    45         task_done();
     53        task_done(kernel_task);
    4654
    4755#ifdef CONFIG_DEBUG
     
    5361}
    5462
     63/** Thread procedure for rebooting the system.
     64 *
     65 * @param arg Argument (unused)
     66 */
     67static void reboot_thrd_proc(void *arg)
     68{
     69        (void)arg;
     70
     71        reboot();
     72}
     73
     74/** Reboot the system.
     75 *
     76 * @return EOK if reboot started successfully. EBUSY if reboot already
     77 *         started, ENOMEM if out of memory.
     78 */
     79sys_errno_t sys_reboot(void)
     80{
     81        thread_t *thread;
     82
     83        thread = thread_create(reboot_thrd_proc, NULL, kernel_task,
     84            THREAD_FLAG_NONE, "reboot");
     85        if (thread == NULL)
     86                return ENOMEM;
     87
     88        spinlock_lock(&reboot_lock);
     89
     90        if (reboot_thrd != NULL) {
     91                spinlock_unlock(&reboot_lock);
     92                thread_put(thread);
     93                return EBUSY;
     94        }
     95
     96        reboot_thrd = thread;
     97
     98        spinlock_unlock(&reboot_lock);
     99
     100        thread_start(thread);
     101        thread_detach(thread);
     102
     103        return EOK;
     104}
     105
    55106/** @}
    56107 */
Note: See TracChangeset for help on using the changeset viewer.