Skip to content

Commit 665ae0a

Browse files
committed
lock memory used for worker restore
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 0169b93 commit 665ae0a

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/worker.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2007-2012 David Robillard <http://drobilla.net>
3+
Copyright 2016-2026 Filipe Coelho <falktx@falktx.com>
34
45
Permission to use, copy, modify, and/or distribute this software for any
56
purpose with or without fee is hereby granted, provided that the above
@@ -14,11 +15,16 @@
1415
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1516
*/
1617

17-
#include <stdlib.h>
18-
1918
#include "worker.h"
2019

2120
#include <sched.h>
21+
#include <stdlib.h>
22+
23+
#ifdef _WIN32
24+
#include <windows.h>
25+
#else
26+
#include <sys/mman.h>
27+
#endif
2228

2329
static LV2_Worker_Status worker_respond(LV2_Worker_Respond_Handle handle, uint32_t size, const void* data)
2430
{
@@ -73,9 +79,18 @@ void worker_init(worker_t *worker, LilvInstance *instance, const LV2_Worker_Inte
7379
zix_thread_create(&worker->thread, size + sizeof(void*) * 4, worker_func, worker);
7480
worker->requests = jack_ringbuffer_create(size);
7581
worker->responses = jack_ringbuffer_create(size);
76-
worker->response = malloc(size);
7782
jack_ringbuffer_mlock(worker->requests);
7883
jack_ringbuffer_mlock(worker->responses);
84+
85+
const uint32_t max_response_size = jack_ringbuffer_write_space(worker->responses);
86+
worker->response = malloc(max_response_size);
87+
#ifdef _WIN32
88+
VirtualLock(worker, sizeof(max_response_size));
89+
VirtualLock(worker->response, max_response_size);
90+
#else
91+
mlock(worker, sizeof(*worker));
92+
mlock(worker->response, max_response_size);
93+
#endif
7994
}
8095

8196
void worker_finish(worker_t *worker)

src/worker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2007-2012 David Robillard <http://drobilla.net>
3+
Copyright 2016-2026 Filipe Coelho <falktx@falktx.com>
34
45
Permission to use, copy, modify, and/or distribute this software for any
56
purpose with or without fee is hereby granted, provided that the above

0 commit comments

Comments
 (0)