thr.h revision 164184
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: head/sys/sys/thr.h 164184 2006-11-11 16:26:58Z trhodes $
27112899Sjeff *
28112899Sjeff */
29112899Sjeff
30112899Sjeff#ifndef _SYS_THR_H_
31112899Sjeff#define	_SYS_THR_H_
32112899Sjeff
33164184Strhodes#include <sys/sched.h>
34160254Sdavidxu
35145434Sdavidxu/* Create the thread in the suspended state. */
36145434Sdavidxu#define	THR_SUSPENDED		0x0001
37145434Sdavidxu/* Create the system scope thread. */
38145434Sdavidxu#define	THR_SYSTEM_SCOPE	0x0002
39112899Sjeff
40145434Sdavidxustruct thr_param {
41145434Sdavidxu    void	(*start_func)(void *);	/* thread entry function. */
42145434Sdavidxu    void	*arg;			/* argument for entry function. */
43145434Sdavidxu    char	*stack_base;		/* stack base address. */
44145434Sdavidxu    size_t	stack_size;		/* stack size. */
45145434Sdavidxu    char	*tls_base;		/* tls base address. */
46145434Sdavidxu    size_t	tls_size;		/* tls size. */
47145434Sdavidxu    long	*child_tid;		/* address to store new TID. */
48145434Sdavidxu    long	*parent_tid;		/* parent accesses the new TID here. */
49145434Sdavidxu    int		flags;			/* thread flags. */
50162497Sdavidxu    struct rtprio	*rtp;		/* Real-time scheduling priority */
51162497Sdavidxu    void	*spare[3];		/* TODO: cpu affinity mask etc. */
52145434Sdavidxu};
53145434Sdavidxu
54112899Sjeff/*
55112899Sjeff * See pthread_*
56112899Sjeff */
57112899Sjeff#ifndef _KERNEL
58112899Sjeff
59131431Smarcelint thr_create(ucontext_t *ctx, long *id, int flags);
60145434Sdavidxuint thr_new(struct thr_param *param, int param_size);
61131431Smarcelint thr_self(long *id);
62136192Smtmvoid thr_exit(long *state);
63131431Smarcelint thr_kill(long id, int sig);
64127482Smtmint thr_suspend(const struct timespec *timeout);
65131431Smarcelint thr_wake(long id);
66155327Sdavidxuint thr_set_name(long id, const char *name);
67162551Sdavidxu#else
68162551Sdavidxustruct thread;
69162551Sdavidxuint kern_thr_new(struct thread *td, struct thr_param *param);
70162551Sdavidxuint kern_thr_suspend(struct thread *, struct timespec *);
71112899Sjeff#endif /* !_KERNEL */
72112899Sjeff
73112899Sjeff#endif /* ! _SYS_THR_H_ */
74