void workerTaskStop (Task *task) { DEBUG_ONLY( OSThreadId id ); DEBUG_ONLY( id = osThreadId() ); ASSERT(task->id == id); ASSERT(myTask() == task); ACQUIRE_LOCK(&all_tasks_mutex); if (task->all_prev) { task->all_prev->all_next = task->all_next; } else { all_tasks = task->all_next; } if (task->all_next) { task->all_next->all_prev = task->all_prev; } currentWorkerCount--; RELEASE_LOCK(&all_tasks_mutex); freeTask(task); }
/** work_done : it will be called after work thread finish @req : the worker **/ void work_done(uv_work_t *req, int status) { cspider_t *cspider = ((cs_task_t*)req->data)->cspider; /*打印到日志 print log */ logger(0, "%s download finish.\n", ((cs_task_t*)req->data)->url, cspider); /* when finish download data, first, remove task from task_queue_doing second, add rawText to data_queue finally, free the task. */ uv_rwlock_wrlock(cspider->lock); cspider->download_thread--; cs_task_queue *q = removeTask(cspider->task_queue_doing, req->data); PANIC(q); cs_rawText_queue *queue = (cs_rawText_queue*)malloc(sizeof(cs_rawText_queue)); PANIC(queue); queue->data = q->task->data; addData(cspider->data_queue, queue); freeTask(q); uv_rwlock_wrunlock(cspider->lock); return; }
nat freeTaskManager (void) { Task *task, *next; nat tasksRunning = 0; ACQUIRE_LOCK(&all_tasks_mutex); for (task = all_tasks; task != NULL; task = next) { next = task->all_next; if (task->stopped) { freeTask(task); } else { tasksRunning++; } } debugTrace(DEBUG_sched, "freeing task manager, %d tasks still running", tasksRunning); all_tasks = NULL; RELEASE_LOCK(&all_tasks_mutex); #if defined(THREADED_RTS) closeMutex(&all_tasks_mutex); #if !defined(MYTASK_USE_TLV) freeThreadLocalKey(¤tTaskKey); #endif #endif tasksInitialized = 0; return tasksRunning; }
void freeModel(_md) { size_t predNum, funcNum, axNum, taskNum, factNum, restrNum, typeNum, srcNum, errNum; freeServData(modelPtr); /* Predicates */ forVect(predNum, preds_m) freeFunc(getPredPtr(predNum)); /* Functions */ forVect(funcNum, funcs_m) freeFunc(getFuncPtr(funcNum)); /* Axioms */ forVect(axNum, axioms_m) freeAxiom(getAxPtr(axNum)); /* Tasks */ forVect(taskNum, taskPtrs_m) freeTask(getTaskPtr(taskNum)); /* Temp Facts */ forVect(factNum, tmpFacts_m) freeFact(ptr(Fact, tmpFacts_m) + factNum); /* Restrictions */ forVect(restrNum, restrs_m) freeRestriction(getRestrPtr(restrNum)); /* DataTypes */ forVect(typeNum, types_m) freeDataType(getTypePtr(typeNum)); /* Sources */ forVect(srcNum, modelPtr->sources) freeSource(ptr(Source, modelPtr->sources) + srcNum); /* Errors */ forVect(errNum, modelPtr->errors) freeError(ptr(Error, modelPtr->errors) + errNum); /* Vectors */ freeVect(preds_m); freeVect(funcs_m); freeVect(axioms_m); freeVect(taskPtrs_m); freeVect(tmpFacts_m) freeVect(restrs_m); freeVect(types_m); freeVect(modelPtr->errors); freeVect(modelPtr->sources); }
void freeHost(Host *h) { if ((h->fetches == NULL) && (h->waits == NULL)) { if (h->next) h->next->prev = h->prev; if (h->prev) h->prev->next = h->next; else { h->task->hosts = h->next; freeTask(h->task); } symFree(h->name); free(h); } }
void discardTasksExcept (Task *keep) { Task *task, *next; // Wipe the task list, except the current Task. ACQUIRE_LOCK(&all_tasks_mutex); for (task = all_tasks; task != NULL; task=next) { next = task->all_next; if (task != keep) { debugTrace(DEBUG_sched, "discarding task %ld", (long)TASK_ID(task)); freeTask(task); } } all_tasks = keep; keep->all_next = NULL; keep->all_prev = NULL; RELEASE_LOCK(&all_tasks_mutex); }
void discardTasksExcept (Task *keep) { Task *task, *next; // Wipe the task list, except the current Task. ACQUIRE_LOCK(&all_tasks_mutex); for (task = all_tasks; task != NULL; task=next) { next = task->all_next; if (task != keep) { debugTrace(DEBUG_sched, "discarding task %" FMT_SizeT "", (size_t)TASK_ID(task)); #if defined(THREADED_RTS) // It is possible that some of these tasks are currently blocked // (in the parent process) either on their condition variable // `cond` or on their mutex `lock`. If they are we may deadlock // when `freeTask` attempts to call `closeCondition` or // `closeMutex` (the behaviour of these functions is documented to // be undefined in the case that there are threads blocked on // them). To avoid this, we re-initialize both the condition // variable and the mutex before calling `freeTask` (we do // precisely the same for all global locks in `forkProcess`). initCondition(&task->cond); initMutex(&task->lock); #endif // Note that we do not traceTaskDelete here because // we are not really deleting a task. // The OS threads for all these tasks do not exist in // this process (since we're currently // in the child of a forkProcess). freeTask(task); } } all_tasks = keep; keep->all_next = NULL; keep->all_prev = NULL; RELEASE_LOCK(&all_tasks_mutex); }
void freeMyTask (void) { Task *task; task = myTask(); if (task == NULL) return; if (!task->stopped) { errorBelch( "freeMyTask() called, but the Task is not stopped; ignoring"); return; } if (task->worker) { errorBelch("freeMyTask() called on a worker; ignoring"); return; } ACQUIRE_LOCK(&all_tasks_mutex); if (task->all_prev) { task->all_prev->all_next = task->all_next; } else { all_tasks = task->all_next; } if (task->all_next) { task->all_next->all_prev = task->all_prev; } taskCount--; RELEASE_LOCK(&all_tasks_mutex); freeTask(task); setMyTask(NULL); }
void discardTasksExcept (Task *keep) { Task *task, *next; // Wipe the task list, except the current Task. ACQUIRE_LOCK(&all_tasks_mutex); for (task = all_tasks; task != NULL; task=next) { next = task->all_next; if (task != keep) { debugTrace(DEBUG_sched, "discarding task %" FMT_SizeT "", (size_t)TASK_ID(task)); // Note that we do not traceTaskDelete here because // we are not really deleting a task. // The OS threads for all these tasks do not exist in // this process (since we're currently // in the child of a forkProcess). freeTask(task); } } all_tasks = keep; keep->all_next = NULL; keep->all_prev = NULL; RELEASE_LOCK(&all_tasks_mutex); }
int main(int argc, char ** argv) { int i, j, counter, order; double * current = NULL, * old = NULL, * test = NULL, sum_test; // Setup: // TaskDescriptor has all the info read from the input TaskDescriptor * task = readTask(stdin); current = malloc(sizeof(double) * task->VECTOR.order); old = malloc(sizeof(double) * task->VECTOR.order); test = malloc (sizeof(double) * (task->VECTOR.order + 1) ); // test vector saves the original values of the matrix row and the value required from the vector for testing // after the algorithm has ended. // Since we only test one row, this is a good approach to save memory memcpy(test, task->MATRIX.value[task->ROW_TEST], sizeof(double) * task->MATRIX.order); test[task->VECTOR.order] = task->VECTOR.value[task->ROW_TEST]; /* Start of the algorithm */ // Initiate the matrix by dividing each value by the diagonal value and setting the diagonal value as 0 for (i = 0; i < task->MATRIX.order; ++i) { int diagonal_value = task->MATRIX.value[i][i]; for (j = 0; j < task->MATRIX.order; j++) task->MATRIX.value[i][j] /= diagonal_value; task->VECTOR.value[i] /= diagonal_value; task->MATRIX.value[i][i] = 0; } memcpy (current, task->VECTOR.value, sizeof(double) * task->VECTOR.order); order = task->VECTOR.order; for (counter = 0; counter < task->ITE_MAX; ) { double max_dif, max_value, error, value; swap_vectors(&old, ¤t); for (i = 0; i < order; ++i) { double sum = 0.0; for (j = 0; j < order; ++j) { // We know value[i][i] is 0, it won't change the value // Faster to do 1 mult and 1 addition once than an if for every value sum += (task->MATRIX.value[i][j] * old[j]); } current[i] = task->VECTOR.value[i] - sum; } // We have ended the iteration, we increase the counter here // so that if we break out of the for loop the counter will be correct ++counter; // Calculate the error // Its calculated as // error_i = Max(Dif[0], Dif[1], ... , Dif[n-1]) / Max(Abs(x[0]_i, x[1]_i, ..., x[n-1]_i)) // where Dif[i] = Abs(x[i]_k - x[i]_(k-1)) max_dif = fabs(current[0] - old[0]); max_value = fabs(current[0]); for (i = 1; i < order; ++i) { value = fabs(current[i] - old[i]); if (value > max_dif) max_dif = value; value = fabs(current[i]); if (value > max_value) max_value = value; } error = max_dif/max_value; if (error < task->ERROR) break; } /* End of the algorithm */ /* Tests and output */ sum_test = 0.0; for (i = 0; i < order; ++i) { sum_test += current[i] * test[i]; } printf("---------------------------------------------------------\n" "Iterations: %d\n" "RowTest: %d => [%f] =? %f\n" "---------------------------------------------------------\n", counter, task->ROW_TEST, sum_test, test[order]); freeTask(&task); if (current) free(current); if (old) free (old); if (test) free(test); return 0; }
void TaskMap<CostInfo>::freeTaskDelay(Task* t, double d) { freeTask(t); delayedTasks[t->getUniqueId()] = d; }
void TaskMap<CostInfo>::freeFromTask(Creature* c) { if (Task* t = getTask(c)) freeTask(t); }
void TaskMap<CostInfo>::takeTask(const Creature* c, Task* task) { freeTask(task); creatureMap.insert(c, task); }