void test_resize(){ ArrayUtil util = create(4, 5); int * list_array = (int *)(util.base); list_array[0] = 10; list_array[1] = 20; list_array[2] = 30; list_array[3] = 40; list_array[4] = 50; assert(util.length == 5); ArrayUtil resized_util = resize(util, 7); assert(resized_util.length = 7); int * resized_list_array = (int *)(resized_util.base); assert(resized_list_array[4] == 50); assert(resized_list_array[5] == 0); assert(util.length == 5); assert(list_array[4] == 50); printf("Array element is not changed\n"); dispose(util); }
ev_err_t ev_vbuff_set_capacity(ev_vbuff *v, size_t num_bytes) { if( v && num_bytes ) { if( v->size < num_bytes ) { dispose(v); } glGenBuffers(1, &v->id); if( !v->id ) return EV_FAIL; ev_vbuff_bind(v); v->buff = ev_malloc(num_bytes); if(!v->buff) return EV_NOMEM; memset(v->buff, 0, num_bytes); glBufferData( GL_ARRAY_BUFFER, num_bytes, v->buff, GL_DYNAMIC_DRAW); v->size = num_bytes; return EV_OK; } return EV_FAIL; }
void AspModel::initFromFile(std::string filename, const uint32_t importFlags) { if (filename.empty()) { SiegeThrow(Exception, "No filename provided for AspModel::initFromFile()!"); } std::ifstream file; if (!utils::filesys::tryOpen(file, filename, std::ifstream::binary)) { SiegeThrow(Exception, "Failed to open ASP file \"" << filename << "\": '" << utils::filesys::getLastFileError() << "'."); } size_t fileSizeBytes = 0; utils::filesys::queryFileSize(filename, fileSizeBytes); if (fileSizeBytes == 0) { SiegeWarn("ASP file \"" << filename << "\" appears to be empty..."); // Make this an empty model. // NOTE: Should this be changed to an error instead? dispose(); srcFileName = std::move(filename); return; } ByteArray fileContents(fileSizeBytes); if (!file.read(reinterpret_cast<char *>(fileContents.data()), fileContents.size())) { SiegeThrow(Exception, "Failed to read " << utils::formatMemoryUnit(fileContents.size()) << " from ASP mode file \"" << filename << "\"!"); } initFromMemory(std::move(fileContents), importFlags, std::move(filename)); }
static int set_ttydev(struct cfgdata_t *cfgdata, char *value) { const char str_dev[] = "/dev/"; char *p; /* Check value for 'tty[0-9]' */ if ( ! ( ('t' == value[0]) && ('t' == value[1]) && ('y' == value[2]) && (value[3] > '0') && (value[3] < '9') ) ) return 0; /* Prepend '/dev/' to tty name (value) */ p = malloc(sizeof(str_dev)+strlen(value)); if (NULL == p) { DPRINTF("Can't allocate memory to store tty device name '/dev/%s'", value); return -1; } dispose(cfgdata->ttydev); cfgdata->ttydev = p; strcpy(cfgdata->ttydev, str_dev); strcat(cfgdata->ttydev, value); return 0; }
CL_GL1FrameBufferProvider::~CL_GL1FrameBufferProvider() { dispose(); CL_SharedGCData::remove_disposable(this); }
DocumentSourceCursor::~DocumentSourceCursor() { dispose(); }
MWInfoPage::~MWInfoPage() { dispose(); }
WorkerContextExecutionProxy::~WorkerContextExecutionProxy() { dispose(); }
Viewport::~Viewport() { dispose(); }
virtual ~MPSegment(){dispose();};
SpatialReference::~SpatialReference() { dispose(); }
InputDeviceProvider_Win32Hid::~InputDeviceProvider_Win32Hid() { dispose(); }
SpriteNumber::~SpriteNumber(){ dispose(); }
/* ### Pack: this routine has changed */ static int Send_new_packets( int num_allowed ) { packet_header *pack_ptr; scatter *scat_ptr; int pack_entry; int num_sent; int ret; num_sent = 0; while( num_sent < num_allowed ) { /* check if down queue is empty */ if( Down_queue_ptr->num_mess == 0 ) break; /* initialize packet_header */ pack_ptr = new(PACK_HEAD_OBJ); scat_ptr = Down_queue_ptr->first->mess; pack_ptr->type = Down_queue_ptr->first->type; pack_ptr->proc_id = My.id; pack_ptr->memb_id = Memb_id(); pack_ptr->seq = Highest_seq+1; Highest_seq++; pack_ptr->fifo_seq = Highest_fifo_seq+1; Highest_fifo_seq++; pack_ptr->data_len = scat_ptr->elements[ Down_queue_ptr->cur_element].len; Send_pack.elements[1].buf = scat_ptr->elements[ Down_queue_ptr->cur_element].buf; Down_queue_ptr->cur_element++; if( Down_queue_ptr->cur_element < scat_ptr->num_elements ) { /* not last packet in message */ pack_ptr->packet_index = Down_queue_ptr->cur_element; }else if( Down_queue_ptr->cur_element == scat_ptr->num_elements ){ down_link *tmp_down; /* last packet in message */ pack_ptr->packet_index = -scat_ptr->num_elements; tmp_down = Down_queue_ptr->first; Down_queue_ptr->first = Down_queue_ptr->first->next; Down_queue_ptr->cur_element = 0; Down_queue_ptr->num_mess--; dispose( tmp_down->mess ); dispose( tmp_down ); if( Down_queue_ptr->num_mess < WATER_MARK ) Sess_unblock_users_level(); }else{ Alarm( EXIT, "Send_new_packets: error in packet index: %d %d\n", Down_queue_ptr->cur_element,scat_ptr->num_elements ); } Send_pack.elements[0].buf = (char *) pack_ptr; Send_pack.elements[1].len = pack_ptr->data_len; #if 1 ret = Net_queue_bcast( &Send_pack ); #else ret = Net_bcast( &Send_pack ); #endif if( ret > 0 ) { num_sent++; } pack_entry = pack_ptr->seq & PACKET_MASK; if( Packets[pack_entry].exist ) Alarm( EXIT, "Send_new_packets: created packet %d already exist %d\n", pack_ptr->seq, Packets[pack_entry].exist ); /* insert new created packet */ Packets[pack_entry].head = pack_ptr; Packets[pack_entry].body = (packet_body *)Send_pack.elements[1].buf; Packets[pack_entry].exist = 1; Packets[pack_entry].proc_index = My_index; Alarm( PROTOCOL, "Send_new_packets: packet %d sent and inserted \n", pack_ptr->seq ); } ret = Net_flush_bcast(); if( ret > 0 ) { num_sent++; } return ( num_sent ); }
void Prot_handle_token(channel fd, int dummy, void *dummy_p) { int new_ptr; int num_retrans, num_allowed, num_sent; int flow_control; char *new_rtr; ring_rtr *ring_rtr_ptr; int32 rtr_proc_id; int16 rtr_seg_index; int32 val; int retrans_allowed; /* how many of my retrans are allowed on token */ int i, ret; /* int r1,r2;*/ ret = Net_recv_token( fd, &New_token ); /* from another monitor component */ if( ret == 0 ) return; /* delete random r1 = ((-My.id)%17)+3; r2 = get_rand() % (r1+3 ); if ( r2 == 0 ) return; */ Alarm( DEBUG, "Received Token\n"); /* check if it is a regular token */ if( Is_form( Token->type ) ) { Alarm(PROTOCOL, "it is a Form Token.\n"); Memb_handle_token( &New_token ); return; } /* The Veto property for tokens - swallow this token */ if( ! Memb_token_alive() ) { Alarm(PROTOCOL, "Prot_handle_token: Veto Property. Memb not alive.\n"); return; } if( ret != sizeof(token_header) + Token->rtr_len ) { Alarm( PRINT, "Prot_handle_token: recv token len is %d, should be %d\n", ret,sizeof(token_header) + Token->rtr_len ); return; } if( !Same_endian( Token->type ) ) Flip_token_body( New_token.elements[1].buf, Token ); /* Deal with wrapping seq values (2^32) by triggering a membership by dropping the token */ if( (Memb_state() != EVS ) && (Token->seq > MAX_WRAP_SEQUENCE_VALUE ) ) { Alarm( PRINT, "Prot_handle_token: Token Sequence number (%ld) approaching 2^31 so trigger membership to reset it.\n", Token->seq); return; } if( Conf_leader( Memb_active_ptr() ) == My.id ) { if( Get_arq(Token->type) != Get_arq(Last_token->type) ) { Alarm( PROTOCOL, "Prot_handle_token: leader swallowing token %d %d %d\n", Get_arq(Token->type),Get_retrans(Token->type),Get_arq(Last_token->type) ); /* received double token - swallow it */ return; } }else{ if( Get_arq(Token->type) == Get_arq(Last_token->type) ) { if( Get_retrans(Token->type) > Get_retrans(Last_token->type) ) { val = Get_retrans(Token->type); Last_token->type = Set_retrans(Last_token->type,val); /* asked to send token again (almost lost) */ Alarm( PROTOCOL, "Prot_handle_token: not leader, asked to retrans %d %d\n", Get_arq(Token->type), val ); Prot_token_hurry(); }else{ Alarm( PROTOCOL, "Prot_handle_token: not leader, swallow same token %d %d\n", Get_arq(Token->type), Get_retrans(Token->type) ); } return; } else if ( Get_arq(Token->type) != ( ( Get_arq( Last_token->type ) + 1 ) % 0x10 ) ) { Alarm( PROTOCOL, "Prot_handle_token: not leader, swallowing very outdated token: ARQ(%d) RETRANS(%d) vs. Last ARQ(%d)\n", Get_arq(Token->type), Get_retrans(Token->type), Get_arq(Last_token->type) ); return; } else { if ( Get_retrans(Token->type) > 0 ) { GlobalStatus.token_hurry++; } } } if( Highest_seq < Token->seq ) Highest_seq = Token->seq; /* Handle retransmissions */ num_retrans = Answer_retrans( &new_ptr, &rtr_proc_id, &rtr_seg_index ); GlobalStatus.retrans += num_retrans; new_rtr = New_token.elements[1].buf; /* Handle new packets */ flow_control = (int) Token->flow_control; num_allowed = FC_allowed( flow_control, num_retrans ); num_sent = Send_new_packets( num_allowed ); GlobalStatus.packet_sent += num_sent; /* Flow control calculations */ Token->flow_control = Token->flow_control - Last_num_retrans - Last_num_sent + num_retrans + num_sent; Last_num_retrans = num_retrans; Last_num_sent = num_sent; /* Prepare my retransmission requests */ for( i = My_aru+1; i <= Highest_seq; i++ ) { if( ! Packets[i & PACKET_MASK].exist ) break; My_aru++; } GlobalStatus.my_aru = My_aru; if( My_aru < Highest_seq ) { /* Compute how many of my retransmission requests are possible to fit */ retrans_allowed = ( sizeof( token_body ) - new_ptr - sizeof( ring_rtr ) ) / sizeof( int32 ); if( retrans_allowed > 1 ) { ring_rtr_ptr = (ring_rtr *)&new_rtr[new_ptr]; ring_rtr_ptr->memb_id = Memb_id(); ring_rtr_ptr->proc_id = rtr_proc_id; ring_rtr_ptr->seg_index = rtr_seg_index; ring_rtr_ptr->num_seq = 0; new_ptr += sizeof(ring_rtr); for( i=My_aru+1; i <= Highest_seq && retrans_allowed > 0; i++, retrans_allowed-- ) { if( ! Packets[i & PACKET_MASK].exist ) { memcpy( &new_rtr[new_ptr], &i, sizeof(int32) ); new_ptr += sizeof(int32); ring_rtr_ptr->num_seq++; } } } } if( Memb_state() == EVS ) { if( My_aru == Highest_seq ) { My_aru = Last_seq; Memb_commit(); } } Token->rtr_len = new_ptr; New_token.elements[1].len = new_ptr; /* Calculating Token->aru and Set_aru */ if( ( Token->aru == Set_aru ) || ( Token->aru_last_id == My.id ) || ( Token->aru == Token->seq ) ) { Token->aru = My_aru; Token->aru_last_id = My.id; if( My_aru < Highest_seq ) Set_aru = My_aru; else Set_aru = -1; }else if( Token->aru > My_aru ) { Token->aru = My_aru; Token->aru_last_id = My.id; Set_aru = My_aru; }else{ Set_aru = -1; } Token->proc_id = My.id; if( Memb_state() != EVS ) Token->seq = Highest_seq; if( Conf_leader( Memb_active_ptr() ) == My.id ) { val = Get_arq( Token->type ); val = (val + 1)% 0x10; Token->type = Set_arq( Token->type, val ); Token->type = Set_retrans( Token->type, 0 ); } /* Send token */ if( ! ( Conf_leader( Memb_active_ptr() ) == My.id && To_hold_token() ) ) { /* sending token */ Net_send_token( &New_token ); /* ### Bug fix for SGIs */ #ifdef ARCH_SGI_IRIX Net_send_token( &New_token ); #endif /* ARCH_SGI_IRIX */ if( Get_retrans( Token->type ) > 1 ) { /* problems */ Net_send_token( &New_token ); Net_send_token( &New_token ); } } Token_rounds++; if( Conf_leader( Memb_active_ptr() ) == My.id ) E_queue( Prot_token_hurry, 0, NULL, Hurry_timeout ); E_queue( Memb_token_loss, 0, NULL, Token_timeout ); /* calculating Aru */ if( Token->aru > Last_token->aru ) Aru = Last_token->aru; else Aru = Token->aru; if( Highest_seq == Aru ) Token_counter++; else Token_counter = 0; dispose( Last_token ); Last_token = Token; New_token.elements[0].buf = (char *) new(TOKEN_HEAD_OBJ); New_token.elements[1].len = sizeof(token_body); Token = (token_header *)New_token.elements[0].buf; /* Deliver & discard packets */ Discard_packets(); Deliver_agreed_packets(); Deliver_reliable_packets( Highest_seq-num_sent+1, num_sent ); if( Memb_state() == EVS && Token_rounds > MAX_EVS_ROUNDS ) { Alarmp( SPLOG_ERROR, PRINT, "Prot_handle_token: BUG WORKAROUND: Too many rounds in EVS state; swallowing token; state:\n" ); Alarmp( SPLOG_ERROR, PRINT, "\tAru: %d\n", Aru ); Alarmp( SPLOG_ERROR, PRINT, "\tMy_aru: %d\n", My_aru ); Alarmp( SPLOG_ERROR, PRINT, "\tHighest_seq: %d\n", Highest_seq ); Alarmp( SPLOG_ERROR, PRINT, "\tHighest_fifo_seq: %d\n", Highest_fifo_seq ); Alarmp( SPLOG_ERROR, PRINT, "\tLast_discarded: %d\n", Last_discarded ); Alarmp( SPLOG_ERROR, PRINT, "\tLast_delivered: %d\n", Last_delivered ); Alarmp( SPLOG_ERROR, PRINT, "\tLast_seq: %d\n", Last_seq ); Alarmp( SPLOG_ERROR, PRINT, "\tToken_rounds: %d\n", Token_rounds ); Alarmp( SPLOG_ERROR, PRINT, "Last Token:\n" ); Alarmp( SPLOG_ERROR, PRINT, "\ttype: 0x%x\n", Last_token->type ); Alarmp( SPLOG_ERROR, PRINT, "\ttransmiter_id: %d\n", Last_token->transmiter_id ); Alarmp( SPLOG_ERROR, PRINT, "\tseq: %d\n", Last_token->seq ); Alarmp( SPLOG_ERROR, PRINT, "\tproc_id: %d\n", Last_token->proc_id ); Alarmp( SPLOG_ERROR, PRINT, "\taru: %d\n", Last_token->aru ); Alarmp( SPLOG_ERROR, PRINT, "\taru_last_id: %d\n", Last_token->aru_last_id ); Alarmp( SPLOG_ERROR, PRINT, "\tflow_control: %d\n", Last_token->flow_control ); Alarmp( SPLOG_ERROR, PRINT, "\trtr_len: %d\n", Last_token->rtr_len ); Alarmp( SPLOG_ERROR, PRINT, "\tconf_hash: %d\n", Last_token->conf_hash ); Memb_token_loss(); } GlobalStatus.highest_seq = Highest_seq; GlobalStatus.aru = Aru; GlobalStatus.token_rounds = Token_rounds; }
void keyboard(uchar key, int x, int y){ if(key == 'q'){ dispose(); exit(0); } }
void teardown(){ dispose(queue); }
Window::~Window() { if (valid()) dispose(); }
PacketManager::~PacketManager() { if(!_disposing) dispose(); if(_workerThread.joinable()) _workerThread.join(); }
MemoryHeapBase::~MemoryHeapBase() { dispose(); }
ramActor::~ramActor() { dispose(); }
Keyboard::~Keyboard() { START(""); dispose(); END(""); }
OcclusionEngine::~OcclusionEngine(void) { dispose(); }
Mesh::~Mesh() { dispose(); }
TextureManager::~TextureManager() { dispose(); }
~Program() { dispose(); }
ScriptRunner::~ScriptRunner() { #if !ENABLE(OILPAN) dispose(); #endif }
Bitmap::~Bitmap() { dispose(); }
~b_tree() { dispose(); }
//----------------------------------------------------------------------------- //! Destructor //----------------------------------------------------------------------------- GBI::~GBI() { dispose(); }