int list_remove(llist_t *the_list, val_t val) { // lock sentinel node node_t *prev = the_list->head; LOCK(prev->lock); if (prev->next == NULL) { // the list is empty UNLOCK(prev->lock); return 0; } node_t *elem = prev->next; LOCK(elem->lock); while (elem->next != NULL && elem->data <= val) { if (elem->data == val) { // if found, assign prev next to elem next prev->next = elem->next; // unlock and deallocate mem UNLOCK(elem->lock); DESTROY_LOCK(elem->lock); free(elem->lock); free(elem); // its a success UNLOCK(prev->lock); return 1; } UNLOCK(prev->lock); prev = elem; elem = elem->next; LOCK(elem->lock); } // just check if the last node in the list is not equal to val if (elem->data == val) { // if found, assign prev next to elem next prev->next = elem->next; // unlock and deallocate mem UNLOCK(elem->lock); DESTROY_LOCK(elem->lock); free(elem->lock); free(elem); // its a success UNLOCK(prev->lock); return 1; } // we did not find it; unlock and report failure UNLOCK(elem->lock); UNLOCK(prev->lock); return 0; }
void terminateWorkerThreads(void) { int i; VLOG(("httpserv: server_thread: waiting on stopping")); PZ_Lock(qLock); PZ_NotifyAllCondVar(jobQNotEmptyCv); PZ_Unlock(qLock); /* Wait for worker threads to terminate. */ for (i = 0; i < maxThreads; ++i) { perThread *slot = threads + i; if (slot->prThread) { PR_JoinThread(slot->prThread); } } /* The worker threads empty the jobQ before they terminate. */ PZ_Lock(qLock); PORT_Assert(threadCount == 0); PORT_Assert(PR_CLIST_IS_EMPTY(&jobQ)); PZ_Unlock(qLock); DESTROY_CONDVAR(jobQNotEmptyCv); DESTROY_CONDVAR(freeListNotEmptyCv); DESTROY_CONDVAR(threadCountChangeCv); PR_DestroyLock(lastLoadedCrlLock); DESTROY_LOCK(qLock); PR_Free(jobTable); PR_Free(threads); }
void ottery_st_wipe(struct ottery_state *st) { DESTROY_LOCK(&st->mutex); ottery_st_wipe_nolock(st); }
static void destroy_writer (struct writer_context_s *ctx) { LOCK (ctx->mutex); ctx->refcount--; if (ctx->refcount != 0) { UNLOCK (ctx->mutex); return; } ctx->stop_me = 1; if (ctx->have_data) SetEvent (ctx->have_data); UNLOCK (ctx->mutex); TRACE1 (DEBUG_SYSIO, "gpgme:destroy_writer", ctx->file_hd, "waiting for termination of thread %p", ctx->thread_hd); WaitForSingleObject (ctx->stopped, INFINITE); TRACE1 (DEBUG_SYSIO, "gpgme:destroy_writer", ctx->file_hd, "thread %p has terminated", ctx->thread_hd); if (ctx->stopped) CloseHandle (ctx->stopped); if (ctx->have_data) CloseHandle (ctx->have_data); if (ctx->is_empty) CloseHandle (ctx->is_empty); CloseHandle (ctx->thread_hd); DESTROY_LOCK (ctx->mutex); free (ctx); }
/* Release all resources associated with the given context. */ void gpgme_release (gpgme_ctx_t ctx) { TRACE (DEBUG_CTX, "gpgme_release", ctx); if (!ctx) return; _gpgme_engine_release (ctx->engine); ctx->engine = NULL; _gpgme_fd_table_deinit (&ctx->fdt); _gpgme_release_result (ctx); _gpgme_signers_clear (ctx); _gpgme_sig_notation_clear (ctx); if (ctx->signers) free (ctx->signers); if (ctx->lc_ctype) free (ctx->lc_ctype); if (ctx->lc_messages) free (ctx->lc_messages); _gpgme_engine_info_release (ctx->engine_info); ctx->engine_info = NULL; DESTROY_LOCK (ctx->lock); free (ctx); }
void node_delete_l(node_l_t *node) { DESTROY_LOCK(&node->lock); #if GC == 1 ssfree((void*) node); #endif }
static struct writer_context_s * create_writer (HANDLE fd) { struct writer_context_s *c; SECURITY_ATTRIBUTES sec_attr; DWORD tid; DEBUG1 ("creating new write thread for file handle %p", fd ); memset (&sec_attr, 0, sizeof sec_attr ); sec_attr.nLength = sizeof sec_attr; sec_attr.bInheritHandle = FALSE; c = calloc (1, sizeof *c ); if (!c) return NULL; c->file_hd = fd; c->have_data = CreateEvent (&sec_attr, TRUE, FALSE, NULL); c->is_empty = CreateEvent (&sec_attr, TRUE, TRUE, NULL); c->stopped = CreateEvent (&sec_attr, TRUE, FALSE, NULL); if (!c->have_data || !c->is_empty || !c->stopped ) { DEBUG1 ("** CreateEvent failed: ec=%d\n", (int)GetLastError ()); if (c->have_data) CloseHandle (c->have_data); if (c->is_empty) CloseHandle (c->is_empty); if (c->stopped) CloseHandle (c->stopped); free (c); return NULL; } c->is_empty = set_synchronize (c->is_empty); INIT_LOCK (c->mutex); c->thread_hd = CreateThread (&sec_attr, 0, writer, c, 0, &tid ); if (!c->thread_hd) { DEBUG1 ("** failed to create writer thread: ec=%d\n", (int)GetLastError ()); DESTROY_LOCK (c->mutex); if (c->have_data) CloseHandle (c->have_data); if (c->is_empty) CloseHandle (c->is_empty); if (c->stopped) CloseHandle (c->stopped); free (c); return NULL; } else { /* We set the priority of the thread higher because we know that it only runs for a short time. This greatly helps to increase the performance of the I/O. */ SetThreadPriority (c->thread_hd, get_desired_thread_priority ()); } return c; }
void list_delete(llist_t *the_list) { /* must lock the whole list */ node_t *elem = the_list->head; LOCK(elem->lock); if (elem->next == NULL) { /* we have an empty list, just delete sentinel node */ UNLOCK(elem->lock); DESTROY_LOCK(elem->lock); /* deallocate memory and we are done */ free(elem->lock); free(elem); } else { // we need to go through list while (elem->next != NULL) { // lock everything LOCK(elem->next->lock); elem = elem->next; } // everything is locked, delete them while (the_list->head != NULL) { elem = the_list->head; the_list->head = elem->next; UNLOCK(elem->lock); DESTROY_LOCK(elem->lock); free(elem->lock); free(elem); } } // deallocate memory free(the_list); }
void set_delete_l(intset_l_t *set) { node_l_t *node, *next; node = set->head; while (node != NULL) { next = node->next; DESTROY_LOCK(&node->lock); /* free(node); */ ssfree((void*) node); /* TODO : fix with ssmem */ node = next; } ssfree(set); }
/* {{{ apc_cache_destroy */ PHP_APCU_API void apc_cache_destroy(apc_cache_t* cache) { if (!cache) { return; } /* destroy lock */ DESTROY_LOCK(&cache->header->lock); /* XXX this is definitely a leak, but freeing this causes all the apache children to freeze. It might be because the segment is shared between several processes. To figure out is how to free this safely. */ /*apc_sma_free(cache->shmaddr);*/ apc_efree(cache); }
void apc_interned_strings_shutdown(TSRMLS_D) { if (apc_interned_strings_data) { zend_hash_clean(CG(function_table)); zend_hash_clean(CG(class_table)); zend_hash_clean(EG(zend_constants)); CG(interned_strings_start) = old_interned_strings_start; CG(interned_strings_end) = old_interned_strings_end; zend_new_interned_string = old_new_interned_string; zend_interned_strings_snapshot = old_interned_strings_snapshot; zend_interned_strings_restore = old_interned_strings_restore; DESTROY_LOCK(APCSG(lock)); } }
void terminateWorkerThreads(void) { VLOG(("selfserv: server_thead: waiting on stopping")); PZ_Lock(qLock); PZ_NotifyAllCondVar(jobQNotEmptyCv); while (threadCount > 0) { PZ_WaitCondVar(threadCountChangeCv, PR_INTERVAL_NO_TIMEOUT); } /* The worker threads empty the jobQ before they terminate. */ PORT_Assert(PR_CLIST_IS_EMPTY(&jobQ)); PZ_Unlock(qLock); DESTROY_CONDVAR(jobQNotEmptyCv); DESTROY_CONDVAR(freeListNotEmptyCv); DESTROY_CONDVAR(threadCountChangeCv); PR_DestroyLock(lastLoadedCrlLock); DESTROY_LOCK(qLock); PR_Free(jobTable); PR_Free(threads); }
static void destroy_writer (struct writer_context_s *c) { LOCK (c->mutex); c->stop_me = 1; if (c->have_data) SetEvent (c->have_data); UNLOCK (c->mutex); DEBUG1 ("waiting for thread %p termination ...", c->thread_hd ); WaitForSingleObject (c->stopped, INFINITE); DEBUG1 ("thread %p has terminated", c->thread_hd ); if (c->stopped) CloseHandle (c->stopped); if (c->have_data) CloseHandle (c->have_data); if (c->is_empty) CloseHandle (c->is_empty); CloseHandle (c->thread_hd); DESTROY_LOCK (c->mutex); free (c); }
static struct writer_context_s * create_writer (HANDLE fd) { struct writer_context_s *ctx; SECURITY_ATTRIBUTES sec_attr; DWORD tid; TRACE_BEG (DEBUG_SYSIO, "gpgme:create_writer", fd); memset (&sec_attr, 0, sizeof sec_attr); sec_attr.nLength = sizeof sec_attr; sec_attr.bInheritHandle = FALSE; ctx = calloc (1, sizeof *ctx); if (!ctx) { TRACE_SYSERR (errno); return NULL; } ctx->file_hd = fd; ctx->refcount = 1; ctx->have_data = CreateEvent (&sec_attr, TRUE, FALSE, NULL); if (ctx->have_data) ctx->is_empty = CreateEvent (&sec_attr, TRUE, TRUE, NULL); if (ctx->is_empty) ctx->stopped = CreateEvent (&sec_attr, TRUE, FALSE, NULL); if (!ctx->have_data || !ctx->is_empty || !ctx->stopped) { TRACE_LOG1 ("CreateEvent failed: ec=%d", (int) GetLastError ()); if (ctx->have_data) CloseHandle (ctx->have_data); if (ctx->is_empty) CloseHandle (ctx->is_empty); if (ctx->stopped) CloseHandle (ctx->stopped); free (ctx); /* FIXME: Translate the error code. */ TRACE_SYSERR (EIO); return NULL; } ctx->is_empty = set_synchronize (ctx->is_empty); INIT_LOCK (ctx->mutex); ctx->thread_hd = CreateThread (&sec_attr, 0, writer, ctx, 0, &tid ); if (!ctx->thread_hd) { TRACE_LOG1 ("CreateThread failed: ec=%d", (int) GetLastError ()); DESTROY_LOCK (ctx->mutex); if (ctx->have_data) CloseHandle (ctx->have_data); if (ctx->is_empty) CloseHandle (ctx->is_empty); if (ctx->stopped) CloseHandle (ctx->stopped); free (ctx); TRACE_SYSERR (EIO); return NULL; } else { /* We set the priority of the thread higher because we know that it only runs for a short time. This greatly helps to increase the performance of the I/O. */ SetThreadPriority (ctx->thread_hd, get_desired_thread_priority ()); } TRACE_SUC (); return ctx; }