static int remoteMouseHandler(mwlirc_keystroke * event, MWKEY * kbuf, MWSCANCODE * pscancode) { unsigned speed; unsigned dir; int len = 0; if ((sscanf(event->name, "m_%u_%u%n", &speed, &dir, &len) < 2) || (len != strlen(event->name)) || (dir > 15) || (speed > 15)) { EPRINTF("LIRC_Read() - Invalid mouse event '%s'\n", event->name); return 0; } return LIRC_mouseMovedPolar(speed, dir); }
void GsSelect (GR_TIMEOUT timeout) { struct MW_UID_MESSAGE m; int rc; /* perform pre-select duties, if any*/ if (scrdev.PreSelect) scrdev.PreSelect (&scrdev); /* let's make sure that the type is invalid */ m.type = MV_UID_INVALID; /* wait up for events */ rc = uid_read_message (&m, timeout); /* return if timed-out or something went wrong */ if (rc < 0) { if (errno != ETIMEDOUT) EPRINTF (" rc= %d, errno=%d\n", rc, errno); else { /* timeout handling */ } return; } /* let's pass the event up to Microwindows */ switch (m.type) { case MV_UID_REL_POS: /* Mouse or Touch Screen event */ case MV_UID_ABS_POS: m_mou = m; while (GsCheckMouseEvent ()) continue; break; case MV_UID_KBD: /* KBD event */ m_kbd = m; GsCheckKeyboardEvent (); break; case MV_UID_TIMER: /* Microwindows does nothing with these.. */ case MV_UID_INVALID: default: break; } }
void td_metrics_stop() { if (!td_metrics.path) goto out; empty_folder(td_metrics.path); if (rmdir(td_metrics.path) == -1){ EPRINTF("failed to delete metrics folder: %s\n", strerror(errno)); goto out; } free(td_metrics.path); td_metrics.path = NULL; out: return; }
int td_metrics_nbd_stop(stats_t *nbd_stats) { int err = 0; if(!nbd_stats->shm.path) goto end; err = shm_destroy(&nbd_stats->shm); if (unlikely(err)) { err = errno; EPRINTF("failed to destroy NBD metrics file: %s\n", strerror(err)); } free(nbd_stats->shm.path); nbd_stats->shm.path = NULL; end: return err; }
static int vbd_stats_destroy(td_vbd_t *vbd) { int err = 0; ASSERT(vbd); err = shm_destroy(&vbd->rrd.shm); if (unlikely(err)) { EPRINTF("failed to destroy RRD file: %s\n", strerror(err)); goto out; } free(vbd->rrd.shm.path); vbd->rrd.shm.path = NULL; out: return -err; }
// allocate and a Stream and associate it with a suitable device. // static Stream *Stream_new(int dir) { AudioDeviceID id= 0; Stream *s= 0; if (!getDefaultDevice(&id, dir)) return 0; // no device available if (!(s= (Stream *)calloc(1, sizeof(Stream)))) { EPRINTF("out of memory"); return 0; } s->id= id; s->direction= dir; DPRINTF("stream %p[%d] created for device %ld\n", s, dir, id); return s; }
void fb_io_device::display_thread (void) { int func_ret = 0; while(1) { wait (m_ev_display); //printf ("display()\n"); /* if DMA in use */ /* retrieve data */ if (m_regs->m_dmaen) { uint32_t offset; uint32_t addr = m_regs->m_buf_addr; uint8_t *data = m_io_res->mem; for (offset = 0; offset < m_io_res->mem_size; offset += 4) { func_ret = master->cmd_read (addr + offset, data + offset, 4); if (!func_ret) break; } if (!func_ret) EPRINTF ("Error in Read\n"); else DPRINTF ("Transfer complete\n"); } kill (m_pid, SIGUSR1); if (m_regs->m_dmaen) { m_regs->m_irqstat |= FB_IO_IRQ_DMA; m_ev_irq_update.notify (); } } }
bool Pong::execute() { /* Read the pong message and output the count. */ if(false == m_ping_subscription->get()) { EPRINTF("Error retreiving ping data\n"); } if(m_ping_subscription->was_updated()) { IPRINTF("Pong gets %u from ping\n", m_ping_subscription->content.count); } /* Increment and publish the pong count. */ ++m_pong_publication->content.count; IPRINTF("Pong puts %u\n", m_pong_publication->content.count); m_pong_publication->put(); return true; }
static int PD_Open(MOUSEDEVICE * pmd) { /* * open up the touch-panel device. * Return the fd if successful, or negative if unsuccessful. */ if ((pd_fd = open(DEVICE, O_NONBLOCK)) < 0) { EPRINTF("Error %d opening touch panel\n", errno); return -1; } /* This is the default transform for this device */ /* We set it here, so that the system will come up normally */ GdSetTransform(&default_transform); /* This should normally be disabled, but we leave it on for debugging */ /*GdHideCursor(&scrdev);*/ return pd_fd; }
int td_metrics_blktap_stop(stats_t *blktap_stats) { int err = 0; if(!blktap_stats->shm.path) goto end; err = shm_destroy(&blktap_stats->shm); if (unlikely(err)) { err = errno; EPRINTF("failed to destroy blktap metrics file: %s\n", strerror(err)); } free(blktap_stats->shm.path); blktap_stats->shm.path = NULL; end: return err; }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ JNIEXPORT void JNICALL Java_com_qualcomm_fastcvdemo_utils_FastCVSampleRenderer_render ( JNIEnv * env, jobject obj, jbyteArray img, jint w, jint h ) { if( state.cameraRenderer == NULL ) { state.cameraRenderer = new CameraRendererRGB565GL2(); if (state.cameraRenderer) { state.cameraRenderer->Init(); } else { EPRINTF( "Unable to get Camera Render object\n" ); } } //if camera frame is ready, display that if( state.cameraRenderer && state.renderBufRGB565 ) { lockRenderBuffer(); state.cameraRenderer->Render ( state.renderBufRGB565, state.renderBufWidth, state.renderBufHeight ); unlockRenderBuffer(); //glFlush(); glFinish(); } }
int tap_ctl_write_message(int fd, tapdisk_message_t * message, struct timeval *timeout) { fd_set writefds; int ret, len, offset; offset = 0; len = sizeof(tapdisk_message_t); DBG("sending '%s' message (uuid = %u)\n", tapdisk_message_name(message->type), message->cookie); while (offset < len) { FD_ZERO(&writefds); FD_SET(fd, &writefds); /* we don't bother reinitializing tv. at worst, it will wait a * bit more time than expected. */ ret = select(fd + 1, NULL, &writefds, NULL, timeout); if (ret == -1) break; else if (FD_ISSET(fd, &writefds)) { ret = write(fd, message + offset, len - offset); if (ret <= 0) break; offset += ret; } else break; } if (offset != len) { EPRINTF("failure writing message\n"); return -EIO; } return 0; }
td_vbd_t* tapdisk_vbd_create(uint16_t uuid) { td_vbd_t *vbd; int i; vbd = calloc(1, sizeof(td_vbd_t)); if (!vbd) { EPRINTF("failed to allocate tapdisk state\n"); return NULL; } vbd->uuid = uuid; vbd->minor = -1; vbd->ring.fd = -1; /* default blktap ring completion */ vbd->callback = tapdisk_vbd_callback; vbd->argument = vbd; #ifdef MEMSHR memshr_vbd_initialize(); #endif INIT_LIST_HEAD(&vbd->driver_stack); INIT_LIST_HEAD(&vbd->images); INIT_LIST_HEAD(&vbd->new_requests); INIT_LIST_HEAD(&vbd->pending_requests); INIT_LIST_HEAD(&vbd->failed_requests); INIT_LIST_HEAD(&vbd->completed_requests); INIT_LIST_HEAD(&vbd->next); gettimeofday(&vbd->ts, NULL); for (i = 0; i < MAX_REQUESTS; i++) tapdisk_vbd_initialize_vreq(vbd->request_list + i); return vbd; }
bool Task::spawn_thread() { Scheduler &sched = Scheduler::get_instance(); /* If rategroup_sync is not NULL at this point, then the task has been * started previously and is already on the scheduler's list. */ if(NULL != m_impl->rategroup_sync) { m_impl->first_pass = true; } else if(m_props.period && (this != &sched)) { m_impl->rategroup_sync = sched.add_task(*this); if(NULL == m_impl->rategroup_sync) { return false; } } /* Spawn the thread. */ m_thread_syncpoint.lock(); m_thread_syncpoint.condition_cleared(); if(pthread_create(&(m_impl->tid), &(m_impl->attr), run, reinterpret_cast<void *>(this)) != 0) { m_thread_syncpoint.unlock(); EPRINTF("%s: Failed to spawn thread\n", m_name); return false; } /* We can't get the mutex back until the thread has released it. This * makes sure the the thread has completed it's initilization before * returning and allowing additional threads to be spawned. */ m_thread_syncpoint.condition_cleared(); m_thread_syncpoint.wait(); m_thread_syncpoint.unlock(); return true; }
static int PD_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb) { struct ts_sample samp; int ret; ret = ts_read(ts, &samp, 1); if (ret <= 0) { if (errno == EINTR || errno == EAGAIN) return 0; EPRINTF("Error reading from touchscreen: %s\n", strerror(errno)); return -1; } *px = samp.x; *py = samp.y; *pb = (samp.pressure) ? MWBUTTON_L : 0; *pz = samp.pressure; if(!*pb) return 3; return 2; }
td_vbd_t* tapdisk_vbd_create(uint16_t uuid) { td_vbd_t *vbd; vbd = calloc(1, sizeof(td_vbd_t)); if (!vbd) { EPRINTF("failed to allocate tapdisk state\n"); return NULL; } vbd->uuid = uuid; INIT_LIST_HEAD(&vbd->images); INIT_LIST_HEAD(&vbd->new_requests); INIT_LIST_HEAD(&vbd->pending_requests); INIT_LIST_HEAD(&vbd->failed_requests); INIT_LIST_HEAD(&vbd->completed_requests); INIT_LIST_HEAD(&vbd->next); tapdisk_vbd_mark_progress(vbd); return vbd; }
int tap_ctl_connect_xenblkif(const pid_t pid, const domid_t domid, const int devid, int poll_duration, int poll_idle_threshold, const grant_ref_t * grefs, const int order, const evtchn_port_t port, int proto, const char *pool, const int minor) { tapdisk_message_t message; int i, err; memset(&message, 0, sizeof(message)); message.type = TAPDISK_MESSAGE_XENBLKIF_CONNECT; message.cookie = minor; message.u.blkif.domid = domid; message.u.blkif.devid = devid; for (i = 0; i < 1 << order; i++) message.u.blkif.gref[i] = grefs[i]; message.u.blkif.order = order; message.u.blkif.port = port; message.u.blkif.proto = proto; message.u.blkif.poll_duration = poll_duration; message.u.blkif.poll_idle_threshold = poll_idle_threshold; if (pool) strncpy(message.u.blkif.pool, pool, sizeof(message.u.blkif.pool)); else message.u.blkif.pool[0] = 0; err = tap_ctl_connect_send_and_receive(pid, &message, NULL); if (err || message.type == TAPDISK_MESSAGE_ERROR) { if (!err) err = -message.u.response.error; if (err == -EALREADY) EPRINTF("failed to connect tapdisk[%d] to the ring: %s\n", pid, strerror(-err)); } return err; }
void *thread_sample(void *arg) { char buffer[1024]; struct timespec ts; double period = 300; size_t size; int i; int rc; test_set_priority(pthread_self(), SCHED_FIFO, 5); DPRINTF(stderr, "Thread Sampler: started\n"); DPRINTF(stdout, "# COLUMNS %d Time TL TP ", 2 + cpus); for (i = 0; i < (cpus - 1); i++) DPRINTF(stdout, "TF%d ", i); DPRINTF(stdout, "\n"); ts.tv_sec = 0; ts.tv_nsec = period * 1000 * 1000; while (!ts_stop) { size = snprintf(buffer, 1023, "%f ", seconds_read() - base_time); for (i = 0; i < cpus + 1; i++) size += snprintf(buffer + size, 1023 - size, "%u ", tp[i].progress); DPRINTF(stdout, "%s\n", buffer); rc = nanosleep(&ts, NULL); if (rc < 0) EPRINTF("UNRESOLVED: Thread %s %d: nanosleep returned " "%d %s", tp->name, tp->index, rc, strerror(rc)); } return NULL; }
int tap_ctl_pause(const int id, const int minor, struct timeval *timeout) { int err; tapdisk_message_t message; memset(&message, 0, sizeof(message)); message.type = TAPDISK_MESSAGE_PAUSE; message.cookie = minor; err = tap_ctl_connect_send_and_receive(id, &message, timeout); if (err) return err; if (message.type == TAPDISK_MESSAGE_PAUSE_RSP) err = message.u.response.error; else { err = EINVAL; EPRINTF("got unexpected result '%s' from %d\n", tapdisk_message_name(message.type), id); } return err; }
int _start(int argc, const char **argv) { int state; shutdown(); if (RegisterLibraryEntries(&_exp_sio2man) != 0) return 1; if (init) return 1; init = 1; sio2_ctrl_set(0x3bc); cb1 = NULL; cb2 = NULL; cb3 = NULL; cb4 = NULL; event_flag = create_event_flag(); thid = create_main_thread(); CpuSuspendIntr(&state); RegisterIntrHandler(IOP_IRQ_SIO2, 1, sio2_intr_handler, &event_flag); EnableIntr(IOP_IRQ_SIO2); CpuResumeIntr(state); dmac_ch_set_dpcr(IOP_DMAC_SIO2in, 3); dmac_ch_set_dpcr(IOP_DMAC_SIO2out, 3); dmac_enable(IOP_DMAC_SIO2in); dmac_enable(IOP_DMAC_SIO2out); StartThread(thid, NULL); #ifndef XSIO2MAN EPRINTF("Logging started.\n"); #endif return 0; }
/* * This is used to drop a client when it is detected that the connection to it * has been lost. */ void GsDropClient(int fd) { GR_CLIENT *client; if((client = GsFindClient(fd))) { /* If it exists */ #if !HELLOOS close(fd); /* Close the socket */ #else #if !NONETWORK bucket_close(fd); #endif #endif GsDestroyClientResources(client); if(client == root_client) root_client = client->next; /* Link the prev to the next */ if(client->prev) client->prev->next = client->next; /* Link the next to the prev */ if(client->next) client->next->prev = client->prev; #if HAVE_SHAREDMEM_SUPPORT if ( client->shm_cmds != 0 ) { /* Free shared memory */ shmctl(client->shm_cmds_shmid,IPC_RMID,0); shmdt(client->shm_cmds); } #endif GsPrintResources(); free(client); /* Free the structure */ clipwp = NULL; /* reset clip window*/ --connectcount; } else EPRINTF("nano-X: trying to drop non-existent client %d.\n", fd); }
static void GrNotImplementedWrapper(void *r) { EPRINTF("nano-X: Function %s() not implemented\n", curfunc); }
/* Flush request buffer if required, possibly reallocate buffer size*/ void nxFlushReq(long newsize, int reply_needed) { ACCESS_PER_THREAD_DATA(); LOCK(&nxGlobalLock); /* handle one-time initialization case*/ if(reqbuf.buffer == NULL) { nxAllocReqbuffer(newsize); UNLOCK(&nxGlobalLock); return; } /* flush buffer if required*/ if(reqbuf.bufptr > reqbuf.buffer) { char * buf = (char*)reqbuf.buffer; int todo = reqbuf.bufptr - reqbuf.buffer; #if HAVE_SHAREDMEM_SUPPORT if ( nxSharedMem != 0 ) { /* There is a shared memory segment used for the * request buffer. Make up a flush command and * send it over the socket, to tell the server to * process the shared memory segment. * The 'reply_needed' argument should be non-zero * when a confirmation is needed that all commands * are flushed, so new ones can be filled into the * request buffer. NOTE: This is *only* needed * when explicitely flushing the request buffer, or * when flushing it to make space for new commands. * DO NOT REQUEST A REPLY when flushing the request * buffer because the last command in the buffer * will send a response: This response would be * queued up first and had to be drained before the * response to the flush command itsel.... * So the GrReadBlock used to read replys to commands * must not specify a nonzero 'reply_needed'. * Not requesting a reply in this case is * safe, since the command executed will wait for * the reply *it* is waiting for, and thus make * sure the request buffer is flushed before * continuing. * * We have to make the protocol request by hand, * as it has to be sent over the socket to wake * up the Nano-X server. */ char c; nxShmCmdsFlushReq req; req.reqType = GrNumShmCmdsFlush; req.hilength = 0; req.length = sizeof(req); req.size = todo; req.reply = reply_needed; nxWriteSocket((char *)&req,sizeof(req)); if ( reply_needed ) #if !HELLOOS while ( read(nxSocket, &c, 1) != 1 ) ; #else while ( bucket_recv(nxSocket, &c, 1) != 1 ) ; #endif reqbuf.bufptr = reqbuf.buffer; if ( reqbuf.buffer + newsize > reqbuf.bufmax ) { /* Shared memory too small, critical */ EPRINTF("nxFlushReq: shm region too small\n"); exit(1); } UNLOCK(&nxGlobalLock); return; } #endif /* HAVE_SHAREDMEM_SUPPORT*/ /* Standard Socket transfer */ nxWriteSocket(buf,todo); reqbuf.bufptr = reqbuf.buffer; } /* allocate larger buffer for current request, if needed*/ if(reqbuf.bufptr + newsize >= reqbuf.bufmax) { reqbuf.buffer = GdRealloc(reqbuf.buffer, reqbuf.bufmax - reqbuf.buffer, newsize); if(!reqbuf.buffer) { EPRINTF("nxFlushReq: Can't reallocate request buffer\n"); exit(1); } reqbuf.bufptr = reqbuf.buffer; reqbuf.bufmax = reqbuf.buffer + newsize; } UNLOCK(&nxGlobalLock); }
/* init framebuffer*/ static PSD fb_open(PSD psd) { PSUBDRIVER subdriver; char* fb=qvfb_connect(); diag_printf("******** fb is %p\n", fb); if (fb==NULL) goto fail; // diag_printf("DISPLAY=%s\n", cyg_hal_sys_getenv("DISPLAY")); assert(status < 2); psd->xres = psd->xvirtres = qvfb_width(); psd->yres = psd->yvirtres = qvfb_height(); /* set planes from fb type*/ psd->planes = 1; /* FIXME */ psd->bpp = qvfb_depth(); psd->ncolors = (psd->bpp >= 24)? (1 << 24): (1 << psd->bpp); /* set linelen to byte length, possibly converted later*/ psd->linelen = qvfb_linestep(); psd->size = 0; /* force subdriver init of size*/ psd->flags = PSF_SCREEN | PSF_HAVEBLIT; if (psd->bpp == 16) psd->flags |= PSF_HAVEOP_COPY; /* set pixel format*/ switch (psd->bpp) { case 32: psd->pixtype = MWPF_TRUECOLOR0888; break; case 16: psd->pixtype = MWPF_TRUECOLOR565; break; default: EPRINTF("Unsupported display type: %d\n", psd->bpp); goto fail; } diag_printf("%dx%dx%d linelen %d bpp %d\n", psd->xres, psd->yres, psd->ncolors, psd->linelen, psd->bpp); /* select a framebuffer subdriver based on planes and bpp*/ subdriver = select_fb_subdriver(psd); if (!subdriver) { EPRINTF("No driver for screen\n", psd->bpp); goto fail; } /* * set and initialize subdriver into screen driver * psd->size is calculated by subdriver init */ if(!set_subdriver(psd, subdriver, TRUE)) { EPRINTF("Driver initialize failed\n", psd->bpp); goto fail; } /* mmap framebuffer into this address space*/ psd->addr = fb; if(psd->addr == NULL || psd->addr == (unsigned char *)-1) { // EPRINTF("Error mmaping %s: %m\n", env); goto fail; } status = 2; return psd; /* success*/ fail: return NULL; }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ bool CameraRendererRGB565GL2::Render ( const uint8_t* img, uint16_t w, uint16_t h ) { if(w != mWidth || h != mHeight ) { mWidth = w; mHeight = h; UnInit(); } if(!mInitialized && !Init()) { EPRINTF("CameraRenderer::Initialize FAILED"); return false; } if(NULL == img) { EPRINTF("NULL Image Buffer. Can't render camera image."); return false; } mFPSCounter.FrameTick(); //Make sure that previous OpenGL Error have been cleaned. glGetError(); // needed for unity compatiblity glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); //Unity does not unbind these buffers before we are called, so we have to do so. //This should shouldn't have an effect on other rendering solutions as long as //the programmer is binding these buffers properly glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glUseProgram(mProgramObject); CameraUtil::checkGlError("glUseProgram"); // Load vertex data glVertexAttribPointer( mGL_av4_PositionLoc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), mVertices ); CameraUtil::checkGlError("glVertexAttribPointer"); glVertexAttribPointer( mGL_av2_TexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), &mVertices[3] ); CameraUtil::checkGlError("glVertexAttribPointer"); glEnableVertexAttribArray( mGL_av4_PositionLoc ); glEnableVertexAttribArray( mGL_av2_TexCoordLoc ); //Update Texture Image. UpdateTextures(img, w, h); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, mTextureId[0] ); if(CameraUtil::checkGlError("glBindTexture-RGB")){} glUniform1i( mGL_u_ImgRGBLoc, 0); glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ); CameraUtil::checkGlError("glDrawArrays"); glDisableVertexAttribArray( mGL_av4_PositionLoc ); glDisableVertexAttribArray( mGL_av2_TexCoordLoc ); return true; }
/* * return a relative path from @from to @to * result should be freed */ char * relative_path_to(char *from, char *to, int *err) { int from_nodes, common; char *to_absolute, *from_absolute; char *up, *common_target_path, *relative_path; *err = 0; up = NULL; to_absolute = NULL; from_absolute = NULL; relative_path = NULL; if (strnlen(to, MAX_NAME_LEN) == MAX_NAME_LEN || strnlen(from, MAX_NAME_LEN) == MAX_NAME_LEN) { EPRINTF("invalid input; max path length is %d\n", MAX_NAME_LEN); *err = -ENAMETOOLONG; return NULL; } to_absolute = realpath(to, NULL); if (!to_absolute) { EPRINTF("failed to get absolute path of %s\n", to); *err = -errno; goto out; } from_absolute = realpath(from, NULL); if (!from_absolute) { EPRINTF("failed to get absolute path of %s\n", from); *err = -errno; goto out; } if (strnlen(to_absolute, MAX_NAME_LEN) == MAX_NAME_LEN || strnlen(from_absolute, MAX_NAME_LEN) == MAX_NAME_LEN) { EPRINTF("invalid input; max path length is %d\n", MAX_NAME_LEN); *err = -ENAMETOOLONG; goto out; } /* count nodes in source path */ from_nodes = count_nodes(from_absolute); /* count nodes in common */ common = count_common_nodes(to_absolute + 1, from_absolute + 1); if (common < 0) { EPRINTF("failed to count common nodes of %s and %s: %d\n", to_absolute, from_absolute, common); *err = common; goto out; } /* move up to common node */ up = up_nodes(from_nodes - common - 1); if (!up) { EPRINTF("failed to allocate relative path for %s: %d\n", from_absolute, -ENOMEM); *err = -ENOMEM; goto out; } /* get path from common node to target */ common_target_path = node_offset(to_absolute, common + 1); if (!common_target_path) { EPRINTF("failed to find common target path to %s: %d\n", to_absolute, -EINVAL); *err = -EINVAL; goto out; } /* get relative path */ if (asprintf(&relative_path, "%s%s", up, common_target_path) == -1) { EPRINTF("failed to construct final path %s%s: %d\n", up, common_target_path, -ENOMEM); relative_path = NULL; *err = -ENOMEM; goto out; } out: sfree(up); sfree(to_absolute); sfree(from_absolute); return relative_path; }
int main(int argc, char **argv) { pthread_mutexattr_t mutex_attr; pthread_attr_t threadattr; pthread_t threads[cpus - 1], threadsample, threadtp, threadtl, threadtb; time_t multiplier = 1; int i; int rc; test_set_priority(pthread_self(), SCHED_FIFO, 6); base_time = seconds_read(); cpus = sysconf(_SC_NPROCESSORS_ONLN); /* Initialize a mutex with PTHREAD_PRIO_INHERIT protocol */ mutex_attr_init(&mutex_attr); mutex_init(&mutex, &mutex_attr); /* Initialize thread attr */ threadattr_init(&threadattr); /* Start the sample thread */ DPRINTF(stderr, "Main Thread: Creating sample thread\n"); rc = pthread_create(&threadsample, &threadattr, thread_sample, NULL); if (rc != 0) { EPRINTF("UNRESOLVED: pthread_create: %d %s", rc, strerror(rc)); exit(UNRESOLVED); } /* Start the TF threads */ DPRINTF(stderr, "Main Thread: Creating %d TF threads\n", cpus - 1); for (i = 0; i < cpus - 1; i++) { rc = pthread_create(&threads[i], &threadattr, thread_fn, &tp[i + 2]); if (rc != 0) { EPRINTF("UNRESOLVED: pthread_create: %d %s", rc, strerror(rc)); exit(UNRESOLVED); } } sleep(base_time + multiplier * 10 - seconds_read()); /* Start TP thread */ DPRINTF(stderr, "Main Thread: Creating TP thread\n"); rc = pthread_create(&threadtp, &threadattr, thread_fn, &tp[1]); if (rc != 0) { EPRINTF("UNRESOLVED: pthread_create: %d %s", rc, strerror(rc)); exit(UNRESOLVED); } sleep(base_time + multiplier * 20 - seconds_read()); /* Start TL thread */ DPRINTF(stderr, "Main Thread: Creating TL thread\n"); rc = pthread_create(&threadtl, &threadattr, thread_tl, &tp[0]); if (rc != 0) { EPRINTF("UNRESOLVED: pthread_create: %d %s", rc, strerror(rc)); exit(UNRESOLVED); } sleep(base_time + multiplier * 30 - seconds_read()); /* Start TB thread (boosting thread) */ rc = pthread_create(&threadtb, &threadattr, thread_tb, NULL); if (rc != 0) { EPRINTF("UNRESOLVED: pthread_create: %d %s", rc, strerror(rc)); exit(UNRESOLVED); } sleep(base_time + multiplier * 40 - seconds_read()); unlock_mutex = 1; sleep(base_time + multiplier * 50 - seconds_read()); /* Stop TL thread */ tp[0].stop = 1; sleep(base_time + multiplier * 60 - seconds_read()); /* Stop TP thread */ tp[1].stop = 1; sleep(base_time + multiplier * 70 - seconds_read()); /* Stop TF threads */ for (i = 2; i < cpus - 1; i++) { tp[i].stop = 1; } /* Stop sampler */ ts_stop = 1; DPRINTF(stderr, "Main Thread: stop sampler thread\n"); return 0; }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void lockRenderBuffer() { int rc = pthread_mutex_lock(&(state.mutex)); if (rc != 0) { EPRINTF("Error locking mutex: %d\n", rc); } }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ JNIEXPORT void JNICALL Java_com_qualcomm_fastcvdemo_apis_imageTransformation_Affine_update ( JNIEnv* env, jobject obj, jbyteArray img, jint w, jint h ) { jbyte* jimgData = NULL; jboolean isCopy = 0; uint32_t* curCornerPtr = 0; uint8_t* renderBuffer; uint64_t time; float timeMs; // Allocate the buffer once here if it's not allocated already if( affineState.affineImgBuf == NULL) { int frameSize = w*h*3/2; affineState.affineImgBuf = (uint8_t *)fcvMemAlloc(frameSize, 16); if( affineState.affineImgBuf == NULL ) { EPRINTF("Allocate affineImgBuf failed"); } else { memset(affineState.affineImgBuf, 0, w*h); memset(affineState.affineImgBuf+(w*h), 128, w*h/2); } } // Get data from JNI jimgData = env->GetByteArrayElements( img, &isCopy ); renderBuffer = getRenderBuffer( w, h ); lockRenderBuffer(); time = util.getTimeMicroSeconds(); uint8_t* pJimgData = (uint8_t*)jimgData; // Check if camera image data is not aligned. if( (int)jimgData & 0xF ) { // Allow for rescale if dimensions changed. if( w != (int)affineState.alignedImgWidth || h != (int)affineState.alignedImgHeight ) { if( affineState.alignedImgBuf != NULL ) { DPRINTF( "%s %d Creating aligned for preview\n", __FILE__, __LINE__ ); fcvMemFree( affineState.alignedImgBuf ); affineState.alignedImgBuf = NULL; } } // Allocate buffer for aligned data if necessary. if( affineState.alignedImgBuf == NULL ) { affineState.alignedImgWidth = w; affineState.alignedImgHeight = h; affineState.alignedImgBuf = (uint8_t*)fcvMemAlloc( w*h*3/2, 16 ); } memcpy( affineState.alignedImgBuf, jimgData, w*h*3/2 ); pJimgData = affineState.alignedImgBuf; } // Perform FastCV Function processing switch( affineState.affineType ) { case AFFINE_U8: updateAffine( (uint8_t*)pJimgData, w, h, affineState.affineImgBuf); colorConvertYUV420ToRGB565Renderer(affineState.affineImgBuf, w, h, (uint32_t*)renderBuffer ); break; case AFFINE_8X8: updateAffine( (uint8_t*)pJimgData, w, h, affineState.affineImgBuf); colorConvertYUV420ToRGB565Renderer(affineState.affineImgBuf, w, h, (uint32_t*)renderBuffer ); break; case NO_AFFINE: default: colorConvertYUV420ToRGB565Renderer(pJimgData, w, h, (uint32_t*)renderBuffer ); break; } // Update image timeMs = ( util.getTimeMicroSeconds() - time ) / 1000.f; util.setProcessTime((util.getProcessTime()*(29.f/30.f))+(float)(timeMs/30.f)); unlockRenderBuffer(); // Let JNI know we don't need data anymore env->ReleaseByteArrayElements( img, jimgData, JNI_ABORT ); }
int tapdisk_vbd_add_secondary(td_vbd_t *vbd) { td_image_t *leaf, *second = NULL; const char *path; int type, err; if (strcmp(vbd->secondary_name, "null") == 0) { DPRINTF("Removing secondary image\n"); vbd->secondary_mode = TD_VBD_SECONDARY_DISABLED; vbd->secondary = NULL; vbd->nbd_mirror_failed = 0; return 0; } DPRINTF("Adding secondary image: %s\n", vbd->secondary_name); type = tapdisk_disktype_parse_params(vbd->secondary_name, &path); if (type < 0) return type; leaf = tapdisk_vbd_first_image(vbd); if (!leaf) { err = -EINVAL; goto fail; } err = tapdisk_image_open(type, path, leaf->flags, &second); if (err) { if (type == DISK_TYPE_NBD) vbd->nbd_mirror_failed = 1; vbd->secondary=NULL; vbd->secondary_mode=TD_VBD_SECONDARY_DISABLED; goto fail; } if (second->info.size != leaf->info.size) { EPRINTF("Secondary image size %"PRIu64" != image size %"PRIu64"\n", second->info.size, leaf->info.size); err = -EINVAL; goto fail; } vbd->secondary = second; leaf->flags |= TD_IGNORE_ENOSPC; if (td_flag_test(vbd->flags, TD_OPEN_STANDBY)) { DPRINTF("In standby mode\n"); vbd->secondary_mode = TD_VBD_SECONDARY_STANDBY; } else { DPRINTF("In mirror mode\n"); vbd->secondary_mode = TD_VBD_SECONDARY_MIRROR; /* * we actually need this image to also be part of the chain, * since it may already contain data */ list_add(&second->next, &leaf->next); } DPRINTF("Added secondary image\n"); return 0; fail: if (second) tapdisk_image_close(second); return err; }