import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / threads / tmem.c
blob00203de5931d5b4addf381cb874afb4507128aa0
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
26 #include "lint.h"
27 #include "thr_uberdata.h"
30 * This file implements the private interface with libumem for per-thread
31 * caching umem (ptcumem). For the full details on how tcumem works and how
32 * these functions work, see section 8.4 of the big theory statement in
33 * lib/libumem/common/umem.c.
35 static tmem_func_t tmem_cleanup = NULL;
37 uintptr_t
38 _tmem_get_base(void)
40 return ((uintptr_t)&curthread->ul_tmem - (uintptr_t)curthread);
43 int
44 _tmem_get_nentries(void)
46 return (NTMEMBASE);
49 void
50 _tmem_set_cleanup(tmem_func_t f)
52 tmem_cleanup = f;
56 * This is called by _thrp_exit() to clean up any per-thread allocations that
57 * are still hanging around and haven't been cleaned up.
59 void
60 tmem_exit(void)
62 int ii;
63 void *buf, *next;
64 tumem_t *tp = &curthread->ul_tmem;
67 if (tp->tm_size == 0)
68 return;
71 * Since we have something stored here, we need to ensure we declared a
72 * clean up handler. If we haven't that's broken and our single private
73 * consumer should be shot.
75 if (tmem_cleanup == NULL)
76 abort();
77 for (ii = 0; ii < NTMEMBASE; ii++) {
78 buf = tp->tm_roots[ii];
79 while (buf != NULL) {
80 next = *(void **)buf;
81 tmem_cleanup(buf, ii);
82 buf = next;