gint DisplayStopThread(camera_t* cam) { displaythread_info_t *info; chain_t *display_service; display_service=GetService(cam,SERVICE_DISPLAY); if (display_service!=NULL) { // if display service running... info=(displaythread_info_t*)display_service->data; // send request for cancellation: pthread_mutex_lock(&info->mutex_cancel); info->cancel_req=1; pthread_mutex_unlock(&info->mutex_cancel); // when cancellation occured, join: pthread_join(display_service->thread, NULL); pthread_mutex_lock(&display_service->mutex_data); pthread_mutex_lock(&display_service->mutex_struct); RemoveChain(cam,display_service); #ifdef HAVE_SDLLIB SDLQuit(display_service); #endif pthread_mutex_unlock(&display_service->mutex_struct); pthread_mutex_unlock(&display_service->mutex_data); FreeChain(display_service); } return (1); }
void FreeNmList( sym_id sym ) { //================================ // Free a symbol table list of name lists. while( sym != NULL ) { FreeChain( &sym->u.nl.group_list ); sym = FreeLink( (void **)sym ); } }
void FreeSFHeader( sym_id sym ) { //================================== // Free statement function header. if( sym->u.ns.si.sf.header != NULL ) { FreeChain( &sym->u.ns.si.sf.header->parm_list ); FMemFree( sym->u.ns.si.sf.header ); sym->u.ns.si.sf.header = NULL; } }
void FiniDebugLine( dw_client cli ) { char buf[ sizeof( uint_32 ) ]; long size; buf[ 0 ] = 0; buf[ 1 ] = 1; buf[ 2 ] = DW_LNE_end_sequence; CLIWrite( DW_DEBUG_LINE, buf, 3 ); size = CLITell( DW_DEBUG_LINE ) - sizeof( uint_32 ) - cli->section_base[ DW_DEBUG_LINE ]; WriteU32( buf, size ); CLISeek( DW_DEBUG_LINE, cli->section_base[ DW_DEBUG_LINE ], DW_SEEK_SET ); CLIWrite( DW_DEBUG_LINE, buf, sizeof(uint_32) ); CLISeek( DW_DEBUG_LINE, 0, DW_SEEK_END ); FreeChain( cli, cli->debug_line.files ); }
gint DisplayStartThread(camera_t* cam) { chain_t *display_service=NULL; displaythread_info_t *info=NULL; display_service=GetService(cam,SERVICE_DISPLAY); if (display_service==NULL) {// if no display service running... display_service=(chain_t*)malloc(sizeof(chain_t)); display_service->current_buffer=NULL; display_service->next_buffer=NULL; display_service->data=(void*)malloc(sizeof(displaythread_info_t)); info=(displaythread_info_t*)display_service->data; pthread_mutex_init(&display_service->mutex_struct, NULL); pthread_mutex_init(&display_service->mutex_data, NULL); pthread_mutex_init(&info->mutex_cancel, NULL); pthread_mutex_lock(&info->mutex_cancel); info->cancel_req=0; pthread_mutex_unlock(&info->mutex_cancel); pthread_mutex_lock(&display_service->mutex_data); CommonChainSetup(cam, display_service,SERVICE_DISPLAY); pthread_mutex_lock(&display_service->mutex_struct); InsertChain(cam, display_service); if (pthread_create(&display_service->thread, NULL, DisplayThread, (void*)display_service)) { RemoveChain(cam, display_service); pthread_mutex_unlock(&display_service->mutex_struct); pthread_mutex_unlock(&display_service->mutex_data); FreeChain(display_service); return(-1); } pthread_mutex_unlock(&display_service->mutex_struct); pthread_mutex_unlock(&display_service->mutex_data); } return (1); }
gint V4lStopThread(camera_t* cam) { v4lthread_info_t *info; chain_t *v4l_service; v4l_service=GetService(cam,SERVICE_V4L); if (v4l_service!=NULL) { // if V4L service running... info=(v4lthread_info_t*)v4l_service->data; /* Clean cancel handler: */ pthread_mutex_lock(&info->mutex_cancel); info->cancel_req=1; pthread_mutex_unlock(&info->mutex_cancel); /* common handlers...*/ pthread_join(v4l_service->thread, NULL); pthread_mutex_lock(&v4l_service->mutex_data); pthread_mutex_lock(&v4l_service->mutex_struct); RemoveChain(cam,v4l_service); /* Do custom cleanups here...*/ if ((info->frame.image!=NULL)&&(info->frame.allocated_image_bytes>0)) { free(info->frame.image); info->frame.allocated_image_bytes=0; } close(info->v4l_dev); /* Mendatory cleanups: */ pthread_mutex_unlock(&v4l_service->mutex_struct); pthread_mutex_unlock(&v4l_service->mutex_data); FreeChain(v4l_service); v4l_service=NULL; } return (1); }
static int SetupGlobChain(char const *dirname, IncludeStruct *i) { DynamicBuffer pattern; char *dir; size_t l; int r; glob_t glob_buf; DirectoryFilenameChain *dc = CachedDirectoryChains; i->chain = NULL; if (!*dirname) return E_CANT_OPEN; dir = StrDup(dirname); if (!dir) return E_NO_MEM; /* Strip trailing slashes off directory */ l = strlen(dir); while(l) { if (*(dir+l-1) == '/') { l--; *(dir+l) = 0; } else { break; } } /* Repair root directory :-) */ if (!l) { *dir = '/'; } /* Check the cache */ while(dc) { if (!strcmp(dc->dirname, dir)) { if (DebugFlag & DB_TRACE_FILES) { fprintf(ErrFp, "Found cached directory listing for `%s'\n", dir); } free(dir); i->chain = dc->chain; return OK; } dc = dc->next; } if (DebugFlag & DB_TRACE_FILES) { fprintf(ErrFp, "Scanning directory `%s' for *.rem files\n", dir); } if (ShouldCache) { dc = malloc(sizeof(DirectoryFilenameChain)); if (dc) { dc->dirname = StrDup(dir); if (!dc->dirname) { free(dc); dc = NULL; } } if (dc) { if (DebugFlag & DB_TRACE_FILES) { fprintf(ErrFp, "Caching directory `%s' listing\n", dir); } dc->chain = NULL; dc->next = CachedDirectoryChains; CachedDirectoryChains = dc; } } DBufInit(&pattern); DBufPuts(&pattern, dir); DBufPuts(&pattern, "/*.rem"); free(dir); r = glob(DBufValue(&pattern), 0, NULL, &glob_buf); DBufFree(&pattern); if (r == GLOB_NOMATCH) { globfree(&glob_buf); return OK; } if (r != 0) { globfree(&glob_buf); return -1; } /* Add the files to the chain backwards to preserve sort order */ for (r=glob_buf.gl_pathc-1; r>=0; r--) { FilenameChain *ch = malloc(sizeof(FilenameChain)); if (!ch) { globfree(&glob_buf); FreeChain(i->chain); i->chain = NULL; return E_NO_MEM; } /* TODO: stat the file and only add if it's a plain file and readable by us */ ch->filename = StrDup(glob_buf.gl_pathv[r]); if (!ch->filename) { globfree(&glob_buf); FreeChain(i->chain); i->chain = NULL; free(ch); return E_NO_MEM; } ch->next = i->chain; i->chain = ch; } if (dc) { dc->chain = i->chain; } globfree(&glob_buf); return OK; }
gint V4lStartThread(camera_t* cam) { chain_t* v4l_service=NULL; v4lthread_info_t *info=NULL; char *stemp; stemp=(char*)malloc(STRING_SIZE*sizeof(char)); v4l_service=GetService(cam, SERVICE_V4L); if (v4l_service==NULL) { // if no V4L service running... v4l_service=(chain_t*)malloc(sizeof(chain_t)); v4l_service->current_buffer=NULL; v4l_service->next_buffer=NULL; v4l_service->data=(void*)malloc(sizeof(v4lthread_info_t)); info=(v4lthread_info_t*)v4l_service->data; pthread_mutex_init(&v4l_service->mutex_data, NULL); pthread_mutex_init(&v4l_service->mutex_struct, NULL); pthread_mutex_init(&info->mutex_cancel, NULL); /* if you want a clean-interrupt thread:*/ pthread_mutex_lock(&info->mutex_cancel); info->cancel_req=0; pthread_mutex_unlock(&info->mutex_cancel); /* setup v4l_thread: handles, ...*/ pthread_mutex_lock(&v4l_service->mutex_data); CommonChainSetup(cam, v4l_service,SERVICE_V4L); info->frame.image=NULL; info->frame.allocated_image_bytes=0; // open V4L device info->v4l_dev=-1; info->v4l_dev = open(cam->prefs.v4l_dev_name, O_RDWR); if (info->v4l_dev < 0) { sprintf(stemp,"Failed to open V4L device %s",cam->prefs.v4l_dev_name); Error(stemp); free(stemp); stemp=NULL; FreeChain(v4l_service); v4l_service=NULL; return(-1); } /* Insert chain and start service*/ pthread_mutex_lock(&v4l_service->mutex_struct); InsertChain(cam, v4l_service); if (pthread_create(&v4l_service->thread, NULL, V4lThread,(void*) v4l_service)) { /* error starting thread. You should cleanup here (free, unset global vars,...):*/ /* Mendatory cleanups:*/ RemoveChain(cam, v4l_service); pthread_mutex_unlock(&v4l_service->mutex_struct); pthread_mutex_unlock(&v4l_service->mutex_data); if ((info->frame.image!=NULL)&&(info->frame.allocated_image_bytes>0)) { free(info->frame.image); info->frame.allocated_image_bytes=0; } free(stemp); stemp=NULL; FreeChain(v4l_service); v4l_service=NULL; return(-1); } pthread_mutex_unlock(&v4l_service->mutex_struct); pthread_mutex_unlock(&v4l_service->mutex_data); } free(stemp); stemp=NULL; return (1); }