static apr_status_t reslist_cleanup(void *data_) { apr_status_t rv; apr_reslist_t *rl = data_; apr_res_t *res; apr_thread_mutex_lock(rl->listlock); while (rl->nidle > 0) { res = pop_resource(rl); rl->ntotal--; rv = destroy_resource(rl, res); if (rv != APR_SUCCESS) { return rv; } free_container(rl, res); } assert(rl->nidle == 0); assert(rl->ntotal == 0); apr_thread_mutex_destroy(rl->listlock); apr_thread_cond_destroy(rl->avail); return APR_SUCCESS; }
/** Read all resources in the resource manager block in CCS. @param reslist Empty list to fill with resources. @param rulelist List of rules to use when searching CCS. @return 0 on success, nonzero on failure. */ int load_resources(resource_t ** reslist, resource_rule_t ** rulelist) { int resID = 0; resource_t *newres; resource_rule_t *currule; char tok[256]; list_do(rulelist, currule) { for (resID = 1;; resID++) { /* XXX check */ snprintf(tok, sizeof(tok), RESOURCE_BASE "/%s[%d]", currule->rr_type, resID); newres = load_resource(currule, tok); if (!newres) break; if (store_resource(reslist, newres) != 0) { fprintf(stderr, "Error storing %s resource\n", newres->r_rule->rr_type); destroy_resource(newres); continue; } /* Just information */ newres->r_flags = RF_DEFINED; } } while (!list_done(rulelist, currule)) ; return 0; }
/** Obliterate a resource_t list. @param list Resource list to free. */ void destroy_resources(resource_t ** list) { resource_t *res; while ((res = *list)) { list_remove(list, res); destroy_resource(res); } }
/* dispatcher function. Uses the above functions to run. */ void dispatcher(PcbPtr queue) { clock_time = 0; input_queue = queue; io_resources = create_resource(PRINTERS,SCANNERS,MODEMS,CDS); memory = mabCreate(REAL_TIME_MEMORY+USER_TIME_MEMORY); memory = memAlloc(memory,REAL_TIME_MEMORY); // allocate memory for real time memory->id = 999; // 999 is for real time while (input_queue || user_queue || realtime_queue || current_process || p1_queue || p2_queue || p3_queue) { // there are items in the queues or a process is running enqueue_user_real_queues(); // add items to user queue and real time queue enqueue_roundrobin(); // add items to feedback queues if memory can be allocated current_process = running_processes(); //check running process and decrement time / suspend start_process(); // start next process in RR queue sleep(1); clock_time = clock_time+1; } memFree_all(memory); // free any remaining memory destroy_resource(io_resources); // free memory for resources }
/** Try to load all the attributes in our rule set. If none are found, or an error occurs, return NULL and move on to the next one. @param rule Resource rule set to use when looking for data @param base Base XPath path to start with. @return New resource if legal or NULL on failure/error */ resource_t * load_resource(resource_rule_t * rule, const char *base) { resource_t *res; char ccspath[1024]; char *attrname, *attr; int x, found = 0, flags; res = malloc(sizeof(*res)); if (!res) { fprintf(stderr, "Out of memory\n"); return NULL; } memset(res, 0, sizeof(*res)); res->r_rule = rule; for (x = 0; res->r_rule->rr_attrs && res->r_rule->rr_attrs[x].ra_name; x++) { flags = rule->rr_attrs[x].ra_flags; attrname = strdup(rule->rr_attrs[x].ra_name); if (!attrname) { destroy_resource(res); return NULL; } /* Ask CCS for the respective attribute */ attr = NULL; /* XXX check */ snprintf(ccspath, sizeof(ccspath), "%s/@%s", base, attrname); if (conf_get(ccspath, &attr) != 0) { if (flags & (RA_REQUIRED | RA_PRIMARY)) { /* Missing required attribute. We're done. */ free(attrname); destroy_resource(res); return NULL; } if (!(flags & RA_INHERIT)) { /* If we don't have the inherit flag, see if we have a value anyway. If we do, this value is the default value, and should be used. */ if (!rule->rr_attrs[x].ra_value) { free(attrname); continue; } /* Copy default value from resource rule */ /* XXX check */ attr = strdup(rule->rr_attrs[x].ra_value); } } found = 1; /* If we are supposed to inherit and we don't have an instance of the specified attribute in CCS, then we keep the inherit flag and use it as the attribute. However, if we _do_ have the attribute for this instance, we drop the inherit flag and use the attribute. */ if (flags & RA_INHERIT) { if (attr) { flags &= ~RA_INHERIT; } else { attr = strdup(rule->rr_attrs[x].ra_value); if (!attr) { destroy_resource(res); free(attrname); return NULL; } } } /* Store the attribute. We'll ensure all required attributes are present soon. */ if (attrname && attr) /* XXX check */ store_attribute(&res->r_attrs, attrname, attr, flags); } if (!found) { destroy_resource(res); return NULL; } /* XXX check, not checking leads to unexpected flow trace */ res->r_actions = act_dup(rule->rr_actions); _get_actions_ccs(base, res); return res; }
/** * Perform routine maintenance on the resource list. This call * may instantiate new resources or expire old resources. */ static apr_status_t reslist_maint(apr_reslist_t *reslist) { apr_time_t now; apr_status_t rv; apr_res_t *res; int created_one = 0; apr_thread_mutex_lock(reslist->listlock); /* Check if we need to create more resources, and if we are allowed to. */ while (reslist->nidle < reslist->min && reslist->ntotal < reslist->hmax) { /* Create the resource */ rv = create_resource(reslist, &res); if (rv != APR_SUCCESS) { free_container(reslist, res); apr_thread_mutex_unlock(reslist->listlock); return rv; } /* Add it to the list */ push_resource(reslist, res); /* Update our counters */ reslist->ntotal++; /* If someone is waiting on that guy, wake them up. */ rv = apr_thread_cond_signal(reslist->avail); if (rv != APR_SUCCESS) { apr_thread_mutex_unlock(reslist->listlock); return rv; } created_one++; } /* We don't need to see if we're over the max if we were under it before */ if (created_one) { apr_thread_mutex_unlock(reslist->listlock); return APR_SUCCESS; } /* Check if we need to expire old resources */ now = apr_time_now(); while (reslist->nidle > reslist->smax && reslist->nidle > 0) { /* Peak at the last resource in the list */ res = APR_RING_LAST(&reslist->avail_list); /* See if the oldest entry should be expired */ if (now - res->freed < reslist->ttl) { /* If this entry is too young, none of the others * will be ready to be expired either, so we are done. */ break; } APR_RING_REMOVE(res, link); reslist->nidle--; reslist->ntotal--; rv = destroy_resource(reslist, res); free_container(reslist, res); if (rv != APR_SUCCESS) { apr_thread_mutex_unlock(reslist->listlock); return rv; } } apr_thread_mutex_unlock(reslist->listlock); return APR_SUCCESS; }
inline void image::draw(const paint_params &pp) { if(modified){ destroy_resource(); create(pp.target); } if(bmp == nullptr) return; if(is_animated){ auto tp = std::chrono::system_clock::now(); duration += std::chrono::duration_cast<std::chrono::milliseconds>(tp - timepoint); timepoint = tp; auto step = duration.count() / (delay.count() * 10); if(step != 0){ duration = std::chrono::milliseconds(duration.count() % (delay.count() * 10)); UINT i = 0; for(;;){ pp.target->DrawBitmap( bmp, dest, 1.f, static_cast<D2D1_BITMAP_INTERPOLATION_MODE>(interpolationmode), src); i++; UINT f = (currentframe + i) % framecount; select_frame(pp.target, f); if(i == step) break; ID2D1Bitmap *frame; btarget->GetBitmap(&frame); if(frame != nullptr){ pp.target->DrawBitmap( frame, dest, 1.f, static_cast<D2D1_BITMAP_INTERPOLATION_MODE>(interpolationmode), src); utils::SafeRelease(frame); } } }else pp.target->DrawBitmap( bmp, dest, 1.f, static_cast<D2D1_BITMAP_INTERPOLATION_MODE>(interpolationmode), src); } if(is_gif){ ID2D1Bitmap *frame; btarget->GetBitmap(&frame); if(frame != nullptr){ pp.target->DrawBitmap( frame, dest, 1.f, static_cast<D2D1_BITMAP_INTERPOLATION_MODE>(interpolationmode), src); utils::SafeRelease(frame); } }else{ pp.target->DrawBitmap( bmp, dest, 1.f, static_cast<D2D1_BITMAP_INTERPOLATION_MODE>(interpolationmode), src); } }
inline image::~image() { destroy_resource(); utils::SafeRelease(composed); }
resource_manager<Derived, Traits>::~resource_manager() { destroy_resource(); }