blob: 1589cb20f6805b860ac42a4dfa02b562d32c6e4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* Delayed deallocation of port_info objects.
Copyright (C) 2015 Free Software Foundation, Inc.
Written by Justus Winter <4winter@informatik.uni-hamburg.de>
This file is part of the GNU Hurd.
The GNU Hurd is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
The GNU Hurd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _HURD_PORTS_DEREF_DEFERRED_
#define _HURD_PORTS_DEREF_DEFERRED_
#include <pthread.h>
/* A list of port_info objects. */
struct pi_list;
/* We use protected payloads to look up objects without taking a lock.
A complication arises if we destroy an object using
ports_destroy_right. To avoid payloads from becoming stale (and
resulting in invalid memory accesses when being interpreted as
pointer), we delay the deallocation of those object until all
threads running at the time of the objects destruction are done
with whatever they were doing and entered a quiescent period. */
struct ports_threadpool
{
/* Access to the threadpool object is serialized by this lock. */
pthread_spinlock_t lock;
/* We maintain two sets of objects and threads. Each thread and the
threadpool itself has a color. If a thread has the same color as
the thread pool, it belongs to the old generation. */
unsigned int color;
/* The number of old threads. When an old thread enters its
quiescent period, it decrements OLD_THREADS and flips its color
(hence becoming a young thread). */
size_t old_threads;
/* A list of old objects. Once OLD_THREADS drops to zero, they are
deallocated, and all young threads and objects become old threads
and objects. */
struct pi_list *old_objects;
/* The number of young threads. Any thread joining or leaving the
thread group must be a young thread. */
size_t young_threads;
/* The list of young objects. Any object being marked for delayed
deallocation is added to this list. */
struct pi_list *young_objects;
};
/* Per-thread state. */
struct ports_thread
{
unsigned int color;
};
/* Initialize the thread pool. */
void _ports_threadpool_init (struct ports_threadpool *);
/* Called by a thread to join a thread pool. */
void _ports_thread_online (struct ports_threadpool *, struct ports_thread *);
/* Called by a thread that enters its quiescent period. */
void _ports_thread_quiescent (struct ports_threadpool *, struct ports_thread *);
/* Called by a thread to leave a thread pool. */
void _ports_thread_offline (struct ports_threadpool *, struct ports_thread *);
struct port_info;
/* Schedule an object for deallocation. */
void _ports_port_deref_deferred (struct port_info *);
#endif /* _HURD_PORTS_DEREF_DEFERRED_ */
|