MCAS changes from Matt
[openafs.git] / src / mcas / ptst.h
1 /******************************************************************************
2  * ptst.h
3  *
4  * Per-thread state management.
5  *
6  * Copyright (c) 2002-2003, K A Fraser
7 Copyright (c) 2003, Keir Fraser All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are
11 met:
12
13     * Redistributions of source code must retain the above copyright
14     * notice, this list of conditions and the following disclaimer.
15     * Redistributions in binary form must reproduce the above
16     * copyright notice, this list of conditions and the following
17     * disclaimer in the documentation and/or other materials provided
18     * with the distribution.  Neither the name of the Keir Fraser
19     * nor the names of its contributors may be used to endorse or
20     * promote products derived from this software without specific
21     * prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 #ifndef __PTST_H__
37 #define __PTST_H__
38
39 typedef struct ptst_st ptst_t;
40
41 #include "gc.h"
42 #include "random.h"
43
44 struct ptst_st
45 {
46     /* Thread id */
47     unsigned int id;
48
49     /* State management */
50     ptst_t      *next;
51     unsigned int count;
52     /* Utility structures */
53     gc_t        *gc;
54     rand_t       rand;
55 };
56
57 extern pthread_key_t ptst_key;
58
59 /*
60  * Enter/leave a critical region. A thread gets a state handle for
61  * use during critical regions.
62  */
63 ptst_t *critical_enter(void);
64 #define critical_exit(_p) gc_exit(_p)
65
66 /* Iterators */
67 extern ptst_t *ptst_list;
68 #define ptst_first()  (ptst_list)
69 #define ptst_next(_p) ((_p)->next)
70
71 /* Called once at start-of-day for entire application. */
72 void _init_ptst_subsystem(void);
73
74 #endif /* __PTST_H__ */