|
1 | 1 | /* |
2 | 2 | Copyright 2007-2012 David Robillard <http://drobilla.net> |
| 3 | + Copyright 2016-2026 Filipe Coelho <falktx@falktx.com> |
3 | 4 |
|
4 | 5 | Permission to use, copy, modify, and/or distribute this software for any |
5 | 6 | purpose with or without fee is hereby granted, provided that the above |
|
14 | 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | 16 | */ |
16 | 17 |
|
17 | | -#include <stdlib.h> |
18 | | - |
19 | 18 | #include "worker.h" |
20 | 19 |
|
21 | 20 | #include <sched.h> |
| 21 | +#include <stdlib.h> |
| 22 | + |
| 23 | +#ifdef _WIN32 |
| 24 | +#include <windows.h> |
| 25 | +#else |
| 26 | +#include <sys/mman.h> |
| 27 | +#endif |
22 | 28 |
|
23 | 29 | static LV2_Worker_Status worker_respond(LV2_Worker_Respond_Handle handle, uint32_t size, const void* data) |
24 | 30 | { |
@@ -73,9 +79,18 @@ void worker_init(worker_t *worker, LilvInstance *instance, const LV2_Worker_Inte |
73 | 79 | zix_thread_create(&worker->thread, size + sizeof(void*) * 4, worker_func, worker); |
74 | 80 | worker->requests = jack_ringbuffer_create(size); |
75 | 81 | worker->responses = jack_ringbuffer_create(size); |
76 | | - worker->response = malloc(size); |
77 | 82 | jack_ringbuffer_mlock(worker->requests); |
78 | 83 | 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 |
79 | 94 | } |
80 | 95 |
|
81 | 96 | void worker_finish(worker_t *worker) |
|
0 commit comments