1/*- 2 * Copyright (c) 2015 Antti Kantee. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 14 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26#ifndef _BMK_CORE_SCHED_H_ 27#define _BMK_CORE_SCHED_H_ 28 29#include <bmk-core/types.h> 30 31#define BMK_TLS_EXTRA (6 * sizeof(unsigned long)) 32struct bmk_tcb { 33 unsigned long btcb_sp; /* stack pointer */ 34 unsigned long btcb_ip; /* program counter */ 35 36 unsigned long btcb_tp; /* tls pointer */ 37 unsigned long btcb_tpsize; /* tls area length */ 38}; 39 40struct bmk_thread; 41 42void bmk_sched_startmain(void (*)(void *), void *) __attribute__((noreturn)); 43 44void bmk_sched_yield(void); 45 46void bmk_sched_dumpqueue(void); 47 48struct bmk_thread *bmk_sched_create(const char *, void *, int, 49 void (*)(void *), void *, 50 void *, unsigned long); 51struct bmk_thread *bmk_sched_create_withtls(const char *, void *, int, 52 void (*)(void *), void *, 53 void *, unsigned long, void *); 54void bmk_sched_join(struct bmk_thread *); 55void bmk_sched_exit(void) __attribute__((__noreturn__)); 56void bmk_sched_exit_withtls(void) __attribute__((__noreturn__)); 57 58void bmk_sched_blockprepare(void); 59#define BMK_SCHED_BLOCK_INFTIME -1 60void bmk_sched_blockprepare_timeout(bmk_time_t); 61int bmk_sched_block(void); 62 63void bmk_sched_wake(struct bmk_thread *); 64 65 66void bmk_sched_suspend(struct bmk_thread *); 67void bmk_sched_unsuspend(struct bmk_thread *); 68 69 70void *bmk_sched_tls_alloc(void); 71void bmk_sched_tls_free(void *); 72 73void *bmk_sched_gettcb(void); 74 75void bmk_cpu_sched_create(struct bmk_thread *, struct bmk_tcb *, 76 void (*)(void *), void *, 77 void *, unsigned long); 78 79void bmk_sched_set_hook(void (*)(void *, void *)); 80struct bmk_thread *bmk_sched_init_mainlwp(void *); 81 82extern __thread struct bmk_thread *bmk_current; 83 84int *bmk_sched_geterrno(void); 85const char *bmk_sched_threadname(struct bmk_thread *); 86 87void bmk_cpu_sched_bouncer(void); 88void bmk_cpu_sched_switch(void *, void *); 89 90void bmk_platform_cpu_sched_settls(struct bmk_tcb *); 91void bmk_platform_cpu_sched_initcurrent(void *, struct bmk_thread *); 92 93#endif /* _BMK_CORE_SCHED_H_ */ 94