static void freectx(PaCtx *ctx) { /* Destroy mutex */ pthread_mutex_destroy(&ctx->mtx); /* Free SRC resources */ if (ctx->src != NULL) src_delete(ctx->src); /* Free echo caneller */ if (ctx->echocan != NULL) echo_can_free(ctx->echocan); /* Free codec2 */ if (ctx->codec2 != NULL) codec2_destroy(ctx->codec2); /* Free FIFOs */ if (ctx->incoming != NULL) fifo_free(ctx->incoming); if (ctx->incrate != NULL) fifo_free(ctx->incrate); if (ctx->outgoing != NULL) fifo_free(ctx->outgoing); }
static void init_phase_two(workqueue_t *wq) { int num; /* * We're going to continually merge the first two entries on the queue, * placing the result on the end, until there's nothing left to merge. * At that point, everything will have been merged into one. The * initial value of ninqueue needs to be equal to the total number of * entries that will show up on the queue, both at the start of the * phase and as generated by merges during the phase. */ wq->wq_ninqueue = num = fifo_len(wq->wq_donequeue); while (num != 1) { wq->wq_ninqueue += num / 2; num = num / 2 + num % 2; } /* * Move the done queue to the work queue. We won't be using the done * queue in phase 2. */ assert(fifo_len(wq->wq_queue) == 0); fifo_free(wq->wq_queue, NULL); wq->wq_queue = wq->wq_donequeue; }
void free_fifo(void *item) { Fifo *op_queue = item; if (op_queue) { fifo_free(op_queue, operation_delete_func); } }
static void coreaudio_free(void *data) { coreaudio_t *dev = (coreaudio_t*)data; if (!dev) return; if (dev->dev_alive) { AudioOutputUnitStop(dev->dev); #ifdef OSX_PPC CloseComponent(dev->dev); #else AudioComponentInstanceDispose(dev->dev); #endif } if (dev->buffer) fifo_free(dev->buffer); slock_free(dev->lock); scond_free(dev->cond); free(dev); }
int mempool_destroy(struct mempool *mp) { int rc = VMM_OK; if (!mp) { return VMM_EFAIL; } switch (mp->type) { case MEMPOOL_TYPE_RAW: rc = vmm_host_memunmap(mp->entity_base); break; case MEMPOOL_TYPE_RAM: rc = vmm_host_free_pages(mp->entity_base, mp->d.ram.page_count); break; case MEMPOOL_TYPE_HEAP: vmm_free((void *)mp->entity_base); break; default: return VMM_EINVALID; }; fifo_free(mp->f); vmm_free(mp); return rc; }
static void coreaudio_free(void *data) { coreaudio_t *dev = (coreaudio_t*)data; if (!dev) return; if (dev->dev_alive) { AudioOutputUnitStop(dev->dev); #if (defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__))) CloseComponent(dev->dev); #else AudioComponentInstanceDispose(dev->dev); #endif } if (dev->buffer) fifo_free(dev->buffer); slock_free(dev->lock); scond_free(dev->cond); free(dev); }
static void dsound_free(void *data) { dsound_t *ds = (dsound_t*)data; if (ds) { if (ds->thread) { ds->thread_alive = false; WaitForSingleObject(ds->thread, INFINITE); CloseHandle(ds->thread); } DeleteCriticalSection(&ds->crit); if (ds->dsb) { IDirectSoundBuffer_Stop(ds->dsb); IDirectSoundBuffer_Release(ds->dsb); } if (ds->ds) IDirectSound_Release(ds->ds); if (ds->event) CloseHandle(ds->event); if (ds->buffer) fifo_free(ds->buffer); free(ds); } }
static void dsound_free(void *data) { dsound_t *ds = (dsound_t*)data; if (!ds) return; if (ds->thread) { ds->thread_alive = false; sthread_join(ds->thread); } DeleteCriticalSection(&ds->crit); if (ds->dsb) { IDirectSoundBuffer_Stop(ds->dsb); IDirectSoundBuffer_Release(ds->dsb); } if (ds->ds) IDirectSound_Release(ds->ds); if (ds->event) CloseHandle(ds->event); if (ds->buffer) fifo_free(ds->buffer); free(ds); }
/* Pop an operation off the queue for tile @index * The user of this function is reponsible for freeing the result using free() * * Concurrency: This function is reentrant (and lock-free) on different @index */ OperationDataDrawDab * operation_queue_pop(OperationQueue *self, TileIndex index) { OperationDataDrawDab *op = NULL; if (!tile_map_contains(self->tile_map, index)) { return NULL; } Fifo **queue_pointer = tile_map_get(self->tile_map, index); Fifo *op_queue = *queue_pointer; if (!op_queue) { return NULL; } op = fifo_pop(op_queue); if (!op) { // Queue empty fifo_free(op_queue, operation_delete_func); *queue_pointer = NULL; return NULL; } else { assert(op != NULL); return op; } }
static void alsa_thread_free(void *data) { alsa_thread_t *alsa = (alsa_thread_t*)data; if (alsa) { if (alsa->worker_thread) { slock_lock(alsa->cond_lock); alsa->thread_dead = true; slock_unlock(alsa->cond_lock); sthread_join(alsa->worker_thread); } if (alsa->buffer) fifo_free(alsa->buffer); if (alsa->cond) scond_free(alsa->cond); if (alsa->fifo_lock) slock_free(alsa->fifo_lock); if (alsa->cond_lock) slock_free(alsa->cond_lock); if (alsa->pcm) { snd_pcm_drop(alsa->pcm); snd_pcm_close(alsa->pcm); } free(alsa); } }
void task_free(task p) { if (p != NULL) { fifo_free(p->q, free); pthread_rwlock_destroy(&p->sublock); free(p); } }
static void deinit_thread_buf(ffemu_t *handle) { if (handle->audio_fifo) { fifo_free(handle->audio_fifo); handle->audio_fifo = NULL; } if (handle->attr_fifo) { fifo_free(handle->attr_fifo); handle->attr_fifo = NULL; } if (handle->video_fifo) { fifo_free(handle->video_fifo); handle->video_fifo = NULL; } }
int mempool_destroy(struct mempool *mp) { if (!mp) { return VMM_EFAIL; } vmm_host_free_pages(mp->page_base, mp->page_count); fifo_free(mp->f); vmm_free(mp); return VMM_OK; }
static void rs_free(void *data) { rsd_t *rsd = (rsd_t*)data; rsd_stop(rsd->rd); rsd_free(rsd->rd); fifo_free(rsd->buffer); slock_free(rsd->cond_lock); scond_free(rsd->cond); free(rsd); }
static void server_done(Server *s) { assert(s); while (s->fifos) fifo_free(s->fifos); safe_close(s->epoll_fd); if (s->bus) { sd_bus_flush(s->bus); sd_bus_unref(s->bus); } }
static void sdl_audio_free(void *data) { SDL_CloseAudio(); SDL_QuitSubSystem(SDL_INIT_AUDIO); sdl_audio_t *sdl = (sdl_audio_t*)data; if (sdl) { fifo_free(sdl->buffer); slock_free(sdl->lock); scond_free(sdl->cond); } free(sdl); }
static void server_done(Server *s) { assert(s); while (s->fifos) fifo_free(s->fifos); if (s->epoll_fd >= 0) close_nointr_nofail(s->epoll_fd); if (s->bus) { dbus_connection_flush(s->bus); dbus_connection_close(s->bus); dbus_connection_unref(s->bus); } }
void tile_map_free(TileMap *self, gboolean free_items) { const int map_size = 2*self->size*2*self->size; if (free_items) { for(int i = 0; i < map_size; i++) { Fifo *op_queue = self->map[i]; if (op_queue) { fifo_free(op_queue, operation_delete_func); } } } free(self->map); free(self); }
/** Reads one character from VCOM port @returns character read, or EOF if character could not be read */ int VCOM_getchar(void) { int result; U8 c; result = fifo_get(&rxfifo, &c) ? c : EOF; if (BulkOut_is_blocked && fifo_free(&rxfifo) >= MAX_PACKET_SIZE) { disableIRQ(); // get more data from usb bus BulkOut(BULK_OUT_EP, 0); BulkOut_is_blocked = false; enableIRQ(); } return result; }
struct mempool *mempool_ram_create(u32 entity_size, u32 page_count, u32 mem_flags) { u32 e; virtual_addr_t va; struct mempool *mp; if (!entity_size || ((VMM_PAGE_SIZE * page_count) < entity_size)) { return NULL; } mp = vmm_zalloc(sizeof(struct mempool)); if (!mp) { return NULL; } mp->type = MEMPOOL_TYPE_RAM; mp->entity_size = entity_size; mp->entity_count = udiv64((VMM_PAGE_SIZE * page_count), entity_size); mp->f = fifo_alloc(sizeof(virtual_addr_t), mp->entity_count); if (!mp->f) { vmm_free(mp); return NULL; } mp->entity_base = vmm_host_alloc_pages(page_count, mem_flags); if (!mp->entity_base) { fifo_free(mp->f); vmm_free(mp); return NULL; } mp->d.ram.page_count = page_count; mp->d.ram.mem_flags = mem_flags; for (e = 0; e < mp->entity_count; e++) { va = mp->entity_base + e * entity_size; fifo_enqueue(mp->f, &va, FALSE); } return mp; }
struct mempool *mempool_raw_create(u32 entity_size, physical_addr_t phys, virtual_size_t size, u32 mem_flags) { u32 e; virtual_addr_t va; struct mempool *mp; if (!entity_size || (size < entity_size)) { return NULL; } mp = vmm_zalloc(sizeof(struct mempool)); if (!mp) { return NULL; } mp->type = MEMPOOL_TYPE_RAW; mp->entity_size = entity_size; mp->entity_count = udiv64(size, entity_size); mp->f = fifo_alloc(sizeof(virtual_addr_t), mp->entity_count); if (!mp->f) { vmm_free(mp); return NULL; } mp->entity_base = vmm_host_memmap(phys, size, mem_flags); if (!mp->entity_base) { fifo_free(mp->f); vmm_free(mp); return NULL; } mp->d.raw.phys = phys; mp->d.raw.size = size; mp->d.raw.mem_flags = mem_flags; for (e = 0; e < mp->entity_count; e++) { va = mp->entity_base + e * entity_size; fifo_enqueue(mp->f, &va, FALSE); } return mp; }
int usb_serial_write(unsigned subdevice, char *buf, unsigned int count) { int room; int i; if (count == 0) return 0; room = fifo_free(&txfifo); if (room == 0) return 0; if (count > room) count = room; for (i = 0; i < count; i++) VCOM_putchar(*buf++); return count; }
bool_t unregister_console_input(struct input_t * input) { struct console_t * console; struct console_input_data_t * dat; console = search_console(input->name); if(!console) return FALSE; dat = (struct console_input_data_t *)console->priv; if(!unregister_console(console)) return FALSE; fifo_free(dat->fifo); free(dat); free(console->name); free(console); return TRUE; }
static int ne2k_driver_remove(struct vmm_driver *dev) { struct vmm_netdev *ndev; struct nic_priv_data *priv_data; ndev = (struct vmm_netdev *)dev->priv; if (ndev) { priv_data = (struct nic_priv_data *)ndev->priv; if (priv_data) { fifo_free(priv_data->rx_rb); vmm_free(priv_data); } vmm_free(ndev); dev->priv = NULL; } return 0; }
int main( int argc, char **argv ) { fifo_queue_t q; fifo_init(&q); #pragma omp parallel #pragma omp single nowait { int i; for(i=1;i<5;++i) { #pragma omp task { int j; for(j = 0; j < 1000; ++j) { fifo_enqueue(&q, i*1000+j); } } #pragma omp task { int d, j; for(j = 0; j < 1000; ++j) { d = fifo_dequeue(&q); if (d) printf("dequeue %d\n", d); } } } } int d; while (true) { d = fifo_dequeue(&q); if (d == -1) break; printf("dequeue %d\n", d); } assert(fifo_empty(&q)); #pragma omp taskwait fifo_free(&q); return 0; }
static void coreaudio_free(void *data) { coreaudio_t *dev = (coreaudio_t*)data; if (!dev) return; if (dev->dev_alive) { AudioOutputUnitStop(dev->dev); AudioComponentInstanceDispose(dev->dev); } if (dev->buffer) fifo_free(dev->buffer); pthread_mutex_destroy(&dev->lock); pthread_cond_destroy(&dev->cond); free(dev); }
static void ps3_audio_free(void *data) { uint64_t val; ps3_audio_t *aud = data; aud->quit_thread = true; ps3_audio_start(aud); sys_ppu_thread_join(aud->thread, &val); ps3_audio_stop(aud); cellAudioPortClose(aud->audio_port); cellAudioQuit(); fifo_free(aud->buffer); sys_lwmutex_destroy(&aud->lock); sys_lwmutex_destroy(&aud->cond_lock); sys_lwcond_destroy(&aud->cond); free(data); }
/** Local function to handle incoming bulk data @param [in] bEP @param [in] bEPStatus */ static void BulkOut(u8 bEP, u8 bEPStatus) { int i, iLen; if (fifo_free(&rxfifo) < MAX_PACKET_SIZE) { // may not fit into fifo return; } // get data from USB into intermediate buffer iLen = USBHwEPRead(bEP, abBulkBuf, sizeof(abBulkBuf)); for (i = 0; i < iLen; i++) { // put into FIFO if (!fifo_put(&rxfifo, abBulkBuf[i])) { // overflow... :( ASSERT(FALSE); break; } } }
struct mempool *mempool_heap_create(u32 entity_size, u32 entity_count) { u32 e; virtual_addr_t va; struct mempool *mp; if (!entity_size || !entity_count) { return NULL; } mp = vmm_zalloc(sizeof(struct mempool)); if (!mp) { return NULL; } mp->type = MEMPOOL_TYPE_HEAP; mp->entity_size = entity_size; mp->entity_count = entity_count; mp->f = fifo_alloc(sizeof(virtual_addr_t), mp->entity_count); if (!mp->f) { vmm_free(mp); return NULL; } mp->entity_base = (virtual_addr_t)vmm_malloc(entity_size * entity_count); if (!mp->entity_base) { fifo_free(mp->f); vmm_free(mp); return NULL; } for (e = 0; e < mp->entity_count; e++) { va = mp->entity_base + e * entity_size; fifo_enqueue(mp->f, &va, FALSE); } return mp; }
static int process_event(Server *s, struct epoll_event *ev) { int r; Fifo *f; assert(s); if (!(ev->events & EPOLLIN)) { log_info("Got invalid event from epoll. (3)"); return -EIO; } f = (Fifo*) ev->data.ptr; r = fifo_process(f); if (r < 0) { log_info_errno(r, "Got error on fifo: %m"); fifo_free(f); return r; } return 0; }