pthread_md.h revision 165241
1144518Sdavidxu/*-
2144518Sdavidxu * Copyright (c) 2005 David Xu <davidxu@freebsd.org>.
3144518Sdavidxu * All rights reserved.
4144518Sdavidxu *
5144518Sdavidxu * Redistribution and use in source and binary forms, with or without
6144518Sdavidxu * modification, are permitted provided that the following conditions
7144518Sdavidxu * are met:
8144518Sdavidxu *
9144518Sdavidxu * 1. Redistributions of source code must retain the above copyright
10144518Sdavidxu *    notice, this list of conditions and the following disclaimer.
11144518Sdavidxu * 2. Redistributions in binary form must reproduce the above copyright
12144518Sdavidxu *    notice, this list of conditions and the following disclaimer in the
13144518Sdavidxu *    documentation and/or other materials provided with the distribution.
14144518Sdavidxu *
15144518Sdavidxu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16144518Sdavidxu * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17144518Sdavidxu * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18144518Sdavidxu * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19144518Sdavidxu * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20144518Sdavidxu * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21144518Sdavidxu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22144518Sdavidxu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23144518Sdavidxu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24144518Sdavidxu * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25144518Sdavidxu *
26144518Sdavidxu * $FreeBSD: head/lib/libthr/arch/arm/include/pthread_md.h 165241 2006-12-15 11:52:01Z davidxu $
27144518Sdavidxu */
28144518Sdavidxu
29144518Sdavidxu/*
30144518Sdavidxu * Machine-dependent thread prototypes/definitions.
31144518Sdavidxu */
32144518Sdavidxu#ifndef _PTHREAD_MD_H_
33144518Sdavidxu#define	_PTHREAD_MD_H_
34144518Sdavidxu
35144518Sdavidxu#include <sys/types.h>
36144518Sdavidxu#include <machine/sysarch.h>
37144518Sdavidxu#include <stddef.h>
38144518Sdavidxu
39165241Sdavidxu#define	CPU_SPINWAIT
40144518Sdavidxu#define	DTV_OFFSET		offsetof(struct tcb, tcb_dtv)
41144518Sdavidxu
42144518Sdavidxu/*
43144518Sdavidxu * Variant II tcb, first two members are required by rtld.
44144518Sdavidxu */
45144518Sdavidxustruct tcb {
46144518Sdavidxu	struct tcb              *tcb_self;	/* required by rtld */
47144518Sdavidxu	void                    *tcb_dtv;	/* required by rtld */
48144518Sdavidxu	struct pthread          *tcb_thread;	/* our hook */
49144518Sdavidxu	void			*tcb_spare[1];
50144518Sdavidxu};
51144518Sdavidxu
52144518Sdavidxu/*
53144518Sdavidxu * The tcb constructors.
54144518Sdavidxu */
55144518Sdavidxustruct tcb	*_tcb_ctor(struct pthread *, int);
56144518Sdavidxuvoid		_tcb_dtor(struct tcb *);
57144518Sdavidxu
58144518Sdavidxu/* Called from the thread to set its private data. */
59144518Sdavidxustatic __inline void
60144518Sdavidxu_tcb_set(struct tcb *tcb)
61144518Sdavidxu{
62144518Sdavidxu	*((struct tcb **)ARM_TP_ADDRESS) = tcb;
63144518Sdavidxu}
64144518Sdavidxu
65144518Sdavidxu/*
66144518Sdavidxu * Get the current tcb.
67144518Sdavidxu */
68144518Sdavidxustatic __inline struct tcb *
69144518Sdavidxu_tcb_get(void)
70144518Sdavidxu{
71144518Sdavidxu	return (*((struct tcb **)ARM_TP_ADDRESS));
72144518Sdavidxu}
73144518Sdavidxu
74144518Sdavidxuextern struct pthread *_thr_initial;
75144518Sdavidxu
76144518Sdavidxustatic __inline struct pthread *
77144518Sdavidxu_get_curthread(void)
78144518Sdavidxu{
79144518Sdavidxu	if (_thr_initial)
80144518Sdavidxu		return (_tcb_get()->tcb_thread);
81144518Sdavidxu	return (NULL);
82144518Sdavidxu}
83144518Sdavidxu
84144518Sdavidxu#endif /* _PTHREAD_MD_H_ */
85