/** * Creates new latch. * * Latch allows one or more threads to wait until a set of operations * being performed in other threads are complete. Latch serves as a gate for the threads * which are waiting until it is opened. Latch initialized to N counts can be used * to make one thread wait until N threads have completed some action, or some * action has been performed N times. * The key difference between latch and traditional semaphore is that latch notifies * every waiting threads when it reaches zero, while semaphore notifies only one waiting thread. * * @param[out] latch the memory address where the newly created latch * will be stored * @param[in] count the created key * @sa java.util.concurrent.CountDownLatch */ IDATA VMCALL hylatch_create(hylatch_t *latch_ptr, IDATA count) { int res; hylatch_t latch; latch = malloc(sizeof(HyLatch)); if (latch == NULL) { return TM_ERROR_OUT_OF_MEMORY; } res = port_mutex_create(&latch->mutex, APR_THREAD_MUTEX_DEFAULT); if (res) { goto cleanup; } res = hycond_create(&latch->condition); if (res) { goto cleanup_mutex; } latch->count = count; *latch_ptr = latch; return TM_ERROR_NONE; cleanup_mutex: port_mutex_destroy(&latch->mutex); cleanup: free(latch); return res; }
EBProfileCollector::~EBProfileCollector() { for (EBProfilesMap::iterator it = profilesByMethod.begin(), end = profilesByMethod.end(); it!=end; ++it) { EBMethodProfile* profile = it->second; delete profile; } port_mutex_destroy(&profilesLock); }
/** * Destroy a monitor. * * Destroying a monitor frees the internal resources associated * with it. * * @note A monitor must NOT be destroyed if threads are waiting on * it, or if it is currently owned. * * @param[in] monitor a monitor to be destroyed * @return 0 on success or non-0 on failure (the monitor is in use) * * @see hythread_monitor_init_with_name */ IDATA VMCALL hythread_monitor_destroy(hythread_monitor_t monitor) { if (monitor->owner != NULL || monitor->wait_count > 0) { return TM_ERROR_ILLEGAL_STATE; } port_mutex_destroy(&monitor->mutex); hycond_destroy(&monitor->condition); free(monitor); return TM_ERROR_NONE; }
/** * Releases thread structure. */ IDATA VMCALL hythread_struct_release(hythread_t thread) { IDATA status; assert(thread); // Release thread primitives status = hysem_destroy(thread->resume_event); assert(status == TM_ERROR_NONE); status = port_mutex_destroy(&thread->mutex); assert(status == TM_ERROR_NONE); status = hythread_monitor_destroy(thread->monitor); assert(status == TM_ERROR_NONE); memset(thread, 0, hythread_get_struct_size()); return TM_ERROR_NONE; }
static IDATA destroy_group_list() { hythread_group_t cur; IDATA status,status2; int i; // This method works only if there are no running threads. // there is no good way to kill running threads status=hythread_global_lock(); if (status != TM_ERROR_NONE) return status; cur = group_list->next; status = TM_ERROR_NONE; while (cur != group_list) { if (hythread_group_release(cur) == TM_ERROR_NONE) { cur = group_list->next; } else { status = TM_ERROR_RUNNING_THREADS; cur = cur->next; } } free(lock_table->live_objs); for (i = 0; i < HY_MAX_FAT_TABLES && lock_table->tables[i]; i++) { free(lock_table->tables[i]); } port_mutex_destroy(&lock_table->mutex); hycond_destroy(&lock_table->write); hycond_destroy(&lock_table->read); free(lock_table); status2=hythread_global_unlock(); if (status2 != TM_ERROR_NONE) return status2; return status; }
int shutdown_signals() { if (asserts_disabled) { restore_assert_dialogs(); asserts_disabled = false; } signal(SIGABRT, prev_sig); ULONG res = RemoveVectoredExceptionHandler(veh); if (!res) return -1; BOOL ok = SetConsoleCtrlHandler((PHANDLER_ROUTINE)ctrl_handler, FALSE); if (!ok) return -1; port_mutex_destroy(&g_mutex); return 0; } //shutdown_signals
/** * Destroys the latch and releases the associated memory. * * @param[in] latch the latch */ IDATA VMCALL hylatch_destroy(hylatch_t latch) { IDATA status = port_mutex_destroy(&latch->mutex); status |= hycond_destroy(&latch->condition); free(latch); return status; }
/** * Destroys the condition variable and releases the associated memory. * * @param[in] cond the condition variable to destroy * @sa apr_thread_cond_destroy() */ IDATA VMCALL hycond_destroy (hycond_t *cond) { assert(cond->dummy_node.next == &cond->dummy_node && "destroying condition variable with active waiters"); return port_mutex_destroy(&cond->queue_mutex); }