Line data Source code
1 : /* 2 : *------------------------------------------------------------------ 3 : * svm.h - shared VM allocation, mmap(...MAP_FIXED...) 4 : * brain police 5 : * 6 : * Copyright (c) 2009 Cisco and/or its affiliates. 7 : * Licensed under the Apache License, Version 2.0 (the "License"); 8 : * you may not use this file except in compliance with the License. 9 : * You may obtain a copy of the License at: 10 : * 11 : * http://www.apache.org/licenses/LICENSE-2.0 12 : * 13 : * Unless required by applicable law or agreed to in writing, software 14 : * distributed under the License is distributed on an "AS IS" BASIS, 15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 : * See the License for the specific language governing permissions and 17 : * limitations under the License. 18 : *------------------------------------------------------------------ 19 : */ 20 : 21 : #ifndef __included_svm_h__ 22 : #define __included_svm_h__ 23 : 24 : #include <pthread.h> 25 : #include <vppinfra/clib.h> 26 : #include <vppinfra/mem.h> 27 : #include <svm/svm_common.h> 28 : 29 : #define MMAP_PAGESIZE (clib_mem_get_page_size()) 30 : 31 : static inline void * 32 : svm_mem_alloc (svm_region_t * rp, uword size) 33 : { 34 : clib_mem_heap_t *oldheap; 35 : ASSERT (rp->flags & SVM_FLAGS_MHEAP); 36 : u8 *rv; 37 : 38 : pthread_mutex_lock (&rp->mutex); 39 : oldheap = clib_mem_set_heap (rp->data_heap); 40 : rv = clib_mem_alloc (size); 41 : clib_mem_set_heap (oldheap); 42 : pthread_mutex_unlock (&rp->mutex); 43 : return (rv); 44 : } 45 : 46 : static inline void 47 : svm_mem_free (svm_region_t * rp, void *ptr) 48 : { 49 : clib_mem_heap_t *oldheap; 50 : ASSERT (rp->flags & SVM_FLAGS_MHEAP); 51 : 52 : pthread_mutex_lock (&rp->mutex); 53 : oldheap = clib_mem_set_heap (rp->data_heap); 54 : clib_mem_free (ptr); 55 : clib_mem_set_heap (oldheap); 56 : pthread_mutex_unlock (&rp->mutex); 57 : 58 : } 59 : 60 : static inline void * 61 4042 : svm_push_pvt_heap (svm_region_t * rp) 62 : { 63 : clib_mem_heap_t *oldheap; 64 4042 : oldheap = clib_mem_set_heap (rp->region_heap); 65 4042 : return ((void *) oldheap); 66 : } 67 : 68 : static inline void * 69 53803 : svm_push_data_heap (svm_region_t * rp) 70 : { 71 : clib_mem_heap_t *oldheap; 72 53803 : oldheap = clib_mem_set_heap (rp->data_heap); 73 53803 : return ((void *) oldheap); 74 : } 75 : 76 : static inline void 77 57845 : svm_pop_heap (void *oldheap) 78 : { 79 57845 : clib_mem_set_heap (oldheap); 80 57845 : } 81 : 82 : #endif /* __included_svm_h__ */ 83 : 84 : /* 85 : * fd.io coding-style-patch-verification: ON 86 : * 87 : * Local Variables: 88 : * eval: (c-set-style "gnu") 89 : * End: 90 : */