1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 2012, Joyent, Inc. All rights reserved. 24 */ 25 26 #include "lint.h" 27 #include "thr_uberdata.h" 28 29 /* 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. 34 */ 35 static tmem_func_t tmem_cleanup = NULL; 36 37 uintptr_t 38 _tmem_get_base(void) 39 { 40 return ((uintptr_t)&curthread->ul_tmem - (uintptr_t)curthread); 41 } 42 43 int 44 _tmem_get_nentries(void) 45 { 46 return (NTMEMBASE); 47 } 48 49 void 50 _tmem_set_cleanup(tmem_func_t f) 51 { 52 tmem_cleanup = f; 53 } 54 55 /* 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. 58 */ 59 void 60 tmem_exit(void) 61 { 62 int ii; 63 void *buf, *next; 64 tumem_t *tp = &curthread->ul_tmem; 65 66 67 if (tp->tm_size == 0) 68 return; 69 70 /* 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. 74 */ 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; 83 } 84 } 85 } 86