bool ServerCollect::clear(LayoutManager& manager, const time_t now) { mutex_.wrlock(); int32_t size = hold_->size(); BlockCollect** blocks = NULL; if (size > 0)//这里size大部份情况下都为0,所以拷贝的代价是能接受的 { int32_t index = 0; blocks = new (std::nothrow)BlockCollect*[size]; assert(NULL != blocks); for (BLOCKS_ITER iter = hold_->begin(); iter != hold_->end(); iter++) { blocks[index++] = (*iter); } } clear_(); mutex_.unlock(); if (size > 0) { BlockCollect* pblock = NULL; ArrayHelper<BlockCollect*> helper(size, blocks, size); for (int32_t i = 0; i < helper.get_array_index(); ++i) { //这里有点问题,如果server刚下线,在上次server结构过期之前又上来了,此时解除了关系是不正确的 //这里先在这里简单搞下在block解除关系的时候,如果检测ID和指针都一致时才解除关系 pblock = *helper.at(i); assert(NULL != pblock); manager.get_block_manager().relieve_relation(pblock, this, now, BLOCK_COMPARE_SERVER_BY_ID_POINTER); } tbsys::gDeleteA(blocks); } return true; }
DataValue& DataValue::operator=(const short int arg) { clear_(); data_.ssize_ = arg; value_type_ = INT_VALUE; return *this; }
Chunk::Chunk( int x, int z ) { clear_(); x_ = x; z_ = z; // worldMatrix_.setIdentity(); float s = getSceneManager()->getLOD()->getScale(); float len = getSceneManager()->getLOD()->getLengthOneSide(); worldMatrix_.setTranslate(x_*len, 0.0f, z_*len); // center_.x = x_*len + 0.5f*len; center_.y = 0.0f; center_.z = z_*len + 0.5f*len; // int vn = getSceneManager()->getLOD()->getVerticesNumberOneChunk(); vertexBuffer_.create(vn * sizeof(sVDT_PositionColorTexture), D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED); refreshHeight(); //heights_.resize(vn, 0); // rect_.left_ = x_*len; rect_.right_ = x_*len + len; rect_.bottom_ = z*len; rect_.top_ = z*len + len; // AlphaMapCompressed_.resize(tAlphaMapCompressedSize * tAlphaMapCompressedSize, 0); AlphaMapUnCompressed_.resize(tAlphaMapUnCompressedSize * tAlphaMapUnCompressedSize, 0); //memset(&AlphaMapUnCompressed_[0], 0, AlphaMapUnCompressed_.size() * sizeof(uniRGBA)); // AlphaMapTexture_ = NULL; }
DataValue& DataValue::operator=(const unsigned long long arg) { clear_(); data_.ssize_ = arg; value_type_ = INT_VALUE; return *this; }
DataValue& DataValue::operator=(const DoubleList& arg) { clear_(); data_.dou_list_ = new DoubleList(arg); value_type_ = DOUBLE_LIST; return *this; }
DataValue& DataValue::operator=(const QString& arg) { clear_(); data_.str_ = new String(arg); value_type_ = STRING_VALUE; return *this; }
DataValue& DataValue::operator=(const StringList& arg) { clear_(); data_.str_list_ = new StringList(arg); value_type_ = STRING_LIST; return *this; }
DataValue& DataValue::operator=(const float arg) { clear_(); data_.dou_ = arg; value_type_ = DOUBLE_VALUE; return *this; }
DataValue& DataValue::operator=(const IntList& arg) { clear_(); data_.int_list_ = new IntList(arg); value_type_ = INT_LIST; return *this; }
blargg_err_t M3u_Playlist::parse() { blargg_err_t err = parse_(); if ( err ) clear_(); return err; }
static T & instance() { static volatile bool register_ = true; static volatile uint64_t location_[ YOCTO_U64_FOR_ITEM(T) ]; //------------------------------------------------------------------ // Double Check Pattern //------------------------------------------------------------------ YOCTO_LOCK(access); if ( !instance_ ) { YOCTO_LOCK(access); if ( !instance_ ) { //---------------------------------------------------------- // once in a lifetime registering //---------------------------------------------------------- if( register_ ) { verbose = singleton_verbosity; if(verbose) hidden::singleton_out( T::name, "registering", T::life_time); clear_( (void *)location_ ); threading::at_exit::perform( release_, T::life_time); register_ = false; } //---------------------------------------------------------- // access protected static memory //---------------------------------------------------------- void *instance_addr = (void *) &location_[0]; instance_ = static_cast<volatile T *>( instance_addr ); try { new ( instance_addr ) T(); } catch(...) { instance_ = NULL; clear_( (void*)location_ ); throw; } } } return *(T *)instance_; }
//! called at exit static void release_() throw() { if (instance_ != NULL) { if(verbose) hidden::singleton_out( T::name, "destroying", T::life_time); instance_->~T(); clear_( (void *)instance_ ); instance_ = NULL; } }
//-------------------------------------------------------------------- // assignment operator //-------------------------------------------------------------------- DataValue& DataValue::operator=(const DataValue& p) { // Check for self-assignment if (this == &p) return *this; // clean up clear_(); // assign if (p.value_type_ == STRING_LIST) { data_.str_list_ = new StringList(*(p.data_.str_list_)); } else if (p.value_type_ == STRING_VALUE) { data_.str_ = new String(*(p.data_.str_)); } else if (p.value_type_ == INT_LIST) { data_.int_list_ = new IntList(*(p.data_.int_list_)); } else if (p.value_type_ == DOUBLE_LIST) { data_.dou_list_ = new DoubleList(*(p.data_.dou_list_)); } else { data_ = p.data_; } // copy type value_type_ = p.value_type_; // copy unit if necessary if (p.hasUnit()) { unit_ = p.unit_; } return *this; }
std::string Terminal::GetCommand(const int &prev_cmd_return_/*=0*/){ std::string output = ""; sclock::time_point commandRequestTime = sclock::now(); sclock::time_point currentTime; //Update status message if (status_window) { werase(status_window); print(status_window,statusStr.at(0).c_str()); } // Check for commands in the command queue. if(!prompt_user && !cmd_queue.empty()){ while(true){ output = cmd_queue.front(); cmd_queue.pop_front(); // Check for blank lines. if(!output.empty()){ break; } } from_script = true; } else{ // Get a command from the user. while(true){ if(SIGNAL_SEGFAULT){ // segmentation fault (SIGSEGV) Close(); return "_SIGSEGV_"; } if(SIGNAL_INTERRUPT){ // ctrl-c (SIGINT) SIGNAL_INTERRUPT = false; output = "CTRL_C"; break; } if(SIGNAL_TERMSTOP){ // ctrl-z (SIGTSTP) SIGNAL_TERMSTOP = false; output = "CTRL_Z"; break; } //Update status message if (status_window) { werase(status_window); print(status_window,statusStr.at(0).c_str()); } flush(); // If there is anything in the stream, dump it to the screen // Time out if there is no command within the set interval (default 0.5 s). if (commandTimeout_ > 0) { // Update the current time. currentTime = sclock::now(); std::chrono::duration<float> time_span = std::chrono::duration_cast<std::chrono::duration<float>>(currentTime - commandRequestTime); // If the timeout has passed we simply return the empty output string. if (time_span.count() > commandTimeout_) { break; } } int keypress = wgetch(input_window); // Check for internal commands if(keypress == ERR){continue;} // No key was pressed in the interval else if(keypress == 10){ // Enter key (10) std::string temp_cmd = cmd.Get(); //Reset the position in the history. commands.Reset(); if(temp_cmd != "" && temp_cmd != commands.PeekPrev()){ // Only save this command if it is different than the previous command commands.Push(temp_cmd); } output = temp_cmd; std::cout << prompt << output << "\n"; flush(); _scrollPosition = 0; clear_(); tabCount = 0; break; } else if(keypress == '\t' && enableTabComplete) { tabCount++; output = cmd.Get().substr(0,cursX - offset) + "\t"; break; } else if(keypress == 4){ // ctrl-d (EOT) output = "CTRL_D"; clear_(); tabCount = 0; break; } else if(keypress == 9){ } // Tab key (9) else if(keypress == KEY_UP){ // 259 if(commands.GetIndex() == 0){ commands.Capture(cmd.Get()); } std::string temp_cmd = commands.GetPrev(); if(temp_cmd != "NULL"){ clear_(); cmd.Set(temp_cmd); in_print_(cmd.Get().c_str()); } } else if(keypress == KEY_DOWN){ // 258 std::string temp_cmd = commands.GetNext(); if(temp_cmd != "NULL"){ clear_(); cmd.Set(temp_cmd); in_print_(cmd.Get().c_str()); } } else if(keypress == KEY_LEFT){ cursX--; } // 260 else if(keypress == KEY_RIGHT){ cursX++; } // 261 else if(keypress == KEY_PPAGE){ //Page up key scroll_(-(_winSizeY-2)); } else if(keypress == KEY_NPAGE){ //Page down key scroll_(_winSizeY-2); } else if(keypress == KEY_BACKSPACE){ // 263 wmove(input_window, 0, --cursX); wdelch(input_window); cmd.Pop(cursX - offset); } else if(keypress == KEY_DC){ // Delete character (330) //Remove character from terminal wdelch(input_window); //Remove character from cmd string cmd.Pop(cursX - offset); } else if(keypress == KEY_IC){ cmd.ToggleInsertMode(); } // Insert key (331) else if(keypress == KEY_HOME){ cursX = offset; } else if(keypress == KEY_END){ cursX = cmd.GetSize() + offset; } else if(keypress == KEY_MOUSE) { //Handle mouse events MEVENT mouseEvent; //Get information about mouse event. getmouse(&mouseEvent); switch (mouseEvent.bstate) { //Scroll up case BUTTON4_PRESSED: scroll_(-3); break; //Scroll down. (Yes the name is strange.) case REPORT_MOUSE_POSITION: scroll_(3); break; } } else if(keypress == KEY_RESIZE) { //Do nothing with the resize key } else{ in_char_((char)keypress); cmd.Put((char)keypress, cursX - offset - 1); } // Check for cursor too far to the left if(cursX < offset){ cursX = offset + cmd.GetSize(); } // Check for cursor too far to the right if(cursX > (int)(cmd.GetSize() + offset)){ cursX = cmd.GetSize() + offset; } if (keypress != ERR) tabCount = 0; update_cursor_(); refresh_(); } if(prompt_user){ // Waiting for user to specify yes or no. if(output != "yes" && output != "y"){ std::cout << prompt << "Aborting execution!\n"; cmd_queue.clear(); } prompt_user = false; return ""; } from_script = false; } // In the event of an empty command, return. if(output.empty()) return ""; // Check for system commands. std::string temp_cmd_string = output.substr(output.find_first_not_of(' '), output.find_first_of(' ')); // Strip the command from the front of the input. std::string temp_arg_string = output.substr(output.find_first_of(' ')+1, output.find_first_of('#')); // Does not ignore leading whitespace. if(temp_cmd_string.empty() || temp_cmd_string[0] == '#'){ // This is a comment line. return ""; } if(temp_cmd_string.substr(0, output.find_first_of(' ')).find('.') != std::string::npos){ if(temp_cmd_string == ".cmd"){ // Load a command script. std::string command_filename = temp_arg_string.substr(output.find_first_not_of(' ')); // Ignores leading whitespace. if(!LoadCommandFile(command_filename.c_str())){ // Failed to load command script. std::cout << prompt << "Error! Failed to load command script " << command_filename << ".\n"; } } else if(temp_cmd_string == ".echo"){ // Print something to the screen. std::cout << prompt << temp_arg_string << std::endl; } else if(temp_cmd_string == ".prompt"){ // Prompt the user with a yes/no question. std::cout << prompt << temp_arg_string << " (yes/no)" << std::endl; prompt_user = true; } else{ // Unrecognized command. std::cout << prompt << "Error! Unrecognized system command " << temp_cmd_string << ".\n"; } return ""; // Done processing the command. Don't need to send it to the caller. } // Print the command if it was read from a script. This is done so that the user // will know what is happening in the script file. It will also ignore system // commands in the file. if(from_script){ std::cout << prompt << output << "\n"; flush(); _scrollPosition = 0; clear_(); tabCount = 0; } return output; }
Chunk::~Chunk() { clear_(); }
QuadNode::~QuadNode() { clear_(); }
void ParDiSO::clear() { clear_(PARDISO_MEMORY_FOR_FACTORS); }
ParDiSO::~ParDiSO() { clear_(PARDISO_ALL_MEMORY); }
Global::Global() { clear_(); }
FxManager::FxManager() { clear_(); }
std::string Terminal::GetCommand(){ std::string output = ""; time_t commandRequestTime; time_t currentTime; time(&commandRequestTime); //Update status message if (status_window) { werase(status_window); print(status_window,statusStr.at(0).c_str()); } while(true){ if(SIGNAL_SEGFAULT){ // segmentation fault (SIGSEGV) Close(); return "_SIGSEGV_"; } if(SIGNAL_INTERRUPT){ // ctrl-c (SIGINT) SIGNAL_INTERRUPT = false; output = "CTRL_C"; text_length = 0; break; } else if(SIGNAL_TERMSTOP){ // ctrl-z (SIGTSTP) SIGNAL_TERMSTOP = false; output = "CTRL_Z"; text_length = 0; break; } flush(); // If there is anything in the stream, dump it to the screen //Time out if there is no command within the set interval (default 0.5 s). if (commandTimeout_ > 0) { time(¤tTime); //If the timeout has passed we simply return the empty output string. if (currentTime > commandRequestTime + commandTimeout_) { break; } } int keypress = wgetch(input_window); // Check for internal commands if(keypress == ERR){ } // No key was pressed in the interval else if(keypress == 10){ // Enter key (10) std::string temp_cmd = cmd.Get(); //Reset the position in the history. commands.Reset(); if(temp_cmd != "" && temp_cmd != commands.PeekPrev()){ // Only save this command if it is different than the previous command commands.Push(temp_cmd); } output = temp_cmd; std::cout << prompt << output << "\n"; flush(); text_length = 0; _scrollPosition = 0; clear_(); tabCount = 0; break; } else if(keypress == '\t' && enableTabComplete) { tabCount++; output = cmd.Get().substr(0,cursX - offset) + "\t"; break; } else if(keypress == 4){ // ctrl-d (EOT) output = "CTRL_D"; text_length = 0; clear_(); tabCount = 0; break; } else if(keypress == 9){ } // Tab key (9) else if(keypress == KEY_UP){ // 259 if(commands.GetIndex() == 0){ commands.Capture(cmd.Get()); } std::string temp_cmd = commands.GetPrev(); if(temp_cmd != "NULL"){ clear_(); cmd.Set(temp_cmd); in_print_(cmd.Get().c_str()); text_length = cmd.GetSize(); } } else if(keypress == KEY_DOWN){ // 258 std::string temp_cmd = commands.GetNext(); if(temp_cmd != "NULL"){ clear_(); cmd.Set(temp_cmd); in_print_(cmd.Get().c_str()); text_length = cmd.GetSize(); } } else if(keypress == KEY_LEFT){ cursX--; } // 260 else if(keypress == KEY_RIGHT){ cursX++; } // 261 else if(keypress == KEY_PPAGE){ //Page up key scroll_(-(_winSizeY-2)); } else if(keypress == KEY_NPAGE){ //Page down key scroll_(_winSizeY-2); } else if(keypress == KEY_BACKSPACE){ // 263 wmove(input_window, 0, --cursX); wdelch(input_window); cmd.Pop(cursX - offset); text_length = cmd.GetSize(); } else if(keypress == KEY_DC){ // Delete character (330) //Remove character from terminal wdelch(input_window); //Remove character from cmd string cmd.Pop(cursX - offset); text_length = cmd.GetSize(); } else if(keypress == KEY_IC){ cmd.ToggleInsertMode(); } // Insert key (331) else if(keypress == KEY_HOME){ cursX = offset; } else if(keypress == KEY_END){ cursX = text_length + offset; } else if(keypress == KEY_MOUSE) { //Handle mouse events MEVENT mouseEvent; //Get information about mouse event. getmouse(&mouseEvent); switch (mouseEvent.bstate) { //Scroll up case BUTTON4_PRESSED: scroll_(-3); break; //Scroll down. (Yes the name is strange.) case REPORT_MOUSE_POSITION: scroll_(3); break; } } else if(keypress == KEY_RESIZE) { //Do nothing with the resize key } else{ in_char_((char)keypress); cmd.Put((char)keypress, cursX - offset - 1); text_length = cmd.GetSize(); } // Check for cursor too far to the left if(cursX < offset){ cursX = offset; } // Check for cursor too far to the right if(cursX > (text_length + offset)){ cursX = text_length + offset; } //Update status message if (status_window) { werase(status_window); print(status_window,statusStr.at(0).c_str()); } if (keypress != ERR) tabCount = 0; update_cursor_(); refresh_(); } return output; }
static aug_result run_BIN_(int argc, char* argv[], const char* archivename) { aug_mpool* mpool; int flags = 0; mode_t mode = 0; aug_mar* mar; int ch; switch (options_ & (READOPT_ | WRITEOPT_)) { case READOPT_: flags = AUG_RDONLY; break; case WRITEOPT_: flags = AUG_WRONLY; break; case READOPT_ | WRITEOPT_: flags = AUG_RDWR; break; } if (options_ & CREATEOPT_) { flags |= AUG_CREAT; mode = 0666; } mpool = aug_getmpool(aug_tlx); mar = aug_openmar_BIN(mpool, archivename, flags, mode); aug_release(mpool); if (!mar) { aug_perrinfo(aug_tlx, "aug_openmar() failed", NULL); return -1; } while (-1 != (ch = aug_getopt(argc, argv, OPTIONS_))) switch (ch) { case 'c': if (clear_(mar) < 0) { aug_perrinfo(aug_tlx, "failed to " CLEARTEXT_, NULL); goto fail; } break; case 'd': if (del_(mar, aug_optarg) < 0) { aug_perrinfo(aug_tlx, "failed to " DELTEXT_, NULL); goto fail; } break; case 'f': break; case 'g': if (get_(mar, aug_optarg) < 0) { aug_perrinfo(aug_tlx, "failed to " GETTEXT_, NULL); goto fail; } break; case 'i': if (insert_BIN_(mar, aug_optarg) < 0) { aug_perrinfo(aug_tlx, "failed to " INSERTTEXT_, NULL); goto fail; } break; case 'l': if (names_(mar) < 0) { aug_perrinfo(aug_tlx, "failed to " NAMESTEXT_, NULL); goto fail; } break; case 'n': size_(mar); break; case 'o': if (aug_compactmar(mar) < 0) { aug_perrinfo(aug_tlx, "failed to " COMPACTTEXT_, NULL); goto fail; } break; case 'p': if (put_BIN_(mar, aug_optarg) < 0) { aug_perrinfo(aug_tlx, "failed to " PUTTEXT_, NULL); goto fail; } break; case 't': if (list_(mar) < 0) { aug_perrinfo(aug_tlx, "failed to " LISTTEXT_, NULL); goto fail; } break; case 'x': if (extract_(mar, aug_optarg) < 0) { aug_perrinfo(aug_tlx, "failed to " EXTRACTTEXT_, NULL); goto fail; } break; case 'z': if (zero_(mar) < 0) { aug_perrinfo(aug_tlx, "failed to " ZEROTEXT_, NULL); goto fail; } break; case 'h': case '?': default: fprintf(stderr, "unexpected option [-%c]\n", aug_optopt); goto fail; } aug_release(mar); return 0; fail: aug_release(mar); return -1; }
ElementDB::~ElementDB() { clear_(); }
Part::Part() { clear_(); }
// destructor DataValue::~DataValue() { clear_(); }
void Resampler::clear() { write_pos = 0; clear_(); }
ResidueDB::~ResidueDB() { clear_(); }
LOD::LOD() { clear_(); }