1139825Simp/*-
2112899Sjeff * Copyright (c) 2003, Jeffrey Roberson <jeff@freebsd.org>
3112899Sjeff * All rights reserved.
4112899Sjeff *
5112899Sjeff * Redistribution and use in source and binary forms, with or without
6112899Sjeff * modification, are permitted provided that the following conditions
7112899Sjeff * are met:
8112899Sjeff * 1. Redistributions of source code must retain the above copyright
9112899Sjeff *    notice unmodified, this list of conditions, and the following
10112899Sjeff *    disclaimer.
11112899Sjeff * 2. Redistributions in binary form must reproduce the above copyright
12112899Sjeff *    notice, this list of conditions and the following disclaimer in the
13112899Sjeff *    documentation and/or other materials provided with the distribution.
14112899Sjeff *
15112899Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16112899Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17112899Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18112899Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19112899Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20112899Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21112899Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22112899Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23112899Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24112899Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25112899Sjeff *
26112899Sjeff * $FreeBSD$
27112899Sjeff *
28112899Sjeff */
29112899Sjeff
30112899Sjeff#ifndef _SYS_THR_H_
31112899Sjeff#define	_SYS_THR_H_
32112899Sjeff
33206903Simp#include <sys/cdefs.h>
34171859Sdavidxu#include <sys/_types.h>
35164184Strhodes#include <sys/sched.h>
36160254Sdavidxu
37171859Sdavidxu#ifndef _SIZE_T_DECLARED
38171859Sdavidxutypedef __size_t	size_t;
39171859Sdavidxu#define _SIZE_T_DECLARED
40171859Sdavidxu#endif
41171859Sdavidxu
42145434Sdavidxu/* Create the thread in the suspended state. */
43145434Sdavidxu#define	THR_SUSPENDED		0x0001
44145434Sdavidxu/* Create the system scope thread. */
45145434Sdavidxu#define	THR_SYSTEM_SCOPE	0x0002
46112899Sjeff
47145434Sdavidxustruct thr_param {
48145434Sdavidxu    void	(*start_func)(void *);	/* thread entry function. */
49145434Sdavidxu    void	*arg;			/* argument for entry function. */
50145434Sdavidxu    char	*stack_base;		/* stack base address. */
51145434Sdavidxu    size_t	stack_size;		/* stack size. */
52145434Sdavidxu    char	*tls_base;		/* tls base address. */
53145434Sdavidxu    size_t	tls_size;		/* tls size. */
54145434Sdavidxu    long	*child_tid;		/* address to store new TID. */
55145434Sdavidxu    long	*parent_tid;		/* parent accesses the new TID here. */
56145434Sdavidxu    int		flags;			/* thread flags. */
57162497Sdavidxu    struct rtprio	*rtp;		/* Real-time scheduling priority */
58162497Sdavidxu    void	*spare[3];		/* TODO: cpu affinity mask etc. */
59145434Sdavidxu};
60145434Sdavidxu
61112899Sjeff/*
62112899Sjeff * See pthread_*
63112899Sjeff */
64112899Sjeff#ifndef _KERNEL
65171859Sdavidxu#include <sys/ucontext.h>
66112899Sjeff
67171859Sdavidxu#ifndef _PID_T_DECLARED
68171859Sdavidxutypedef __pid_t		pid_t;
69171859Sdavidxu#define _PID_T_DECLARED
70171859Sdavidxu#endif
71171859Sdavidxu
72206903Simp__BEGIN_DECLS
73131431Smarcelint thr_create(ucontext_t *ctx, long *id, int flags);
74145434Sdavidxuint thr_new(struct thr_param *param, int param_size);
75131431Smarcelint thr_self(long *id);
76136192Smtmvoid thr_exit(long *state);
77131431Smarcelint thr_kill(long id, int sig);
78171859Sdavidxuint thr_kill2(pid_t pid, long id, int sig);
79127482Smtmint thr_suspend(const struct timespec *timeout);
80131431Smarcelint thr_wake(long id);
81155327Sdavidxuint thr_set_name(long id, const char *name);
82206903Simp__END_DECLS
83112899Sjeff#endif /* !_KERNEL */
84112899Sjeff
85112899Sjeff#endif /* ! _SYS_THR_H_ */
86