// MEMBER FUNCTION void Trick::MemoryManager::clear_all_vars() { ALLOC_INFO_MAP::iterator pos; ALLOC_INFO* alloc_info; pthread_mutex_lock(&mm_mutex); for (pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) { alloc_info = pos->second; pthread_mutex_unlock(&mm_mutex); clear_var( alloc_info->start); } pthread_mutex_unlock(&mm_mutex); }
bool persist_file_context::set_var(const std::string &global,const config &val, bool immediate) { // if (cfg_.empty()) { // load_persist_data(namespace_,cfg_); // } config bak; config bactive; if (immediate) { bak = cfg_; bactive = active_->cfg_.child_or_add("variables"); load(); root_node_.init(); } config &cfg = active_->cfg_.child_or_add("variables"); if (val.has_attribute(global)) { if (val[global].empty()) { clear_var(global,immediate); } else { cfg[global] = val[global]; if (immediate) bactive[global] = val[global]; } } else { cfg.clear_children(global); cfg.append(val); if (immediate) { bactive.clear_children(global); bactive.append(val); } } // dirty_ = true; if (!in_transaction_) return save_context(); else if (immediate) { bool ret = save_context(); cfg_ = bak; root_node_.init(); active_->cfg_.clear_children("variables"); active_->cfg_.remove_attribute("variables"); active_->cfg_.add_child("variables",bactive); return ret; } else return true; }
void remove_var(pgxc_ctl_var *var) { if ((var_head == var_tail) && (var_head == var)) var_head = var_tail = NULL; else if (var_head == var) { var_head = var_head->next; var_head->prev = NULL; } else if (var_tail == var) { var_tail->next = NULL; var_tail = var_tail->prev; } else { var->prev->next = var->next; var->next->prev = var->prev; } clear_var(var); }
// MEMBER FUNCTION void Trick::MemoryManager::clear_var( const char* name) { VARIABLE_MAP::iterator pos; ALLOC_INFO *alloc_info; pthread_mutex_lock(&mm_mutex); pos = variable_map.find( name); if (pos != variable_map.end()) { alloc_info = pos->second; pthread_mutex_unlock(&mm_mutex); clear_var( alloc_info->start); } else { std::stringstream message; message << "Can't clear variable \"" << name << "\" because it doesn't exist."; emitError(message.str()); } pthread_mutex_unlock(&mm_mutex); }
int main () { int typ; double op2; char s[MAX]; clear_var(); while((typ = my_getop(s)) != EOF) { switch(typ) { case NUMB: push(atof(s)); break; case '>': printf("%g\n",pop()); break; case LC: lower_case(s); break; case '+': push(pop() + pop()); break; case '-': op2 = pop(); push(pop() - op2); break; case '=': op2 = pop(); var[((int) op2) - 'A'] = pop(); break; case '*': push(pop() * pop()); break; case '/': op2 = pop(); if(op2) { push(pop() / op2); } else { printf("Zero division error\n"); } break; case '%': op2 = pop(); if(op2) { push(fmod(pop(),op2)); } else { printf("zero division error\n"); } break; case '$': printf("the result is %g\n", pop()); flag = 1; break; case '\n': break; default : if((typ >= 'A') & (typ <= 'Z')) { map_var(typ); } else { printf("Unknown operator or operand\n"); } break; } } return 0; }