@@ -44,6 +44,7 @@ struct dmm_region {
44
44
struct dmm_heap {
45
45
struct sys_heap heap ;
46
46
const struct dmm_region * region ;
47
+ struct k_spinlock lock ;
47
48
};
48
49
49
50
static const struct dmm_region dmm_regions [] = {
@@ -54,6 +55,7 @@ struct {
54
55
struct dmm_heap dmm_heaps [ARRAY_SIZE (dmm_regions )];
55
56
} dmm_heaps_data ;
56
57
58
+
57
59
static struct dmm_heap * dmm_heap_find (void * region )
58
60
{
59
61
struct dmm_heap * dh ;
@@ -113,13 +115,25 @@ static size_t dmm_heap_size_get(struct dmm_heap *dh)
113
115
114
116
static void * dmm_buffer_alloc (struct dmm_heap * dh , size_t length )
115
117
{
118
+ void * ret ;
119
+ k_spinlock_key_t key ;
120
+
116
121
length = ROUND_UP (length , dh -> region -> dt_align );
117
- return sys_heap_aligned_alloc (& dh -> heap , dh -> region -> dt_align , length );
122
+
123
+ key = k_spin_lock (& dh -> lock );
124
+ ret = sys_heap_aligned_alloc (& dh -> heap , dh -> region -> dt_align , length );
125
+ k_spin_unlock (& dh -> lock , key );
126
+
127
+ return ret ;
118
128
}
119
129
120
130
static void dmm_buffer_free (struct dmm_heap * dh , void * buffer )
121
131
{
132
+ k_spinlock_key_t key ;
133
+
134
+ key = k_spin_lock (& dh -> lock );
122
135
sys_heap_free (& dh -> heap , buffer );
136
+ k_spin_unlock (& dh -> lock , key );
123
137
}
124
138
125
139
int dmm_buffer_out_prepare (void * region , void const * user_buffer , size_t user_length ,
0 commit comments