void x11c_clear(X11Common* x11Common) { x11Common->stopped = 1; join_thread(&x11Common->processEventThreadId, NULL, NULL); PTHREAD_MUTEX_LOCK(&x11Common->eventMutex) /* don't allow events to be processed */ kic_free_keyboard_connect(&x11Common->keyboardConnect); pic_free_progress_bar_connect(&x11Common->progressBarConnect); mic_free_mouse_connect(&x11Common->mouseConnect); if (x11Common->createdWindowInfo) { x11c_close_window(&x11Common->windowInfo); x11Common->createdWindowInfo = 0; } SAFE_FREE(&x11Common->windowName); x11Common->osd = NULL; PTHREAD_MUTEX_UNLOCK(&x11Common->eventMutex) destroy_mutex(&x11Common->eventMutex); memset(x11Common, 0, sizeof(x11Common)); }
TASKQ *task_freeq (TASKQ *q) { TASK *t; task_stop (q); wait_mutex (q); debug ("freeing queue\n"); while ((t = q->queue) != NULL) { q->queue = t->next; free (t); } debug ("freeing pool\n"); while ((t = q->pool) != NULL) { q->pool = t->next; free (t); } debug ("closing event and critical section\n"); end_mutex (q); destroy_mutex (q); destroy_ready (q); free (q); return (NULL); }
~ring_buffer_implementation() throw (ring_buffer_concurrency_error_exception) { { lock_guard lock(this); free(buffer); } destroy_mutex(this); }
ring_buffer_implementation(size_t capacity, ring_buffer* parent) throw (ring_buffer_concurrency_error_exception, ring_buffer_out_of_memory_exception) : capacity(capacity), _read(0), _write(0), parent(parent) { initialize_mutex(this); read_callback.callback = write_callback.callback = 0; if (0 == (buffer = malloc(capacity))) { destroy_mutex(this); throw ring_buffer_out_of_memory_exception(); } }
ring_buffer_implementation(ring_buffer_implementation* other, ring_buffer* parent) throw (ring_buffer_concurrency_error_exception, ring_buffer_out_of_memory_exception) : capacity(other->capacity), _read(other->_read), _write(other->_write), read_callback(other->read_callback), write_callback(other->write_callback), parent(parent) { lock_guard lock(other); initialize_mutex(this); if (0 != (buffer = malloc(capacity))) memcpy(buffer, other->buffer, capacity); else { destroy_mutex(this); throw ring_buffer_out_of_memory_exception(); } }
void delete_list_item(play_item_t* play_item) { dbg1("deleting list item at %p with ID %llu between (prev) %p and (next) %p\n", play_item, play_item->play_id, play_item->prev_item, play_item->next_item); if (play_item->next_item != NULL) { play_item->next_item->prev_item = play_item->prev_item; } if (play_item->prev_item != NULL) { play_item->prev_item->next_item = play_item->next_item; } destroy_mutex(play_item->mutex); PyMem_Free(play_item); }
static void destroy_connect_data(CONNECT_THREAD_DATA **p_data) { tcp_destruct((*p_data)->p_self); free((*p_data)->p_self); destroy_mutex(&(*p_data)->t_data_mutex); destroy_semaphore(&(*p_data)->t_data_sem); free(*p_data); *p_data=NULL; }
void hac_free_http_access(HTTPAccess** access) { if (*access == NULL) { return; } (*access)->stopped = 1; join_thread(&(*access)->httpThreadId, NULL, NULL); har_free_resources(&(*access)->resources); destroy_mutex(&(*access)->playerStateMutex); SAFE_FREE(access); }
void free_dv_decoder_resources() { int i; DVDecoder* decoder = NULL; int refCount; if (g_decoderResourceRefCount <= 0) { return; } PTHREAD_MUTEX_LOCK(&g_decoderResource.resourceMutex); g_decoderResourceRefCount--; refCount = g_decoderResourceRefCount; PTHREAD_MUTEX_UNLOCK(&g_decoderResource.resourceMutex); if (refCount == 0) { if (g_decoderResource.numDecodersInUse > 0) { ml_log_warn("There are %d DV decoder resources still in use - please fix the source code\n", g_decoderResource.numDecodersInUse); } for (i = 0; i < g_decoderResource.numDecoders; i++) { /* set decoder NULL in list so that free doesn't just change it to !inUse */ decoder = g_decoderResource.decoder[i]; g_decoderResource.decoder[i] = NULL; free_dv_decoder(&decoder); } destroy_mutex(&g_decoderResource.resourceMutex); memset(&g_decoderResource, 0, sizeof(DVDecoderResource)); } }
static void ddc_close(void* data) { DVDecodeStreamConnect* connect = (DVDecodeStreamConnect*)data; if (data == NULL) { return; } if (connect->useWorkerThread) { connect->stopped = 1; /* wake up threads - this is to avoid valgrind saying the mutx is still in use when pthread_mutex_destroy is called below */ PTHREAD_MUTEX_LOCK(&connect->workerMutex); pthread_cond_broadcast(&connect->frameIsReadyCond); pthread_cond_broadcast(&connect->workerIsBusyCond); PTHREAD_MUTEX_UNLOCK(&connect->workerMutex); join_thread(&connect->workerThreadId, NULL, NULL); } free_dv_decoder(&connect->decoder); free_dv_decoder_resources(); SAFE_FREE(&connect->dvData); if (connect->useWorkerThread) { destroy_cond_var(&connect->workerIsBusyCond); destroy_cond_var(&connect->frameIsReadyCond); destroy_mutex(&connect->workerMutex); } SAFE_FREE(&connect); }
static void test() { pid_t childpid; mutex mparent = create_mutex(MUTEX_NAME, true); if ((childpid = fork()) == -1) { sys_error_exit("fork"); } if (childpid == 0) { /* Child process */ mutex m = open_mutex(MUTEX_NAME); log("Child try lock mutex"); if (trylock_mutex(m)) // Should not succeed error_exit("Child trylock_mutex: mutex not locked by parent"); log("Child try to lock, 1 second timeout"); if (lock_withtimeout_mutex(m, 1)) error_exit("Child lock_withtimeout_mutex: mutex not locked by parent"); log("Child try to lock, 4 second timeout"); if (!lock_withtimeout_mutex(m, 4)) error_exit("Child lock_withtimeout_mutex: mutex locked by parent"); log("Child release lock"); unlock_mutex(m); close_mutex(m); exit(0); } else { /* Parent process */ log("Parent sleep 2 second with lock"); sleep(2); log("Parent unlock"); unlock_mutex(mparent); log("Parent sleep 2 seconds without lock"); sleep(2); log("Parent wait for lock"); lock_mutex(mparent); log("Parent got lock"); destroy_mutex(MUTEX_NAME, mparent); } }
int main(){ global *container;/*holder for EVERYTHING!*/ container=malloc(sizeof(global)); resetContainer(&container);/*clear out container*/ int esc = False;/*build for loop to contain prompt*/ /*system("clear");*/ printf("Good day, this is the recovery utility\n"); while(esc !=True){ char *inp; printf("\nPlease select ONE of the following:\n"); printf("1: Scan drive.\n");/*restarts program from beginning*/ printf("2: Save results to file.\n");/*save stack to file if exists*/ printf("3: Load results from file.\n");/*load stack from file*/ printf("4: Begin recovery.\n");/*start processing if we have full stack. if not open option 2, will prompt to save stack if it preexists*/ printf("5: Exit.\n");/*exits program, prompts to save current stack*/ printf(">"); inp = getInput(); int select = answer1(inp); free(inp); inp=NULL; /*begin task*/ if(select == 1){/*Scan drive*/ int go=True; if(container ->head != NULL && container ->tail != NULL){ printf("\nSCANNING DRIVE WILL WIPE CURRENT MEMORY!\n"); printf("Are you sure you would like to continue?(y or n)\n>"); go=yesNo(); } if(go==True){ printf("\nActivating scanner program, please standby\n"); destroyContainer(&container); resetContainer(&container); /*system("clear");*/ printf("Follow the prompt below\n"); printf("Name of file: "); char *tmp3 = getInput(); strcpy(container->name,tmp3); free(tmp3); tmp3=NULL; /*container->name =getInput();*/ go=partOne(&container);/*start program*/ if(go ==True){ /*system("clear");*/ stats(container); } } } else if(select == 2){/*Save results to file*/ if(one(container) == False){ printf("\nInitial scan skipped or invalid name given\ninvalid option selected. Try again\n"); } else{ printf("\nSAVE COMPLETE\n"); } } else if(select == 3){/*Load results from file*/ if(container ->head != NULL && container ->tail != NULL){/*pre existing data in memory*/ printf("\nLoading from file will DELETE RESULTS already in memory.\nContinue?\n>"); if(yesNo() == True){ if(two(&container) == False){ printf("\nInvalid file or file does not exist.\ninvalid option selected. Try again\n"); }/*error*/ }/*yes or no*/ }/*if head and tail are not nulled*/ else{/*are nulled so skip prompt*/ if(two(&container) == False){ printf("\nInvalid file or file does not exist.\ninvalid option selected. Try again\n"); }/*error*/ } /*system("clear");*/ stats(container); }/*end processing*/ else if(select == 4){/*Begin processing*/ if(container ->head != NULL && container ->tail != NULL){ printf("\nAbout to begin processing.\nONCE STARTED ALL RESULTS IN MEMORY WILL BE DELETED\n"); printf("Would you like to continue?\n>"); if(yesNo() == True){/*do not save before continuing*/ /*system("clear");*/ stats(container); end(&container);/*make threaded to show progress*/ /*system("clear");*//*return to main menu*/ printf("Complete!\n"); } } else{/*no stack*/ printf("\nInitial scan skipped.\ninvalid option selected. Try again\n"); } }/*end the processing case*/ else if(select == 5){/*exit*/ if(container ->head != NULL && container ->tail != NULL){/*pre existing data in memory*/ printf("\nEXITING WITHOUT SAVING CURRENT RESULTS WILL WIPE MEMORY!\nAre you sure you would like to exit?(y or n)\n>"); if(yesNo()==True){ printf("\n"); esc = True; break;/*break from this loop*/ } /*end the yesno question*/ }/*end case of data preexisting in memory*/ else{/*no data in memory so just exit*/ esc = True; break;/*break from this loop*/ } }/*end the exit case*/ /*end task*/ }/*end while loop*/ printf("\nShutting down program, Please wait\n"); destroyContainer(&container); free(container); container=NULL; destroy_mutex(); fprintf(stderr,"All Done! =^.^=\n"); pthread_exit(NULL); }/*end mainfile*/
int main() { setlocale(LC_ALL,""); clit_config *config = malloc(sizeof(clit_config)); if(parse_config(config) == -1) { // first run int res = authorize(config); if(res == -1) { printf("Please retry.\n"); } else printf("Authorization finished. Run the program again.\n"); free(config); exit(0); } me = newuser(); me->screen_name = config->screen_name; me->id = config->user_id; init_oauth(config->key,config->secret); free(config); init_mutex(); raw_event_stream = new_raw_event_queue(); printf("Loading the timelines....\n"); if(init_timelines() == -1) { pthread_mutex_lock(&error_mutex); printf("Cannot load the timeline. Please check your network connection.\n"); pthread_mutex_unlock(&error_mutex); goto exit_twilc; } initscr(); curs_set(0); //if(has_colors() == FALSE) //goto exit_twilc; raw(); keypad(stdscr,TRUE); noecho(); start_color(); move(0,0); refresh(); if(init_ui() == -1) goto exit_twilc; start_userstream(); wait_command(tl_win); exit_twilc: destroy_ui(); curs_set(1); endwin(); destroy_mutex(); for(int i = 0; i < TIMELINE_COUNT; ++i) destroy_timeline(timelines[i]); stop_userstream(); pthread_mutex_lock(&event_buffer_mutex); destroy_raw_event_queue(raw_event_stream); raw_event_stream = NULL; pthread_mutex_unlock(&event_buffer_mutex); return 0; }