Skip to content

Commit 2f1be30

Browse files
committed
Start some cleanup
Signed-off-by: falkTX <falktx@falktx.com>
1 parent b6ecd76 commit 2f1be30

File tree

4 files changed

+5
-52
lines changed

4 files changed

+5
-52
lines changed

src/effects.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,8 +4371,7 @@ int effects_init(void* client)
43714371
INIT_LIST_HEAD(&g_rtsafe_list);
43724372
INIT_LIST_HEAD(&g_raw_midi_port_list);
43734373

4374-
if (!rtsafe_memory_pool_create(&g_rtsafe_mem_pool, "mod-host", sizeof(postponed_event_list_data),
4375-
MAX_POSTPONED_EVENTS))
4374+
if (!rtsafe_memory_pool_create(&g_rtsafe_mem_pool, sizeof(postponed_event_list_data), MAX_POSTPONED_EVENTS))
43764375
{
43774376
fprintf(stderr, "can't allocate realtime-safe memory pool\n");
43784377
if (client == NULL)
@@ -5211,7 +5210,6 @@ int effects_add(const char *uri, int instance, int activate)
52115210
event_ports_count = 0;
52125211
input_event_ports_count = 0;
52135212
output_event_ports_count = 0;
5214-
worker_buf_size = 0;
52155213
effect->presets_count = 0;
52165214
effect->presets = NULL;
52175215
effect->monitors_count = 0;

src/monitor/monitor-client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ int jack_initialize(jack_client_t* client, const char* load_init)
465465
if (!mon->in_ports || !mon->out_ports)
466466
{
467467
fprintf(stderr, "out of memory\n");
468+
free(mon);
468469
return 1;
469470
}
470471

src/rtmempool/rtmempool.c

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,17 @@ typedef struct list_head k_list_head;
3333

3434
typedef struct _RtMemPool
3535
{
36-
char name[RTSAFE_MEMORY_POOL_NAME_MAX];
37-
38-
size_t dataSize;
39-
size_t maxPreallocated;
40-
4136
k_list_head used;
42-
unsigned int usedCount;
43-
4437
k_list_head unused;
45-
unsigned int unusedCount;
46-
4738
pthread_mutex_t mutex;
48-
4939
} RtMemPool;
5040

5141
// ------------------------------------------------------------------------------------------------
5242

5343
bool rtsafe_memory_pool_create(RtMemPool_Handle* handlePtr,
54-
const char* poolName,
5544
size_t dataSize,
5645
size_t maxPreallocated)
5746
{
58-
assert(poolName == NULL || strlen(poolName) < RTSAFE_MEMORY_POOL_NAME_MAX);
59-
6047
k_list_head* nodePtr;
6148
RtMemPool* poolPtr;
6249

@@ -67,23 +54,8 @@ bool rtsafe_memory_pool_create(RtMemPool_Handle* handlePtr,
6754
return false;
6855
}
6956

70-
if (poolName != NULL)
71-
{
72-
strcpy(poolPtr->name, poolName);
73-
}
74-
else
75-
{
76-
sprintf(poolPtr->name, "%p", poolPtr);
77-
}
78-
79-
poolPtr->dataSize = dataSize;
80-
poolPtr->maxPreallocated = maxPreallocated;
81-
8257
INIT_LIST_HEAD(&poolPtr->used);
83-
poolPtr->usedCount = 0;
84-
8558
INIT_LIST_HEAD(&poolPtr->unused);
86-
poolPtr->unusedCount = 0;
8759

8860
pthread_mutexattr_t atts;
8961
pthread_mutexattr_init(&atts);
@@ -93,17 +65,16 @@ bool rtsafe_memory_pool_create(RtMemPool_Handle* handlePtr,
9365
pthread_mutex_init(&poolPtr->mutex, &atts);
9466
pthread_mutexattr_destroy(&atts);
9567

96-
while (poolPtr->unusedCount < poolPtr->maxPreallocated)
68+
for (unsigned int unusedCount = 0; unusedCount < maxPreallocated; unusedCount++)
9769
{
98-
nodePtr = malloc(sizeof(k_list_head) + poolPtr->dataSize);
70+
nodePtr = malloc(sizeof(k_list_head) + dataSize);
9971

10072
if (nodePtr == NULL)
10173
{
10274
break;
10375
}
10476

10577
list_add_tail(nodePtr, &poolPtr->unused);
106-
poolPtr->unusedCount++;
10778
}
10879

10980
*handlePtr = (RtMemPool_Handle)poolPtr;
@@ -120,21 +91,10 @@ void rtsafe_memory_pool_destroy(RtMemPool_Handle handle)
12091
k_list_head* nodePtr;
12192
RtMemPool* poolPtr = (RtMemPool*)handle;
12293

123-
// caller should deallocate all chunks prior releasing pool itself
124-
if (poolPtr->usedCount != 0)
125-
{
126-
assert(0);
127-
}
128-
129-
while (poolPtr->unusedCount != 0)
94+
while (! list_empty(&poolPtr->unused))
13095
{
131-
assert(! list_empty(&poolPtr->unused));
132-
13396
nodePtr = poolPtr->unused.next;
134-
13597
list_del(nodePtr);
136-
poolPtr->unusedCount--;
137-
13898
free(nodePtr);
13999
}
140100

@@ -166,9 +126,6 @@ void* rtsafe_memory_pool_allocate_atomic(RtMemPool_Handle handle)
166126
nodePtr = poolPtr->unused.next;
167127
list_del(nodePtr);
168128

169-
poolPtr->unusedCount--;
170-
poolPtr->usedCount++;
171-
172129
list_add_tail(nodePtr, &poolPtr->used);
173130

174131
pthread_mutex_unlock(&poolPtr->mutex);
@@ -189,8 +146,6 @@ void rtsafe_memory_pool_deallocate(RtMemPool_Handle handle, void* memoryPtr)
189146

190147
list_del((k_list_head*)memoryPtr - 1);
191148
list_add_tail((k_list_head*)memoryPtr - 1, &poolPtr->unused);
192-
poolPtr->usedCount--;
193-
poolPtr->unusedCount++;
194149

195150
pthread_mutex_unlock(&poolPtr->mutex);
196151
}

src/rtmempool/rtmempool.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ typedef void* RtMemPool_Handle;
4646
* @return Success status, true if successful
4747
*/
4848
bool rtsafe_memory_pool_create(RtMemPool_Handle* handlePtr,
49-
const char* poolName,
5049
size_t dataSize,
5150
size_t maxPreallocated);
5251

0 commit comments

Comments
 (0)