MCPcopy Create free account
hub / github.com/csound/csound / event_insert_thread

Function event_insert_thread

Engine/insert.c:155–232  ·  view source on GitHub ↗

* creates a thread to process instance allocations */

Source from the content-addressed store, hash-verified

153 * creates a thread to process instance allocations
154 */
155uintptr_t event_insert_thread(void *p) {
156 CSOUND *csound = (CSOUND *) p;
157 ALLOC_DATA *inst = csound->alloc_queue;
158 float wakeup = (1000*csound->ksmps/csound->esr);
159 unsigned long rp = 0, items, rpm = 0;
160 message_string_queue_t *mess = NULL;
161 void (*csoundMessageStringCallback)(CSOUND *csound,
162 int attr,
163 const char *str) = NULL;
164 void (*csoundMessageCallback)(CSOUND *csound,
165 int attr,
166 const char *format,
167 va_list args)
168 = csound->csoundMessageCallback_;
169 if(csound->oparms_.msglevel){
170 if(csound->message_string_queue == NULL)
171 csound->message_string_queue = (message_string_queue_t *)
172 csound->Calloc(csound, QUEUESIZ*sizeof(message_string_queue_t));
173 mess = csound->message_string_queue;
174 if(csound->csoundMessageStringCallback)
175 csoundMessageStringCallback = csound->csoundMessageStringCallback;
176 else csoundMessageStringCallback = print_messages;
177 csoundSetMessageStringCallback(csound, message_string_enqueue);
178 } else {
179 csoundSetMessageCallback(csound, no_op);
180 }
181
182 while(csound->event_insert_loop) {
183 // get the value of items_to_alloc
184 items = ATOMIC_GET(csound->alloc_queue_items);
185 if(items == 0)
186 csoundSleep((int) ((int) wakeup > 0 ? wakeup : 1));
187 else while(items) {
188 if (inst[rp].type == 3) {
189 INSDS *ip = inst[rp].ip;
190 OPDS *ids = inst[rp].ids;
191 csoundSpinLock(&csound->alloc_spinlock);
192 reinit_pass(csound, ip, ids);
193 csoundSpinUnLock(&csound->alloc_spinlock);
194 ATOMIC_SET(ip->init_done, 1);
195 }
196 if (inst[rp].type == 2) {
197 INSDS *ip = inst[rp].ip;
198 ATOMIC_SET(ip->init_done, 0);
199 csoundSpinLock(&csound->alloc_spinlock);
200 init_pass(csound, ip);
201 csoundSpinUnLock(&csound->alloc_spinlock);
202 ATOMIC_SET(ip->init_done, 1);
203 }
204 if(inst[rp].type == 1) {
205 csoundSpinLock(&csound->alloc_spinlock);
206 insert_midi(csound, inst[rp].insno, inst[rp].chn, &inst[rp].mep);
207 csoundSpinUnLock(&csound->alloc_spinlock);
208 }
209 if(inst[rp].type == 0) {
210 csoundSpinLock(&csound->alloc_spinlock);
211 insert_event(csound, inst[rp].insno, &inst[rp].blk);
212 csoundSpinUnLock(&csound->alloc_spinlock);

Callers

nothing calls this directly

Calls 9

csoundSetMessageCallbackFunction · 0.85
csoundSleepFunction · 0.85
csoundSpinLockFunction · 0.85
reinit_passFunction · 0.85
csoundSpinUnLockFunction · 0.85
init_passFunction · 0.85
insert_midiFunction · 0.85
insert_eventFunction · 0.85

Tested by

no test coverage detected