The idle thread is now actually run when the system is idle because it truly goes idle. The idle thread is made power efficient by using the hlt instruction rather than a busy loop. The new futex(2) system call is used to implement fast user-space mutexes, condition variables, and semaphores. The same backend and design is used as kutexes for truly sleeping kernel mutexes and condition variables. The new exit_thread(2) flag EXIT_THREAD_FUTEX_WAKE wakes a futex. Sleeping on clocks in the kernel now uses timers for true sleep. The interrupt worker thread now truly sleeps when idle. Kernel threads are now named. This is a compatible ABI change.
174 lines
3.5 KiB
C
174 lines
3.5 KiB
C
/*
|
|
* Copyright (c) 2013, 2014, 2017, 2021 Jonas 'Sortie' Termansen.
|
|
*
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*
|
|
* __/pthread.h
|
|
* Thread API.
|
|
*/
|
|
|
|
#ifndef INCLUDE____PTHREAD_H
|
|
#define INCLUDE____PTHREAD_H
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/__/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#if defined(__is_sortix_libc)
|
|
typedef struct
|
|
{
|
|
__SIZE_TYPE__ stack_size;
|
|
int detach_state;
|
|
} __pthread_attr_t;
|
|
#else
|
|
typedef struct
|
|
{
|
|
__SIZE_TYPE__ __pthread_stack_size;
|
|
int __pthread_detached_state;
|
|
} __pthread_attr_t;
|
|
#endif
|
|
|
|
typedef int __pthread_barrier_t;
|
|
|
|
typedef int __pthread_barrierattr_t;
|
|
|
|
typedef __SIZE_TYPE__ __pthread_key_t;
|
|
|
|
#if defined(__is_sortix_libc)
|
|
typedef struct
|
|
{
|
|
int lock;
|
|
unsigned long type;
|
|
unsigned long owner;
|
|
unsigned long recursion;
|
|
} __pthread_mutex_t;
|
|
#else
|
|
typedef struct
|
|
{
|
|
int __pthread_lock;
|
|
unsigned long __pthread_type;
|
|
unsigned long __pthread_owner;
|
|
unsigned long __pthread_recursion;
|
|
} __pthread_mutex_t;
|
|
#endif
|
|
|
|
#if defined(__is_sortix_libc)
|
|
typedef struct
|
|
{
|
|
int type;
|
|
} __pthread_mutexattr_t;
|
|
#else
|
|
typedef struct
|
|
{
|
|
int __pthread_type;
|
|
} __pthread_mutexattr_t;
|
|
#endif
|
|
|
|
#if defined(__is_sortix_libc)
|
|
typedef struct
|
|
{
|
|
__pthread_mutex_t lock;
|
|
struct pthread_cond_elem* first;
|
|
struct pthread_cond_elem* last;
|
|
__clockid_t clock;
|
|
} __pthread_cond_t;
|
|
#else
|
|
typedef struct
|
|
{
|
|
__pthread_mutex_t __pthread_lock;
|
|
void* __pthread_first;
|
|
void* __pthread_last;
|
|
__clockid_t __pthread_clock;
|
|
} __pthread_cond_t;
|
|
#endif
|
|
|
|
#if defined(__is_sortix_libc)
|
|
typedef struct
|
|
{
|
|
__clockid_t clock;
|
|
} __pthread_condattr_t;
|
|
#else
|
|
typedef struct
|
|
{
|
|
__clockid_t __pthread_clock;
|
|
} __pthread_condattr_t;
|
|
#endif
|
|
|
|
#if defined(__is_sortix_libc)
|
|
typedef struct
|
|
{
|
|
__pthread_mutex_t lock;
|
|
int executed;
|
|
} __pthread_once_t;
|
|
#else
|
|
typedef struct
|
|
{
|
|
__pthread_mutex_t __pthread_lock;
|
|
int __pthread_executed;
|
|
} __pthread_once_t;
|
|
#endif
|
|
|
|
#if defined(__is_sortix_libc)
|
|
typedef struct
|
|
{
|
|
__pthread_cond_t reader_condition;
|
|
__pthread_cond_t writer_condition;
|
|
__pthread_mutex_t request_mutex;
|
|
unsigned long num_readers;
|
|
unsigned long num_writers;
|
|
unsigned long pending_readers;
|
|
unsigned long pending_writers;
|
|
} __pthread_rwlock_t;
|
|
#else
|
|
typedef struct
|
|
{
|
|
__pthread_cond_t __pthread_reader_condition;
|
|
__pthread_cond_t __pthread_writer_condition;
|
|
__pthread_mutex_t __pthread_request_mutex;
|
|
unsigned long __pthread_num_readers;
|
|
unsigned long __pthread_num_writers;
|
|
unsigned long __pthread_pending_readers;
|
|
unsigned long __pthread_pending_writers;
|
|
} __pthread_rwlock_t;
|
|
#endif
|
|
|
|
#if defined(__is_sortix_libc)
|
|
typedef struct
|
|
{
|
|
char __structure_is_non_empty;
|
|
} __pthread_rwlockattr_t;
|
|
#else
|
|
typedef struct
|
|
{
|
|
char __structure_is_non_empty;
|
|
} __pthread_rwlockattr_t;
|
|
#endif
|
|
|
|
typedef int __pthread_spinlock_t;
|
|
|
|
#if defined(__is_sortix_libc)
|
|
typedef struct pthread* __pthread_t;
|
|
#else
|
|
typedef struct __pthread* __pthread_t;
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
} /* extern "C" */
|
|
#endif
|
|
|
|
#endif
|