int main(int argc, char** argv) { lock_t m[2]; pthread_t alice, bob; if (INIT(m)) { fprintf(stderr, "Failed to create first mutex.\n"); return -1; } if (INIT(m + 1)) { fprintf(stderr, "Failed to create second mutex.\n"); return -1; } if (pthread_create(&alice, NULL, (void *(*)(void*))alice_main, m)) { fprintf(stderr, "Failed to start alice.\n"); return -1; } if (pthread_create(&bob, NULL, (void *(*)(void*))bob_main, m)) { fprintf(stderr, "Failed to start bob.\n"); return -1; } pthread_join(alice, NULL); pthread_join(bob, NULL); DESTROY(m); DESTROY(m + 1); return 0; }
void RunGame( int load) { game g = NULL; if(load) { g = LoadGame(); } else { g = NewGame(); } if(g==NULL) { return; } wrefresh(g->arena); wrefresh(g->status); if(g!=NULL) { if(g->pc) g->print(g->pc); creature G = CreateCreature(g); G = g->ZombieListHead; while(G) { g->print(G->Character); G = G->Next; } PrintAllBuildings(g->gameMap, g->pc->pos); PlayLoop(g); if(G) { PurgeCreatureNode(G); DESTROY(G); } PurgeGame(g); DESTROY(g); } }
void Scene::shRotateAllLights( const Matrix& matrixRotation ) { DESTROY( spRotated ) ; // destroy the old one before making the new one. SHVector* summedLight = sumAllLights() ; // rotate the summed light spRotated = summedLight->rotate( matrixRotation ) ; DESTROY( summedLight ) ; // after i rotate it i only need the rotated result }
void Scene::clearEntireScene() { for( UINT i = 0 ; i < shapes.size() ; i++ ) DESTROY( shapes[i] ); shapes.clear() ; DESTROY( spExact ) ; DESTROY( spMesh ) ; DESTROY( spAll ) ; }
static void configrow_object_free (ConfigRow *row) { ASSERT (row != NULL); FREE (row->tag); DESTROY (ConfigPair, row->pair_head); DESTROY (ConfigVector, row->vector_head); FREE (row); }
BD_t * crashsim_bd(BD_t * disk, uint32_t threshold) { struct crashsim_info * info; BD_t * bd; info = malloc(sizeof(*info)); if(!info) return NULL; bd = &info->my_bd; info->blocks = hash_map_create(); if(!info->blocks) { free(info); return NULL; } BD_INIT(bd, crashsim_bd); info->bd = disk; info->threshold = threshold; info->crashed = 0; info->absorbed = 0; info->total = 0; bd->blocksize = disk->blocksize; bd->numblocks = disk->numblocks; bd->atomicsize = disk->atomicsize; bd->level = disk->level; bd->graph_index = disk->graph_index + 1; if(bd->graph_index >= NBDINDEX) { DESTROY(bd); return NULL; } if(modman_add_anon_bd(bd, __FUNCTION__)) { DESTROY(bd); return NULL; } if(modman_inc_bd(disk, bd, NULL) < 0) { modman_rem_bd(bd); DESTROY(bd); return NULL; } printf("Crash simulator block device initialized (threshold %u)\n", threshold); return bd; }
BD_t * block_resizer_bd(BD_t * disk, uint16_t blocksize) { struct resize_info * info; uint16_t original_size; BD_t * bd; original_size = disk->blocksize; /* make sure it's an even multiple of the block size */ if(blocksize % original_size) return NULL; /* block resizer not needed */ if(blocksize == original_size) return NULL; info = malloc(sizeof(*info)); if(!info) return NULL; bd = &info->my_bd; BD_INIT(bd, block_resizer_bd); info->bd = disk; info->original_size = original_size; bd->blocksize = blocksize; info->merge_count = blocksize / original_size; bd->atomicsize = disk->atomicsize; bd->numblocks = disk->numblocks / info->merge_count; bd->level = disk->level; bd->graph_index = disk->graph_index + 1; if(bd->graph_index >= NBDINDEX) { DESTROY(bd); return NULL; } if(modman_add_anon_bd(bd, __FUNCTION__)) { DESTROY(bd); return NULL; } if(modman_inc_bd(disk, bd, NULL) < 0) { modman_rem_bd(bd); DESTROY(bd); return NULL; } return bd; }
int main(int argc, char * argv[]) { char input_file[100]; char lookup_file[100]; lpm_root * root = NULL; if(argc != 4) { puts("./alg -v4/6 default_rule input_file"); return 1; } ipv = strcmp("-v6", argv[1]) == 0 ? 6 : 4; sprintf(input_file, "./input/IPv%d/%s", ipv, argv[3]); sprintf(lookup_file, "./input/IPv%d/lookup", ipv); default_rule = atoi(argv[2]); root = INIT(default_rule); fillTable(root, input_file); printf("%lf\n", lookup(root, lookup_file)); DESTROY(root); }
/* Уничтожение буфера. Функция вызывается только из внутренних задач.*/ static void combuf_destroy(const combuf_t combuf) { ASSERT1(CHECK_COMBUF(combuf), "invalid combuf = %u", combuf); /* Пометить буфер для удаления */ DESTROY(combuf); /* Если буфер последний в очереди, то удаляем его и * следующие буферы в очереди ( если они помечены для удаления ) */ if (IS_BACK(combuf)) { cb_store_t _busy; cb_store_t cb_size; do { cb_size = SIZE(back); back = SUM(back, cb_size); __critical_enter(); busy -= cb_size; _busy = busy; __critical_exit(); } while ((0 < _busy) && IS_DESTROYED(back)); } }
MethodRegex::~MethodRegex() { for (std::vector<wxRegEx *>::iterator i = m_regex.begin(); i != m_regex.end(); ++i) { DESTROY(*i); } }
MenuState::~MenuState() { if (m_States != 0) { DESTROY(m_States); } }
void DestroyZombies( game g ) { if( g == NULL ) return; if( g->ZombieListHead == NULL ) return; while( g->ZombieListHead->Next != NULL ) { creature G = g->ZombieListHead->Next; CutCreatureNode( g->ZombieListHead, G ); if(G != NULL) { PurgeCreatureNode( G ); DESTROY(G); } } if( g->ZombieListHead != NULL ) { PurgeCreatureNode( g->ZombieListHead ); DESTROY( g->ZombieListHead ); } }
void CBlock::clear() { for (auto iter = blockContents.begin(); iter != blockContents.end();) { DESTROY(iter->second); iter++; } blockContents.clear(); }
Group::Group() : Node() { Member *name = FindMember(wxT("Name")); DeleteMember(name); DESTROY(name); }
ShaderObject::~ShaderObject() { for (std::map<wxString, Method *>::iterator i = m_methods.begin(); i != m_methods.end(); ++i) { DESTROY(i->second); } }
static void config_method_destroy (Config * c) { ASSERT (c != NULL); DESTROY (ConfigBlock, c->block_head); config_object_free (c); }
void RealFieldValueCache::clear() { if (find_element_xi_cache) { DESTROY(Computed_field_find_element_xi_cache)(&find_element_xi_cache); find_element_xi_cache = 0; } FieldValueCache::clear(); }
AStar::~AStar() { DESTROY( finalPath ) ; // delete the object, // but no necessarily the Graph * objects // that were passed in, because someone else // may still be using them. // DO NOT DELETE THE 'graph*' object! // It belongs to someone else. }
void DeleteChild(wxXmlNode& node, const wxString& name) { wxXmlNode *child = FindChild(node, name); if (child != NULL) { node.RemoveChild(child); DESTROY(child); } }
void LoadPlayerCharacter( game g, chr c ) { if( g == NULL || c == NULL ) return; if( g->pc ) { // Start from scratch ... PurgeCharacter( g->pc ); DESTROY(g->pc); } g->pc = CreateCharacter(g); CopyCharacter( g->pc, c ); wrefresh(g->arena); }
RealFieldValueCache::~RealFieldValueCache() { if (find_element_xi_cache) { DESTROY(Computed_field_find_element_xi_cache)(&find_element_xi_cache); find_element_xi_cache = 0; } delete[] values; delete[] derivatives; }
static void configblock_method_destroy (ConfigBlock * block) { ASSERT (block != NULL); DESTROY (ConfigRow, block->row_head); SINGLE_UNLINK (ConfigBlock, block->cfg->block_head, block->cfg->block_tail, block); configblock_object_free (block); }
void vm_destroy(struct vmctx *vm) { assert(vm != NULL); if (vm->fd >= 0) close(vm->fd); DESTROY(vm->name); free(vm); }
/***************************************************************************//** * Command modifier function which converts field into type 'determinant' * (if it is not already) and allows its contents to be modified. */ int define_Computed_field_type_determinant(struct Parse_state *state, void *field_modify_void, void *computed_field_matrix_operators_package_void) { int return_code; ENTER(define_Computed_field_type_determinant); USE_PARAMETER(computed_field_matrix_operators_package_void); Computed_field_modify_data *field_modify = reinterpret_cast<Computed_field_modify_data*>(field_modify_void); if (state && field_modify) { return_code = 1; cmzn_field_id source_field = 0; if (NULL != field_modify->get_field() && (computed_field_determinant_type_string == Computed_field_get_type_string(field_modify->get_field()))) { source_field = cmzn_field_get_source_field(field_modify->get_field(), 1); } Option_table *option_table = CREATE(Option_table)(); Option_table_add_help(option_table, "Creates a field returning the scalar real determinant of a square matrix. " "Only supports 1, 4 (2x2) and 9 (3x3) component source fields."); struct Set_Computed_field_conditional_data set_source_field_data = { Computed_field_is_square_matrix, /*user_data*/0, field_modify->get_field_manager() }; Option_table_add_entry(option_table, "field", &source_field, &set_source_field_data, set_Computed_field_conditional); return_code = Option_table_multi_parse(option_table, state); if (return_code) { return_code = field_modify->update_field_and_deaccess( cmzn_fieldmodule_create_field_determinant(field_modify->get_field_module(), source_field)); } DESTROY(Option_table)(&option_table); if (source_field) { cmzn_field_destroy(&source_field); } } else { display_message(ERROR_MESSAGE, "define_Computed_field_type_determinant. Invalid argument(s)"); return_code=0; } LEAVE; return (return_code); }
CFS_t * file_hiding_cfs(CFS_t * frontend_cfs) { file_hiding_state_t * state; CFS_t * cfs; if (!frontend_cfs) return NULL; state = malloc(sizeof(*state)); if (!state) return NULL; cfs = &state->cfs; CFS_INIT(cfs, file_hiding); OBJMAGIC(cfs) = FILE_HIDING_MAGIC; state->hide_table = vector_create(); if (!state->hide_table) goto error_state; state->frontend_cfs = frontend_cfs; state->nopen = 0; if (modman_add_anon_cfs(cfs, __FUNCTION__)) { DESTROY(cfs); return NULL; } if(modman_inc_cfs(frontend_cfs, cfs, NULL) < 0) { modman_rem_cfs(cfs); DESTROY(cfs); return NULL; } return cfs; error_state: free(state); return NULL; }
bool CClientNet::Start(unsigned short port) { if (!CServer::Start(port)) return false; DESTROY(m_agent); m_Connect->addPeer(ServerUID, m_Addr); m_agent = new CPeerConnection(m_Connect->getSocket()); if (!m_agent->isValidSocket()) return false; m_agent->setPeer(m_Addr); return isRunning(); }
void Scene::shAddInterreflections() { // ADD INTERREFLECTIONS TOGETHER. for( int i = 0 ; i < shapes.size() ; i++ ) { // Add the interreflection stage SH functions to the 1st stage functions for( int j=0; j < shapes[i]->meshGroup->meshes.size() ; j++ ) { Mesh *mesh = shapes[i]->meshGroup->meshes[j] ; for( int v = 0 ; v < mesh->verts.size() ; v++ ) { AllVertex& vertex = mesh->verts[ v ] ; //if( !vertex.shDiffuseAmbient ) { error ("No ambient shproj" ) ; continue ; } //if( !vertex.shDiffuseInterreflected ) { error( "No interreflected shproj" ) ; continue ; } // SHOW ONLY THE SHADOWED, DIRECT LIGHT //vertex.shDiffuseSummed->add( vertex.shDiffuseAmbient ) ; // SHOW ONLY THE INTERREFLECTIONS //vertex.shDiffuseSummed->add( vertex.shDiffuseInterreflected ) ; // add the ambient occlusion and interreflection sh projs vertex.shDiffuseSummed->add( vertex.shDiffuseAmbient )->add( vertex.shDiffuseInterreflected ) ; // CLEAN UP, don't need these anymore DESTROY( vertex.shDiffuseAmbient ) ; DESTROY( vertex.shDiffuseInterreflected ) ; // Just overwrite the specular with the interreflected part. vertex.shSpecularMatrix->add( vertex.shSpecularMatrixInterreflected ) ; // CLEAN UP, don't need these anymore DESTROY( vertex.shSpecularMatrixInterreflected ) ; } } } }
BD_t * partition_bd(BD_t * disk, uint32_t start, uint32_t length) { struct partition_info * info; BD_t * bd; info = malloc(sizeof(*info)); if(!info) return NULL; bd = &info->my_bd; BD_INIT(bd, partition_bd); info->bd = disk; info->start = start; bd->blocksize = disk->blocksize; bd->numblocks = length; bd->atomicsize = disk->atomicsize; bd->level = disk->level; bd->graph_index = disk->graph_index + 1; if(bd->graph_index >= NBDINDEX) { DESTROY(bd); return NULL; } if(modman_add_anon_bd(bd, __FUNCTION__)) { DESTROY(bd); return NULL; } if(modman_inc_bd(disk, bd, NULL) < 0) { modman_rem_bd(bd); DESTROY(bd); return NULL; } return bd; }
END_COMPONENT_UPDATE void tv_widget_textbox_set_text(tv_widget_textbox *textbox, tvchar *text) { tv_animation* a = ((tv_widget*)textbox)->animation; if(a) { if(((tv_component*)a)->id != tv_animation_id()) { return; } /* delete the old text animation (if there is one) */ DESTROY(a); } tv_widget_set_model((tv_widget*)textbox, tv_gui_model_text(text, 80, textbox->color)); }
bool GraphCanvas::CopyAsMetafile() { #ifdef _WIN32 wxMetafileDC mdc; Paint(mdc); wxMetafile *meta = mdc.Close(); bool ok = meta->SetClipboard(); DESTROY(meta); return ok; #else return false; #endif }