char* get_all_ele(void) { char* buf=NULL; char* temp=NULL; char* data=pvPortMalloc(66*sizeof(char)); memset(data,0,66); buf=get_ele_data(portL); strcpy(data,buf); vPortFree(buf); temp=get_ele_data(portR); strcat(data,temp); *(data+63)=0; vPortFree(temp); return data; }
void _lru_process_waiters(cache_t *c) { cache_lru_t *cp = (cache_lru_t *)c->fn.priv; lru_page_wait_t *pw = NULL; cache_cond_t *cache_cond; ex_off_t bytes_free, bytes_needed; if (stack_size(cp->pending_free_tasks) > 0) { //**Check on pending free tasks 1st while ((cache_cond = (cache_cond_t *)pop(cp->pending_free_tasks)) != NULL) { log_printf(15, "waking up pending task cache_cond=%p stack_size left=%d\n", cache_cond, stack_size(cp->pending_free_tasks)); apr_thread_cond_signal(cache_cond->cond); //** Wake up the paused thread } // return; } if (stack_size(cp->waiting_stack) > 0) { //** Also handle the tasks waiting for flushes to complete bytes_free = _lru_max_bytes(c) - cp->bytes_used; move_to_top(cp->waiting_stack); pw = get_ele_data(cp->waiting_stack); bytes_needed = pw->bytes_needed; while ((bytes_needed <= bytes_free) && (pw != NULL)) { bytes_free -= bytes_needed; delete_current(cp->waiting_stack, 1, 0); log_printf(15, "waking up waiting stack pw=%d\n", pw); apr_thread_cond_signal(pw->cond); //** Wake up the paused thread //** Get the next one if available pw = get_ele_data(cp->waiting_stack); bytes_needed = (pw == NULL) ? bytes_free + 1 : pw->bytes_needed; } } }
int resource_list_pending_activate(Resource_list_t *rl, char *rid, Resource_t *r) { int slot; char *prid; apr_thread_mutex_lock(rl->lock); move_to_top(rl->pending); slot = -1; while ((prid = get_ele_data(rl->pending)) != NULL) { log_printf(0, "rid=%s prid=%s\n", rid, prid); if (strcmp(rid, prid) == 0) { delete_current(rl->pending, 0, 0); slot = _resource_list_insert(rl, r); break; } move_down(rl->pending); } apr_thread_mutex_unlock(rl->lock); if (slot == -1) { log_printf(0, "No pending RID matches %s\n", rid); } return(slot); }
int resource_list_pending_insert(Resource_list_t *rl, char *rid) { int err; char *prid; apr_thread_mutex_lock(rl->lock); move_to_top(rl->pending); err = 0; while ((prid = get_ele_data(rl->pending)) != NULL) { log_printf(0, "rid=%s prid=%s\n", rid, prid); if (strcmp(rid, prid) == 0) { log_printf(0, "Attempting to insert an already pending RID=%s!\n", rid); err = 1; break; } move_down(rl->pending); } if (err == 0) { //** Safe to insert it push(rl->pending, rid); } apr_thread_mutex_unlock(rl->lock); return(err); }
void _opque_print_stack(Stack_t *stack) { op_generic_t *gop; int i=0; if (log_level() <= 15) return; move_to_top(stack); while ((gop = (op_generic_t *)get_ele_data(stack)) != NULL) { log_printf(15, " i=%d gid=%d type=%d\n", i, gop_id(gop), gop_get_type(gop)); i++; move_down(stack); } if (stack_size(stack) != i) log_printf(0, "Stack size mismatch! stack_size=%d i=%d\n", stack_size(stack), i); }
Task_que_t *task_lock(Task_coord_t *tc, ibp_task_t *task, Resource_t *r, char *cid, int op, int offset, int len, int tryagain, Allocation_t *a, int *lock) { osd_id_t id; Task_que_t *tq; int err, i; *lock = TASK_LOCK_ERROR; if (sscanf(cid, LU, &id) == 0) { return(NULL); } log_printf(10, "task_lock: Lock requested for cid=%s id=" LU " ns=%d ta=%d!\n", cid, id, task->ns->id, tryagain); // lock_tc(tc); tq = (Task_que_t *)g_hash_table_lookup(tc->table, cid); if (tq == NULL) { //** Not in the que if ((err = get_allocation_resource(r, id, a)) != 0) { //** Get the allocation log_printf(10, "task_lock id =%s not found\n", cid); // unlock_tc(tc) return(NULL); } log_printf(10, "task_lock: cid=%s id=" LU " a->id=" LU " ns=%d ta=%d!\n", cid, id, a->id, task->ns->id, tryagain); flush_log(); if (a->type == IBP_BYTEARRAY) { //** Don't need to worry about serializing op *lock = TASK_LOCK_GRANTED; // unlock_tc(tc) return(NULL); } log_printf(10, "task_lock: Creating new task_que for id=%s! ns=%d\n", cid, task->ns->id); flush_log(); if ((tq = create_task_que()) == NULL) { //** Get a new slice to add log_printf(0, "task_lock: Error allocating new 'Task_que_t'!\n"); // unlock_tc(tc) return(NULL); } log_printf(10, "task_lock: AFTER creatied new task_que for id=%s! ns=%d\n", cid, task->ns->id); flush_log(); //*** Init the new data structure *** tq->cid = strdup(cid); //** Dup the CID tq->dummycid = strdup(cid); //** Debugging only so REMOVE tq->a = *a; tq->r = r; g_hash_table_insert(tc->table, tq->cid, tq); //**Insert it into the table log_printf(10, "task_lock: AFTER g_hash_table_insert id=%s! ns=%d\n", cid, task->ns->id); flush_log(); } pthread_mutex_lock(&(tq->qlock)); //** Get the lock //** At this point we have a data structure that has to be managed if ((op == TASK_MANAGE) || (a->type == IBP_BYTEARRAY)) { //** Don't need to worry about serializing op *lock = TASK_LOCK_GRANTED; *a = tq->a; pthread_mutex_unlock(&(tq->qlock)); // unlock_tc(tc) return(NULL); } //** Anything else qoes in the queue debug_code( Stack_t *rque = tq->io_que[TASK_READ_QUE]; Stack_t *wque = tq->io_que[TASK_WRITE_QUE]; ibp_task_t *rt; ibp_task_t *wt; move_to_top(rque); move_to_top(wque); rt = (ibp_task_t *)get_ele_data(rque); wt = (ibp_task_t *)get_ele_data(wque); debug_printf(10, "task_lock: Start of routine "); if (rt == NULL) { debug_printf(10, "rtask=NULL * "); } else { debug_printf(10, "rtask=%d * ", rt->ns->id); } if (wt == NULL) { debug_printf(10, "wtask=NULL\n"); } else { debug_printf(10, "wtask=%d\n", wt->ns->id); } )