本文整理汇总了C++中sem_post函数的典型用法代码示例。如果您正苦于以下问题:C++ sem_post函数的具体用法?C++ sem_post怎么用?C++ sem_post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sem_post函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: max11802_read
//.........这里部分代码省略.........
ierr("ERROR: Unsupported read size: %d\n", len);
return -ENOSYS;
}
/* Get exclusive access to the driver data structure */
ret = sem_wait(&priv->devsem);
if (ret < 0)
{
/* This should only happen if the wait was cancelled by an signal */
ierr("ERROR: sem_wait: %d\n", errno);
DEBUGASSERT(errno == EINTR);
return -EINTR;
}
/* Try to read sample data. */
ret = max11802_sample(priv, &sample);
if (ret < 0)
{
/* Sample data is not available now. We would ave to wait to get
* receive sample data. If the user has specified the O_NONBLOCK
* option, then just return an error.
*/
iinfo("Sample data is not available\n");
if (filep->f_oflags & O_NONBLOCK)
{
ret = -EAGAIN;
goto errout;
}
/* Wait for sample data */
ret = max11802_waitsample(priv, &sample);
if (ret < 0)
{
/* We might have been awakened by a signal */
ierr("ERROR: max11802_waitsample: %d\n", ret);
goto errout;
}
}
/* In any event, we now have sampled MAX11802 data that we can report
* to the caller.
*/
report = (FAR struct touch_sample_s *)buffer;
memset(report, 0, SIZEOF_TOUCH_SAMPLE_S(1));
report->npoints = 1;
report->point[0].id = sample.id;
report->point[0].x = sample.x;
report->point[0].y = sample.y;
/* Report the appropriate flags */
if (sample.contact == CONTACT_UP)
{
/* Pen is now up. Is the positional data valid? This is important to
* know because the release will be sent to the window based on its
* last positional data.
*/
if (sample.valid)
{
report->point[0].flags = TOUCH_UP | TOUCH_ID_VALID | TOUCH_POS_VALID;
}
else
{
report->point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
}
}
else if (sample.contact == CONTACT_DOWN)
{
/* First contact */
report->point[0].flags = TOUCH_DOWN | TOUCH_ID_VALID | TOUCH_POS_VALID;
}
else /* if (sample->contact == CONTACT_MOVE) */
{
/* Movement of the same contact */
report->point[0].flags = TOUCH_MOVE | TOUCH_ID_VALID | TOUCH_POS_VALID;
}
iinfo(" id: %d\n", report->point[0].id);
iinfo(" flags: %02x\n", report->point[0].flags);
iinfo(" x: %d\n", report->point[0].x);
iinfo(" y: %d\n", report->point[0].y);
ret = SIZEOF_TOUCH_SAMPLE_S(1);
errout:
sem_post(&priv->devsem);
iinfo("Returning: %d\n", ret);
return ret;
}
示例2: nxffs_write
//.........这里部分代码省略.........
int ret;
fvdbg("Write %d bytes to offset %d\n", buflen, filep->f_pos);
/* Sanity checks */
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
/* Recover the open file state from the struct file instance */
wrfile = (FAR struct nxffs_wrfile_s *)filep->f_priv;
/* Recover the volume state from the open file */
volume = (FAR struct nxffs_volume_s *)filep->f_inode->i_private;
DEBUGASSERT(volume != NULL);
/* Get exclusive access to the volume. Note that the volume exclsem
* protects the open file list.
*/
ret = sem_wait(&volume->exclsem);
if (ret != OK)
{
ret = -get_errno();
fdbg("ERROR: sem_wait failed: %d\n", ret);
goto errout;
}
/* Check if the file was opened with write access */
if ((wrfile->ofile.oflags & O_WROK) == 0)
{
fdbg("ERROR: File not open for write access\n");
ret = -EACCES;
goto errout_with_semaphore;
}
/* Loop until we successfully appended all of the data to the file (or an
* error occurs)
*/
for (total = 0; total < buflen; )
{
remaining = buflen - total;
/* Have we already allocated the data block? */
if (wrfile->doffset == 0)
{
/* No, allocate the data block now, re-packing if necessary. */
wrfile->datlen = 0;
ret = nxffs_wralloc(volume, wrfile, remaining);
if (ret < 0)
{
fdbg("ERROR: Failed to allocate a data block: %d\n", -ret);
goto errout_with_semaphore;
}
}
/* Seek to the FLASH block containing the data block */
nxffs_ioseek(volume, wrfile->doffset);
/* Verify that the FLASH data that was previously written is still intact */
ret = nxffs_reverify(volume, wrfile);
if (ret < 0)
{
fdbg("ERROR: Failed to verify FLASH data block: %d\n", -ret);
goto errout_with_semaphore;
}
/* Append the data to the end of the data block and write the updated
* block to flash.
*/
nwritten = nxffs_wrappend(volume, wrfile, &buffer[total], remaining);
if (nwritten < 0)
{
fdbg("ERROR: Failed to append to FLASH to a data block: %d\n", -ret);
goto errout_with_semaphore;
}
/* Decrement the number of bytes remaining to be written */
total += nwritten;
}
/* Success.. return the number of bytes written */
ret = total;
filep->f_pos = wrfile->datlen;
errout_with_semaphore:
sem_post(&volume->exclsem);
errout:
return ret;
}
示例3: p
/*
This is a simulation of the process diagram
on slide 38 module 06-Concurrency
*/
void * p( void * arg )
{
unsigned k , mynum ;
mynum = ( unsigned ) arg ;
pthread_detach( pthread_self() );
switch( mynum )
{
case 1:
printf("Thread %d started\n", mynum);
SPIN ;
printf("Thread %d ended\n", mynum);
sem_post( & s[1] /* or simply s+1 */ );
sem_post( s+1 );
sem_post( s+1 );
break ;
case 2:
sem_wait( s+1 ) ;
printf("Thread %d started\n", mynum);
SPIN ;
printf("Thread %d ended\n", mynum);
sem_post( s+2 );
sem_post( s+2 );
break ;
case 3:
sem_wait( s+2 ) ;
printf("Thread %d started\n", mynum);
SPIN ;
printf("Thread %d ended\n", mynum);
sem_post( s+3 );
break ;
case 4:
sem_wait( s+2 ) ;
printf("Thread %d started\n", mynum);
SPIN ;
printf("Thread %d ended\n", mynum);
sem_post( s+4 );
break ;
case 5:
sem_wait( s+1 ) ;
printf("Thread %d started\n", mynum);
SPIN ;
printf("Thread %d ended\n", mynum);
sem_post( s+5 );
break ;
case 6:
sem_wait( s+4 ) ;
sem_wait( s+5 ) ;
printf("Thread %d started\n", mynum);
SPIN ;
printf("Thread %d ended\n", mynum);
sem_post( s+6 );
break ;
case 7:
sem_wait( s+1 ) ;
printf("Thread %d started\n", mynum);
SPIN ;
printf("Thread %d ended\n", mynum);
sem_post( s+7 );
break ;
case 8:
sem_wait( s+3 ) ;
sem_wait( s+6 ) ;
sem_wait( s+7 ) ;
printf("Thread %d started\n", mynum);
SPIN ;
printf("Thread %d ended\n", mynum);
sem_post( s+8 );
break ;
};
pthread_exit( NULL ) ;
}
示例4: Audio_Callback2
DttSP_EXP void
Audio_Callback2 (float **input, float **output, unsigned int nframes)
{
unsigned int thread;
BOOLEAN b = reset_em;
BOOLEAN return_empty=FALSE;
unsigned int i;
for(thread=0;thread<threadno;thread++)
{
if (top[thread].susp) return_empty = TRUE;
}
if (return_empty)
{
for(thread=0;thread<threadno;thread++)
{
memset (output[2*thread], 0, nframes * sizeof (float));
memset (output[2*thread+1], 0, nframes * sizeof (float));
}
return;
}
if (b)
{
//fprintf(stderr, "reset_em!\n"); fflush(stderr);
//fprintf(stdout,"Audio_Callback2: reset_em = TRUE\n"), fflush(stdout);
reset_system_audio(nframes);
for(thread=0;thread<threadno;thread++) {
memset (output[2*thread], 0, nframes * sizeof (float));
memset (output[2*thread+1], 0, nframes * sizeof (float));
}
return;
}
#if 0
if (diversity.flag) {
// Deal with the transmitter first
if ((ringb_float_read_space (top[1].jack.ring.o.l) >= nframes)
&& (ringb_float_read_space (top[1].jack.ring.o.r) >= nframes))
{
ringb_float_read (top[1].jack.ring.o.l, output[2], nframes);
ringb_float_read (top[1].jack.ring.o.r, output[3], nframes);
}
else
{
// rb pathology
//reset_system_audio(nframes);
for(thread=0;thread<threadno;thread++)
{
memset (output[thread], 0, nframes * sizeof (float));
memset (output[thread], 0, nframes * sizeof (float));
}
return;
}
// input: copy from port to ring
if ((ringb_float_write_space (top[1].jack.ring.i.l) >= nframes)
&& (ringb_float_write_space (top[1].jack.ring.i.r) >= nframes))
{
ringb_float_write (top[1].jack.ring.i.l, input[2], nframes);
ringb_float_write (top[1].jack.ring.i.r, input[3], nframes);
}
else
{
// rb pathology
for(thread=0;thread<threadno;thread++)
{
memset (output[thread], 0, nframes * sizeof (float));
memset (output[thread], 0, nframes * sizeof (float));
}
return;
}
// if enough accumulated in ring, fire dsp
if ((ringb_float_read_space (top[1].jack.ring.i.l) >= top[1].hold.size.frames) &&
(ringb_float_read_space (top[1].jack.ring.i.r) >= top[1].hold.size.frames))
sem_post (&top[1].sync.buf.sem);
//
// Deal with the diversity channel next
//
if ((ringb_float_read_space (top[0].jack.ring.o.l) >= nframes)
&& (ringb_float_read_space (top[0].jack.ring.o.r) >= nframes))
{
/*ringb_float_read (top[thread].jack.auxr.o.l, output[l], nframes);
ringb_float_read (top[thread].jack.auxr.o.r, output[r], nframes);*/
ringb_float_read (top[0].jack.ring.o.l, output[2], nframes);
ringb_float_read (top[0].jack.ring.o.r, output[3], nframes);
}
else
{
// rb pathology
//reset_system_audio(nframes);
for(thread=0;thread<threadno;thread++)
{
memset (output[thread], 0, nframes * sizeof (float));
memset (output[thread], 0, nframes * sizeof (float));
}
return;
}
//.........这里部分代码省略.........
示例5: main
int main(int argc, char *argv[])
{
int n_elements = 61;
int n_processors = 10;
// First calculate how much work to give to each process.
// Really, this is just a dummy example. Each child will just
// do some meaningless calculations as an example.
int n_per_processor = n_elements / n_processors;
int n_remaining = n_elements % n_processors;
int node_start = 0;
int node_end;
printf("\n");
// Here we read the key for the shared memory. This will be availble
// to all clients so they can attach to shared memory.
// Remember, each child will inherit an exact copy of the stack and
// heap.
//
//
int shm_fd = shm_open("/wikastarea1", O_RDWR, 0755);
if (shm_fd < 0)
{
perror("shm_open");
exit(0);
}
void *mptr = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
MAP_SHARED, shm_fd, 0x0);
if (mptr == MAP_FAILED)
{
perror("mmap");
exit(0);
}
shdata_t *shdata = (shdata_t *) mptr;
sem_t *sem1 = sem_open("/wikassem1", 0);
if (sem1 == SEM_FAILED)
{
perror("sem_open sem1");
exit(0);
}
sem_t *sem2 = sem_open("/wikassem2", 0);
if (sem2 == SEM_FAILED)
{
perror("sem_open sem2");
exit(0);
}
int count = 0;
for (int i=0; i < 100; i++)
{
sem_wait(sem2);
printf("Damn! the pot is empty!\n");
for (int j=0; j < 10; j++)
{
shdata->values[j] = 1.0;
printf("producing %d\n", ++count);
}
sem_post(sem1);
}
}
示例6: get_mpeg2ts_segment
static gsize get_mpeg2ts_segment (RequestData *request_data, EncoderOutput *encoder_output, gchar **buf)
{
GstClockTime timestamp;
gint number;
guint64 year, month, mday, hour, sequence, duration, rap_addr, max_age;
GstClockTime us; /* microseconds */
struct tm tm;
gchar date[20], *header, *path, *file, *cache_control;
gsize buf_size;
GError *err = NULL;
struct timespec ts;
number = sscanf (request_data->uri, "/%*[^/]/encoder/%*[^/]/%04lu%02lu%02lu%02lu/%lu_%lu_%lu.ts$",
&year, &month, &mday, &hour, &us, &sequence, &duration);
if (number != 7) {
GST_WARNING ("uri not found: %s", request_data->uri);
*buf = g_strdup_printf (http_404, PACKAGE_NAME, PACKAGE_VERSION);
buf_size = strlen (*buf);
return buf_size;
}
sprintf (date, "%04lu-%02lu-%02lu %02lu:00:00", year, month, mday, hour);
memset (&tm, 0, sizeof (struct tm));
strptime (date, "%Y-%m-%d %H:%M:%S", &tm);
tm.tm_isdst = daylight;
timestamp = mktime (&tm) * 1000000 + us;
/* read from memory */
if (clock_gettime (CLOCK_REALTIME, &ts) == -1) {
GST_ERROR ("get_mpeg2ts_segment clock_gettime error: %s", g_strerror (errno));
*buf = g_strdup_printf (http_500, PACKAGE_NAME, PACKAGE_VERSION);
buf_size = strlen (*buf);
return buf_size;
}
ts.tv_sec += 2;
while (sem_timedwait (encoder_output->semaphore, &ts) == -1) {
if (errno == EINTR) {
continue;
}
GST_ERROR ("get_mpeg2ts_segment sem_timedwait failure: %s", g_strerror (errno));
*buf = g_strdup_printf (http_500, PACKAGE_NAME, PACKAGE_VERSION);
buf_size = strlen (*buf);
return buf_size;
}
/* seek gop */
rap_addr = encoder_output_gop_seek (encoder_output, timestamp);
if (rap_addr != G_MAXUINT64) {
/* segment found, send it */
gsize gop_size;
gop_size = encoder_output_gop_size (encoder_output, rap_addr);
cache_control = g_strdup_printf ("max-age=%lu", encoder_output->dvr_duration);
header = g_strdup_printf (http_200, PACKAGE_NAME, PACKAGE_VERSION, "video/mpeg", gop_size, cache_control, "");
g_free (cache_control);
*buf = g_malloc (strlen (header) + gop_size);
memcpy (*buf, header, strlen(header));
if (rap_addr + gop_size + 12 < encoder_output->cache_size) {
memcpy (*buf + strlen (header), encoder_output->cache_addr + rap_addr + 12, gop_size);
} else {
gint n;
n = encoder_output->cache_size - rap_addr - 12;
if (n > 0) {
memcpy (*buf + strlen (header), encoder_output->cache_addr + rap_addr + 12, n);
memcpy (*buf + strlen (header) + n, encoder_output->cache_addr, gop_size - n);
} else {
GST_WARNING ("nnnnn: n < 0 %d", n);
memcpy (*buf + strlen (header), encoder_output->cache_addr - n, gop_size);
}
}
buf_size = strlen (header) + gop_size;
g_free (header);
} else {
buf_size = 0;
}
sem_post (encoder_output->semaphore);
/* buf_size == 0? segment not found in memory, read frome dvr directory */
if (buf_size == 0) {
path = g_strdup_printf ("%s/%04lu%02lu%02lu%02lu/%010lu_%lu_%lu.ts",
encoder_output->record_path,
year, month, mday, hour, us, sequence, duration);
if (!g_file_get_contents (path, &file, &buf_size, &err)) {
g_error_free (err);
GST_WARNING ("segment not found: %s", request_data->uri);
*buf = g_strdup_printf (http_404, PACKAGE_NAME, PACKAGE_VERSION);
buf_size = strlen (*buf);
} else {
max_age = encoder_output->dvr_duration - (g_get_real_time () - timestamp) / 1000000;
cache_control = g_strdup_printf ("max-age=%lu", max_age);
header = g_strdup_printf (http_200,
PACKAGE_NAME,
PACKAGE_VERSION,
"video/mpeg",
buf_size,
cache_control,
"");
//.........这里部分代码省略.........
示例7: reinit_signal_handler
// Serves as a global method to trigger reinitialization
// and as a function that can be provided to signal().
void reinit_signal_handler(int /*signal*/) {
sem_post(&reinit);
}
示例8: service_engine
int service_engine(char *addr, int port)
{
int i;
if(MAX_TASK_NUM > 0)
{
for (i = 0; i < MAX_TASK_NUM; i++)
{
sem_init(&event[i], 0, 0);
int temp = i;
if (pthread_create(&thread_id[i], NULL, (void *)handle_requests, (void *)temp) != 0)
{
printf("pthread_create error, %s:%d\n",__FILE__, __LINE__);
exit(-1);
}
}
}
/*
* command line console
*/
init_mdb();
ServiceHandler h = -1;
initialize_service(addr,port);
while(1)
{
h = service_start();
// handle_request(h);
task_node_t *tnode = (task_node_t *)malloc( sizeof(task_node_t));
tnode->buf_size = MAX_BUF_LEN;
if (receive_data (h, tnode->buf, &(tnode->buf_size)) == 0)
{
service_stop(h);
continue;
}
if (MAX_TASK_NUM > 0)
{
tnode->req = h;
int i = random_int(MAX_TASK_NUM);
/* put tnode into task_list */
if (task_list[i] == NULL)
{
task_list[i] = tnode;
tnode->next = NULL;
tnode->last = tnode;
}
else
{
task_node_t *p = task_list[i];
p->last->next = tnode;
p->last = tnode;
tnode->next = NULL;
}
sem_post(&event[i]);
// service_stop(h);
}
else
{
handle_one_request(h, tnode->buf, tnode->buf_size);
free(tnode);
}
}
shutdown_service();
close_mdb();
if (MAX_TASK_NUM > 0 )
{
for (i = 0; i< MAX_TASK_NUM; i++)
{
task_node_t *p = task_list[i];
task_node_t *q;
while (p)
{
q = p->next;
free(p);
p = q;
}
}
}
return 0;
}
示例9: threadfunc
void threadfunc()
{
printf("Hello from threadfunc!\n");
sleep(3);
sem_post(&g_sema);
}
示例10: readDone
virtual void readDone(uint32_t v) {
fprintf(stderr, "readDone %d\n", v);
sem_post(&read_sem);
}
示例11: atender_peticion_orquestador
/*
* La cola RR solo la agregamos por compatibilidad,
* siempre va a ser un puntero a NULL.
*/
uint32_t atender_peticion_orquestador(uint32_t cliente, t_stream *pedido, t_queue_rr *cola_rr){
/*t_stream *pedido;
recibir(cliente, (void*)&pedido);
*/
t_header header;
deserializar_header(pedido, &header);
int32_t pos_payload = sizeof(t_header);
//char personajeElegido;
switch (header.type){
case HANDSHAKE_NUEVO_NIVEL:{
uint32_t nro_nivel;
uint32_t puerto;
t_stream *payload = get_payload(pedido);
memcpy(&nro_nivel,&payload[0],4);
memcpy(&puerto,&payload[4],4);
t_planificador *nodo_planificador;
nodo_planificador = get_nodo_nivel(nro_nivel);
//log_debug(logger_orq, "Hand_nuevo_nivel: dir nodo_planificador = %d", nodo_planificador);
if(nodo_planificador == NULL){
nodo_planificador = malloc(sizeof(t_planificador));
nodo_planificador->tid=malloc(sizeof(pthread_t));
nodo_planificador->nivel.direccion = malloc(sizeof(struct sockaddr_in));
log_info(logger_orq, "Handshake_nuevo_nivel: Nueva conexión, nivel %d.", nro_nivel);
completar_datos_nivel(nro_nivel, cliente, nodo_planificador);
nodo_planificador->planificador.descriptor = 0;
(nodo_planificador->nivel.direccion)->sin_port=htons(puerto);
list_mutex_add(planificadores, (void*) nodo_planificador);
sem_post(&semaforo_nodos_nuevos);
free(pedido);
return EXIT_SUCCESS;
}
log_info(logger_orq, "Se reconecta en nivel %d.", nro_nivel);
completar_datos_nivel(nro_nivel, cliente, nodo_planificador);
(nodo_planificador->nivel.direccion)->sin_port=htons(puerto);
free(pedido);
return EXIT_SUCCESS;
}
case HANDSHAKE_NUEVO_PJ:{
int8_t simbolo_pj;
t_stream *payload =get_payload(pedido);
simbolo_pj = (int8_t)payload[0];
log_info(logger_orq, "Handshake_nuevo_pj: Nueva conexión, pj %c", simbolo_pj);
t_personaje_finalizado *pj;
int pos_pj;
pos_pj = get_pos_pj_finalizado(simbolo_pj);
//Si todavía no está en la lista lo metemos.
if(pos_pj == -1){
log_debug(logger_orq, "Handshake_nuevo_pj: El pj no existía así que lo guardo en listo personajes_finalizados.");
pj = malloc(sizeof(t_personaje_finalizado));
pj->simbolo_pj = simbolo_pj;
pj->termino_plan_de_niveles = false;
log_debug(logger_orq, "Handshake_nuevo_pj: Guardo: Simbolo = %c bool_fin = %d", pj->simbolo_pj, pj->termino_plan_de_niveles);
list_mutex_add(personajes_finalizados, (void*)pj);
t_personaje_finalizado *test_pj = list_mutex_get(personajes_finalizados, 0);
log_debug(logger_orq,"Handshake_nuevo_pj: Guardé simbolo = %c, bool_fin = %d ", test_pj->simbolo_pj, test_pj->termino_plan_de_niveles);
}
else{
pthread_mutex_lock(&personajes_finalizados->mutex);
pj = list_get(personajes_finalizados->list, pos_pj);
pj->termino_plan_de_niveles = false;
pthread_mutex_unlock(&personajes_finalizados->mutex);
}
t_stream *stream_senial_ok;
stream_senial_ok = serializar_senial(OK);
log_debug(logger_orq, "Handshake_nuevo_pj: Envío OK al pj recién conectado");
enviar(cliente, stream_senial_ok);
free(stream_senial_ok);
free(pedido);
return EXIT_SUCCESS;
}
case SOLICITUD_DATOS_NIVEL:{
t_stream *payload = get_payload(pedido);
int8_t simbolo_pj = payload[0];
int8_t nro_nivel = payload[1];
t_datos_nivel datos_nivel;
datos_nivel.direccion_nivel[0] = '\0';
datos_nivel.direccion_planificador[0]='\0';
int resultado = get_datos_nivel(nro_nivel, &datos_nivel);
//Si el nivel no existe o si todavía no se lanzó su planificador asociado.
if(resultado == EXIT_FAILURE){
char cadena_vacia = 'a';
t_stream *stream_nivel_no_existe = serializar_solicitud(NO_EXISTE_EL_NIVEL, sizeof(cadena_vacia), (t_stream*)&cadena_vacia);
//.........这里部分代码省略.........
示例12: writeDone
virtual void writeDone(uint32_t v) {
fprintf(stderr, "writeDone %d\n", v);
sem_post(&write_sem);
}
示例13: cgi_semgive
static inline void cgi_semgive(void)
{
sem_post(&g_cgisem);
}
示例14: bscanGet
virtual void bscanGet(uint64_t v) {
printf("bscanGet: %llx\n", (long long)v);
sem_post(&sem_bscan);
}
示例15: process_callback
static int process_callback( jack_nframes_t nframes, void *arg )
{
int c;
jack_handle_t* handle = (jack_handle_t*)arg;
size_t to_read = nframes;
for(c=0; c<handle->channels; ++c)
handle->ports_buf[c] =
jack_port_get_buffer(handle->ports[c], nframes);
/* One ringbuffer to rule them all, getting interleaved data piecewise
and appending to non-interleaved buffers. */
while(to_read)
{
/* Need to read into temporary storage, then deinterleave to JACK
buffers. */
size_t got_piece;
size_t avail_piece;
size_t piece = to_read > handle->procbuf_frames
? handle->procbuf_frames
: to_read;
/* Ensure we get only full PCM frames by checking available byte count
and reducing expectation. */
avail_piece = jack_ringbuffer_read_space(handle->rb)/handle->framesize;
got_piece = jack_ringbuffer_read( handle->rb
, handle->procbuf, (avail_piece > piece ? piece : avail_piece)
* handle->framesize ) / handle->framesize;
debug2( "fetched %"SIZE_P" frames from ringbuffer (wanted %"SIZE_P")"
, (size_p)got_piece, (size_p)piece );
/* If this is the last piece, fill up, not time to wait. */
if(to_read > piece)
piece = got_piece; /* We got further loop cycle(s) to get the rest. */
else
{
if(piece > got_piece)
{
debug("filling up with zeros");
bzero( handle->procbuf+got_piece*handle->framesize
, (piece-got_piece)*handle->framesize );
}
}
/* Now extract the pieces for the channels. */
for (c=0; c < handle->channels; ++c)
{
size_t n;
jack_default_audio_sample_t *dst = handle->ports_buf[c];
if(handle->encoding == MPG123_ENC_FLOAT_32)
{
float* src = (float*)handle->procbuf;
for(n=0; n<piece; ++n)
*(dst++) = src[(n*handle->channels)+c];
}
else /* MPG123_ENC_FLOAT_64 */
{
double* src = (double*)handle->procbuf;
for(n=0; n<piece; ++n)
*(dst++) = src[(n*handle->channels)+c];
}
/* Store output buffer offset. */
handle->ports_buf[c] = dst;
}
/* Give the writer a hint about the time passed. */
sem_post(&handle->sem);
to_read -= piece;
}
/* Success*/
return 0;
}