static void pull_event_loop(audioport_t *port, sys_event_queue_t id) { sys_event_t event; int16_t *in_buf = memalign(128, CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(int16_t)); float *conv_buf = memalign(128, CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(float)); while (!port->quit_thread) { uint32_t has_read = 0; if (port->sample_cb) has_read = port->sample_cb(in_buf, CELL_AUDIO_BLOCK_SAMPLES * port->channels, port->userdata); else { has_read = CELL_AUDIO_BLOCK_SAMPLES * port->channels; sys_lwmutex_lock(&port->lock, SYS_NO_TIMEOUT); uint32_t avail = fifo_read_avail(port->buffer); if (avail < CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(int16_t)) has_read = avail / sizeof(int16_t); fifo_read(port->buffer, in_buf, has_read * sizeof(int16_t)); sys_lwmutex_unlock(&port->lock); } if (has_read < CELL_AUDIO_BLOCK_SAMPLES * port->channels) memset(in_buf + has_read, 0, (CELL_AUDIO_BLOCK_SAMPLES * port->channels - has_read) * sizeof(int16_t)); resampler_int16_t_to_float(conv_buf, in_buf, CELL_AUDIO_BLOCK_SAMPLES * port->channels); sys_event_queue_receive(id, &event, SYS_NO_TIMEOUT); cellAudioAddData(port->audio_port, conv_buf, CELL_AUDIO_BLOCK_SAMPLES, 1.0); pthread_cond_signal(&port->cond); } free(conv_buf); }
static OSStatus audio_write_cb(void *userdata, AudioUnitRenderActionFlags *action_flags, const AudioTimeStamp *time_stamp, UInt32 bus_number, UInt32 number_frames, AudioBufferList *io_data) { coreaudio_t *dev = (coreaudio_t*)userdata; (void)time_stamp; (void)bus_number; (void)number_frames; if (!io_data) return noErr; if (io_data->mNumberBuffers != 1) return noErr; unsigned write_avail = io_data->mBuffers[0].mDataByteSize; void *outbuf = io_data->mBuffers[0].mData; pthread_mutex_lock(&dev->lock); if (fifo_read_avail(dev->buffer) < write_avail) { *action_flags = kAudioUnitRenderAction_OutputIsSilence; memset(outbuf, 0, write_avail); // Seems to be needed. pthread_mutex_unlock(&dev->lock); pthread_cond_signal(&dev->cond); // Technically possible to deadlock without. return noErr; } fifo_read(dev->buffer, outbuf, write_avail); pthread_mutex_unlock(&dev->lock); pthread_cond_signal(&dev->cond); return noErr; }
void *tx_task(void *arg) { sim_t *s = (sim_t *)arg; size_t samples_populated; while (1) { int16_t *tx_buffer_current = s->tx.buffer; unsigned int buffer_samples_remaining = SAMPLES_PER_BUFFER; while (buffer_samples_remaining > 0) { pthread_mutex_lock(&(s->gps.lock)); while (get_sample_length(s) == 0) { pthread_cond_wait(&(s->fifo_read_ready), &(s->gps.lock)); } // assert(get_sample_length(s) > 0); samples_populated = fifo_read(tx_buffer_current, buffer_samples_remaining, s); pthread_mutex_unlock(&(s->gps.lock)); pthread_cond_signal(&(s->fifo_write_ready)); #if 0 if (is_fifo_write_ready(s)) { /* printf("\rTime = %4.1f", s->time); s->time += 0.1; fflush(stdout); */ } else if (is_finished_generation(s)) { goto out; } #endif // Advance the buffer pointer. buffer_samples_remaining -= (unsigned int)samples_populated; tx_buffer_current += (2 * samples_populated); } // If there were no errors, transmit the data buffer. bladerf_sync_tx(s->tx.dev, s->tx.buffer, SAMPLES_PER_BUFFER, NULL, TIMEOUT_MS); if (is_fifo_write_ready(s)) { /* printf("\rTime = %4.1f", s->time); s->time += 0.1; fflush(stdout); */ } else if (is_finished_generation(s)) { goto out; } } out: return NULL; }
int child_process (void) { int fd; char buf [100]; /* Setup a signal handler for SIGINT */ signal (SIGINT, int_proc); signal (SIGTERM, int_proc); if (verbose) printf ("child start\n"); fd = fifo_open (FILENAME, 0); if (fd == -1) return EXIT_FAILURE; while (!stop) { memset (buf, 0, 100); fifo_read (fd, buf, 100); printf ("read: >%s<\n", buf); fflush (stdout); } fifo_close (fd); if (verbose) printf ("child done\n"); return EXIT_SUCCESS; }
void *tx_task(void *arg) { sim_t *s = (sim_t *)arg; size_t samples_populated; while (1) { int16_t *tx_buffer_current = s->tx.buffer; unsigned int buffer_samples_remaining = SAMPLES_PER_BUFFER; while (buffer_samples_remaining > 0) { samples_populated = fifo_read(tx_buffer_current, buffer_samples_remaining, s); if (is_fifo_write_ready(s)) { pthread_cond_signal(&(s->fifo_write_ready)); printf("\rTime = %4.1f", s->time); s->time += 0.1; fflush(stdout); } // Advance the buffer pointer. buffer_samples_remaining -= (unsigned int)samples_populated; tx_buffer_current += (2 * samples_populated); } // If there were no errors, transmit the data buffer. bladerf_sync_tx(s->tx.dev, s->tx.buffer, SAMPLES_PER_BUFFER, NULL, TIMEOUT_MS); } }
DWORD WINAPI read_fifo(LPVOID lpParam) { char buffer[4096]; pipe_t *pipe = (pipe_t*)lpParam; int wasRead; DWORD actualWritten; WINE_TRACE("\n"); for(;;) { wasRead = fifo_read(pipe->l,buffer,4096); if (wasRead<0) { printf("error reading fifo...\n"); break; } dump_data("%s, F->P",pipe->name,buffer,wasRead); if (!WriteFile(pipe->w,buffer,wasRead,&actualWritten,NULL)) { printf("error writing to pipe...\n"); break; } if (wasRead!=actualWritten) { printf("error writing data to pipe\n"); break; } } }
static void ffmpeg_flush_audio(ffmpeg_t *handle, void *audio_buf, size_t audio_buf_size) { size_t avail = fifo_read_avail(handle->audio_fifo); if (avail) { struct ffemu_audio_data aud = {0}; fifo_read(handle->audio_fifo, audio_buf, avail); aud.frames = avail / (sizeof(int16_t) * handle->params.channels); aud.data = audio_buf; ffmpeg_push_audio_thread(handle, &aud, false); } for (;;) { AVPacket pkt; if (!encode_audio(handle, &pkt, true) || !pkt.size || av_interleaved_write_frame(handle->muxer.ctx, &pkt) < 0) break; } }
static void filter(priv_t * p) { int i, num_in = max(0, fifo_occupancy(&p->input_fifo)); filter_t const * f = p->filter_ptr; int const overlap = f->num_taps - 1; double * output; while (num_in >= f->dft_length) { double const * input = fifo_read_ptr(&p->input_fifo); fifo_read(&p->input_fifo, f->dft_length - overlap, NULL); num_in -= f->dft_length - overlap; output = fifo_reserve(&p->output_fifo, f->dft_length); fifo_trim_by(&p->output_fifo, overlap); memcpy(output, input, f->dft_length * sizeof(*output)); lsx_safe_rdft(f->dft_length, 1, output); output[0] *= f->coefs[0]; output[1] *= f->coefs[1]; for (i = 2; i < f->dft_length; i += 2) { double tmp = output[i]; output[i ] = f->coefs[i ] * tmp - f->coefs[i+1] * output[i+1]; output[i+1] = f->coefs[i+1] * tmp + f->coefs[i ] * output[i+1]; } lsx_safe_rdft(f->dft_length, -1, output); } }
static int modem_pipe_read(struct m_pipe *pipe, struct modem_io *io) { char hdr[M_PIPE_MAX_HDR]; int ret; if (fifo_read(pipe->rx, hdr, pipe->header_size) == 0) return -EAGAIN; fifo_move_tail(pipe->rx, pipe->header_size); ret = pipe->pull_header(io, hdr); if (ret) return ret; if(io->magic != 0xCAFECAFE) { pr_err("modem_pipe_read: io->magic != 0xCAFECAFE, possible FIFO corruption\n"); return -EIO; } if (fifo_read_user(pipe->rx, io->data, io->datasize) != io->datasize) return -EIO; fifo_move_tail(pipe->rx, SIZ_PACKET_BUFSIZE); return 0; }
static void consume_item(void){ size_t size=100; bool q_status=false; ssize_t read=0; char buffer [100] = {0} ; char *buff; loff_t offset; loff_t * off; offset=0; buff = buffer; off = &offset; // printk(KERN_ALERT "read call accessed\n"); //size=strlen(MSG); //do { // printk(KERN_ALERT "we are at read call\n"); read = fifo_read(buff,size,off); if (read == 0){ printk(KERN_ALERT "we couldn't read\n"); } else printk(KERN_ALERT "we have read %d bytes\n",(int)read); off +=read; //}while (read!=0 && buff[read]!='\0'); printk(KERN_ALERT "consumed one item: \t\t\t\t%s\n",buffer); if (flag==0){ q_status=queue_delayed_work(consumer_wq,&consumer,HZ/rate); // printk(KERN_ALERT "Schduling next consumer\n"); } else printk(KERN_ALERT "consumer is unloading\n"); return 0; }
static void event_loop(uint64_t data) #endif { float out_tmp[CELL_AUDIO_BLOCK_SAMPLES * AUDIO_CHANNELS] __attribute__((aligned(16))); sys_event_queue_t id; sys_ipc_key_t key; sys_event_t event; ps3_audio_t *aud = data; cellAudioCreateNotifyEventQueue(&id, &key); cellAudioSetNotifyEventQueue(key); while (!aud->quit_thread) { sys_event_queue_receive(id, &event, SYS_NO_TIMEOUT); sys_lwmutex_lock(&aud->lock, SYS_NO_TIMEOUT); if (fifo_read_avail(aud->buffer) >= sizeof(out_tmp)) fifo_read(aud->buffer, out_tmp, sizeof(out_tmp)); else memset(out_tmp, 0, sizeof(out_tmp)); sys_lwmutex_unlock(&aud->lock); sys_lwcond_signal(&aud->cond); cellAudioAddData(aud->audio_port, out_tmp, CELL_AUDIO_BLOCK_SAMPLES, 1.0); } cellAudioRemoveNotifyEventQueue(key); sys_ppu_thread_exit(0); }
static int modem_pipe_read(struct m_pipe *pipe, struct modem_io *io) { unsigned data_size = io->size; char hdr[M_PIPE_MAX_HDR]; int ret; if (fifo_read(pipe->rx, hdr, pipe->header_size) == 0) return -EAGAIN; ret = pipe->pull_header(io, hdr); if (ret) return ret; if (data_size < io->size) { pr_info("modem_pipe_read: discarding packet (%d)\n", io->size); if (fifo_skip(pipe->rx, io->size + 1) != (io->size + 1)) return -EIO; return -EAGAIN; } else { if (fifo_read_user(pipe->rx, io->data, io->size) != io->size) return -EIO; if (fifo_skip(pipe->rx, 1) != 1) return -EIO; } return 0; }
void AudioOutputFiller::run() { int size = 256; char data[size]; running = 1; while(running) { if (fifo_bytes_available(fifo) < size) { usleep(10000); continue; } if (audio_output->bytesFree() < size) { usleep(10000); continue; } fifo_read(fifo, data, size); int res = output->write(data, size); if (res != size) { qDebug() << "write size mismatch! " << size << res; } } }
static uint32_t resampler_cb(void *userdata, float **data) { audioport_t *port = userdata; uint32_t has_read = 0; if (port->sample_cb) has_read = port->sample_cb(port->re_pull_buffer, CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(int16_t), port->userdata); else { has_read = CELL_AUDIO_BLOCK_SAMPLES * port->channels; sys_lwmutex_lock(&port->lock, SYS_NO_TIMEOUT); uint32_t avail = fifo_read_avail(port->buffer); if (avail < CELL_AUDIO_BLOCK_SAMPLES * port->channels * sizeof(int16_t)) has_read = avail / sizeof(int16_t); fifo_read(port->buffer, port->re_pull_buffer, has_read * sizeof(int16_t)); sys_lwmutex_unlock(&port->lock); sys_lwcond_signal(&port->cond); } if (has_read < CELL_AUDIO_BLOCK_SAMPLES * port->channels * 2) memset(port->re_pull_buffer + has_read, 0, (CELL_AUDIO_BLOCK_SAMPLES * port->channels - has_read) * sizeof(int16_t)); audio_convert_s16_to_float_altivec(port->re_buffer, port->re_pull_buffer, CELL_AUDIO_BLOCK_SAMPLES * port->channels); *data = port->re_buffer; return CELL_AUDIO_BLOCK_SAMPLES; }
static void adapter_thread(void *data) { uint8_t __attribute__((aligned(32))) send_command_buf[4096]; struct wiiusb_adapter *adapter = (struct wiiusb_adapter*)data; wiiusb_hid_t *hid = adapter ? adapter->hid : NULL; if (!adapter) return; while (!adapter->quitting) { size_t send_command_size; int tmp; int report_number; int size = 0; (void)tmp; (void)report_number; slock_lock(adapter->send_control_lock); if (fifo_read_avail(adapter->send_control_buffer) >= sizeof(send_command_size)) { fifo_read(adapter->send_control_buffer, &send_command_size, sizeof(send_command_size)); if (fifo_read_avail(adapter->send_control_buffer) >= sizeof(send_command_size)) { fifo_read(adapter->send_control_buffer, send_command_buf, send_command_size); USB_WriteIntrMsg(adapter->handle, adapter->endpoint_out, send_command_size, send_command_buf); } } slock_unlock(adapter->send_control_lock); size = USB_ReadIntrMsg(adapter->handle, adapter->endpoint_in, adapter->endpoint_in_max_size, &adapter->data[0]); /* RARCH_LOG("%p USB_ReadIntrMsg(%i, %i, %i, %p): %i\n", &adapter->data[0], adapter->handle, adapter->endpoint_in, adapter->endpoint_in_max_size, &adapter->data[0], size); */ //RARCH_LOG("%03i %03i %03i %03i\n", adapter->data[0], adapter->data[1], adapter->data[2], adapter->data[3], adapter->data[4]); //memmove(&adapter->data[1], &adapter->data[0], 2048); if (adapter && hid && hid->slots && size) pad_connection_packet(&hid->slots[adapter->slot], adapter->slot, adapter->data - 1, size+1); } }
static void ffemu_flush_buffers(ffemu_t *handle) { void *video_buf = av_malloc(2 * handle->params.fb_width * handle->params.fb_height * handle->video.pix_size); size_t audio_buf_size = 512 * handle->params.channels * sizeof(int16_t); int16_t *audio_buf = (int16_t*)av_malloc(audio_buf_size); // Try pushing data in an interleaving pattern to ease the work of the muxer a bit. bool did_work; do { did_work = false; if (fifo_read_avail(handle->audio_fifo) >= audio_buf_size) { fifo_read(handle->audio_fifo, audio_buf, audio_buf_size); struct ffemu_audio_data aud = {0}; aud.frames = 512; aud.data = audio_buf; ffemu_push_audio_thread(handle, &aud, true); did_work = true; } struct ffemu_video_data attr_buf; if (fifo_read_avail(handle->attr_fifo) >= sizeof(attr_buf)) { fifo_read(handle->attr_fifo, &attr_buf, sizeof(attr_buf)); fifo_read(handle->video_fifo, video_buf, attr_buf.height * attr_buf.pitch); attr_buf.data = video_buf; ffemu_push_video_thread(handle, &attr_buf); did_work = true; } } while (did_work); // Flush out last audio. ffemu_flush_audio(handle, audio_buf, audio_buf_size); // Flush out last video. ffemu_flush_video(handle); av_free(video_buf); av_free(audio_buf); }
static void adapter_thread(void *data) { uint8_t send_command_buf[4096]; struct libusb_adapter *adapter = (struct libusb_adapter*)data; libusb_hid_t *hid = adapter ? adapter->hid : NULL; if (!adapter) return; while (!adapter->quitting) { size_t send_command_size; int tmp; int report_number; int size = 0; slock_lock(adapter->send_control_lock); if (fifo_read_avail(adapter->send_control_buffer) >= sizeof(send_command_size)) { fifo_read(adapter->send_control_buffer, &send_command_size, sizeof(send_command_size)); if (fifo_read_avail(adapter->send_control_buffer) >= sizeof(send_command_size)) { fifo_read(adapter->send_control_buffer, send_command_buf, send_command_size); libusb_interrupt_transfer(adapter->handle, adapter->endpoint_out, send_command_buf, send_command_size, &tmp, 1000); } } slock_unlock(adapter->send_control_lock); libusb_interrupt_transfer(adapter->handle, adapter->endpoint_in, &adapter->data[1], adapter->endpoint_in_max_size, &size, 1000); if (adapter && hid && hid->slots && size) pad_connection_packet(&hid->slots[adapter->slot], adapter->slot, adapter->data, size+1); } }
uint8_t fifo_read_array(fifo_t *fifo, uint8_t *array, uint8_t size) { uint8_t i = 0; uint8_t c; while(i < size && fifo_read(fifo, &c) == 0) { array[i] = c; i++; } return i; }
static void alsa_worker_thread(void *data) { alsa_thread_t *alsa = (alsa_thread_t*)data; uint8_t *buf = (uint8_t *)calloc(1, alsa->period_size); if (!buf) { RARCH_ERR("failed to allocate audio buffer"); goto end; } while (!alsa->thread_dead) { size_t avail; size_t fifo_size; snd_pcm_sframes_t frames; slock_lock(alsa->fifo_lock); avail = fifo_read_avail(alsa->buffer); fifo_size = MIN(alsa->period_size, avail); fifo_read(alsa->buffer, buf, fifo_size); scond_signal(alsa->cond); slock_unlock(alsa->fifo_lock); /* If underrun, fill rest with silence. */ memset(buf + fifo_size, 0, alsa->period_size - fifo_size); frames = snd_pcm_writei(alsa->pcm, buf, alsa->period_frames); if (frames == -EPIPE || frames == -EINTR || frames == -ESTRPIPE) { if (snd_pcm_recover(alsa->pcm, frames, 1) < 0) { RARCH_ERR("[ALSA]: (#2) Failed to recover from error (%s)\n", snd_strerror(frames)); break; } continue; } else if (frames < 0) { RARCH_ERR("[ALSA]: Unknown error occurred (%s).\n", snd_strerror(frames)); break; } } end: slock_lock(alsa->cond_lock); alsa->thread_dead = true; scond_signal(alsa->cond); slock_unlock(alsa->cond_lock); free(buf); }
/* * Read wrapper for fifo's */ int ufsfifo_read(void *v) { struct vop_read_args *ap = v; /* * Set access flag. */ VTOI(ap->a_vp)->i_flag |= IN_ACCESS; return (fifo_read(ap)); }
static ssize_t audio_cb(void *data, size_t bytes, void *userdata) { rsd_t *rsd = (rsd_t*)userdata; size_t avail = fifo_read_avail(rsd->buffer); size_t write_size = bytes > avail ? avail : bytes; fifo_read(rsd->buffer, data, write_size); scond_signal(rsd->cond); return write_size; }
static void double_sample(stage_t * p, fifo_t * output_fifo) { sox_sample_t * output; int i, j, num_in = max(0, fifo_occupancy(&p->fifo)); rate_shared_t const * s = p->shared; dft_filter_t const * f = &s->half_band[p->which]; int const overlap = f->num_taps - 1; #ifdef SSE_ const float * const coeff = f->coefs; sox_sample_t tmp; __m128 coef, outp, sign; sign = SIGN; #endif while (p->rem + p->tuple * num_in >= f->dft_length) { div_t divd = div(f->dft_length - overlap - p->rem + p->tuple - 1, p->tuple); sox_sample_t const * input = fifo_read_ptr(&p->fifo); fifo_read(&p->fifo, divd.quot, NULL); num_in -= divd.quot; output = fifo_reserve_aligned(output_fifo, f->dft_length); fifo_trim_by(output_fifo, overlap); memset(output, 0, f->dft_length * sizeof(*output)); for (j = 0, i = p->rem; i < f->dft_length; ++j, i += p->tuple) output[i] = input[j]; p->rem = p->tuple - 1 - divd.rem; ff_rdft_x(f->dft_length, 1, output, f->tmp_buf); #ifdef SSE_ output[0] *= coeff[0]; output[1] *= coeff[1]; tmp = output[2]; output[2] = coeff[2] * tmp - coeff[3] * output[3]; output[3] = coeff[3] * tmp + coeff[2] * output[3]; for (i = 4; i < f->dft_length; i += 4) { outp = _mm_load_ps(output+i); coef = _mm_load_ps(coeff+i); _mm_store_ps(output+i, ZMUL2(outp, coef, sign)); } #else output[0] *= f->coefs[0]; output[1] *= f->coefs[1]; for (i = 2; i < f->dft_length; i += 2) { sox_sample_t tmp = output[i]; output[i ] = f->coefs[i ] * tmp - f->coefs[i+1] * output[i+1]; output[i+1] = f->coefs[i+1] * tmp + f->coefs[i ] * output[i+1]; } #endif ff_rdft_x(f->dft_length, -1, output, f->tmp_buf); } }
static void sdl_audio_cb(void *data, Uint8 *stream, int len) { sdl_audio_t *sdl = (sdl_audio_t*)data; size_t avail = fifo_read_avail(sdl->buffer); size_t write_size = len > (int)avail ? avail : len; fifo_read(sdl->buffer, stream, write_size); scond_signal(sdl->cond); // If underrun, fill rest with silence. memset(stream + write_size, 0, len - write_size); }
uint16_t fifo_read_n(fifo_t* f, uint8_t* rx, uint16_t maxlen) { uint16_t len = 0; while ( len < maxlen && fifo_read(f, rx) ) { len++; rx++; } return len; }
/** Function Name : fifo_module_read Function Type : Kernel Callback Method Description : Method is invoked whenever the fifo device files are read. This callback method is triggered when a read operation performed on the devices register to this file operation object. FIFO Devices are allocated. */ static ssize_t fifo_module_read(struct file *file, char *buf, size_t count, loff_t *ppos) { if(finished_fifo) { /** Successful execution of read callback with EOF reached.*/ return 0; } /** Flag set to Completed marking EOF.*/ finished_fifo = 1; return fifo_read(buf,count,ppos); }
static PyObject* fifoRead(PyObject* self, PyObject* arg) { PyObject* transferTuple; unsigned int id, size, i ; if(!PyArg_ParseTuple(arg, "ll", &id, &size)) return NULL; uint8_t rx[size]; fifo_read(id, rx, size); transferTuple = PyTuple_New(size); for(i=0;i<size;i++) PyTuple_SetItem(transferTuple, i, Py_BuildValue("i",rx[i])); return transferTuple; }
/****************************************************************************** Description.: copy a picture from testpictures.h and signal this to all output plugins, afterwards switch to the next frame of the animation. Input Value.: arg is not used Return Value: NULL ******************************************************************************/ void *worker_thread(void *arg) { int i = 0; int remaining ; char * fPointer ; int outlen = 0; int vsync = 0 ; /* set cleanup handler to cleanup allocated ressources */ pthread_cleanup_push(worker_cleanup, NULL); while(!pglobal->stop) { pthread_mutex_lock(&pglobal->in[plugin_number].db); //TODO: need to iterate to get the vsync signal and then grab a full frame fifo_reset(); fifo_read(grab_buffer, 320*240*3); i = 0 ; vsync = 0 ; while(!vsync && i < (320*240*3)){ unsigned short * shortVal ; shortVal = &grab_buffer[i]; if(*shortVal == 0xAA55){ i+=2 ; if( (i < (320*240*2)) && grab_buffer[i+(320*240)] == 0x55){ vsync = 1 ; fPointer = &grab_buffer[i]; break ; } } i ++ ; } if(vsync){ DBG("Vsync found !\n"); if(!write_jpegmem_gray(fPointer, 320, 240, &pglobal->in[plugin_number].buf, &outlen, 100)){ printf("compression error !\n"); exit(EXIT_FAILURE); } pglobal->in[plugin_number].size = outlen ; /* signal fresh_frame */ pthread_cond_broadcast(&pglobal->in[plugin_number].db_update); } pthread_mutex_unlock(&pglobal->in[plugin_number].db); } IPRINT("leaving input thread, calling cleanup function now\n"); pthread_cleanup_pop(1); return NULL; }
int tmpfs_fifo_read(void *v) { struct vop_read_args /* { struct vnode *a_vp; struct uio *a_uio; int a_ioflag; kauth_cred_t a_cred; } */ *ap = v; struct vnode *vp = ap->a_vp; VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_ACCESSED; return (fifo_read(v)); }
void test_normal(void) { for(uint32_t i=0; i < FIFO_SIZE; i++) { fifo_write(&ff_non_overwritable, &i); } for(uint32_t i=0; i < FIFO_SIZE; i++) { uint32_t c; fifo_read(&ff_non_overwritable, &c); TEST_ASSERT_EQUAL(i, c); } }
void test_circular(void) { FIFO_DEF(ff_overwritable, 2, uint32_t, true, 0); uint32_t data; // feed fifo to full data = 1; fifo_write(&ff_overwritable, &data); // 1 data = 2; fifo_write(&ff_overwritable, &data); // 2 // overflow data data = 100; fifo_write(&ff_overwritable, &data); //------------- 1st read should be 2, second is 100 -------------// fifo_read(&ff_overwritable, &data); TEST_ASSERT_EQUAL(2, data); fifo_read(&ff_overwritable, &data); TEST_ASSERT_EQUAL(100, data); }