struct s_table* init_hash_table() { int i; /*allocs the table*/ tm_table= (struct s_table*)shm_malloc( sizeof( struct s_table ) ); if ( !tm_table) { LOG(L_ERR, "ERROR: init_hash_table: no shmem for TM table\n"); goto error0; } memset( tm_table, 0, sizeof (struct s_table ) ); /* try first allocating all the structures needed for syncing */ if (lock_initialize()==-1) goto error1; /* inits the entrys */ for( i=0 ; i<TABLE_ENTRIES; i++ ) { init_entry_lock( tm_table, (tm_table->entrys)+i ); tm_table->entrys[i].next_label = rand(); } return tm_table; error1: free_hash_table( ); error0: return 0; }
/*------------------------------------------------------------------------ * * Apply default policy to gcpu * *------------------------------------------------------------------------ */ void guest_cpu_control_setup(guest_cpu_handle_t gcpu) { MON_ASSERT(gcpu); lock_initialize(&(gcpu->vmexit_setup.lock)); gcpu_minimal_controls(gcpu); msr_vmexit_activate(gcpu); io_vmexit_activate(gcpu); }
int fcnotify_initialize(fcnotify_context * pnotify, unsigned short islocal, void * paplist, alloc_context * palloc, unsigned int filecount TSRMLS_DC) { int result = NONFATAL; unsigned short locktype = LOCK_TYPE_SHARED; fcnotify_header * header = NULL; unsigned int msize = 0; _ASSERT(pnotify != NULL); _ASSERT(paplist != NULL); _ASSERT(palloc != NULL); _ASSERT(palloc->memaddr != NULL); if(islocal) { locktype = LOCK_TYPE_LOCAL; pnotify->islocal = islocal; } pnotify->islocal = islocal; pnotify->fcaplist = paplist; pnotify->fcalloc = palloc; pnotify->processid = WCG(fmapgdata)->pid; pnotify->fcmemaddr = palloc->memaddr; pnotify->lscavenge = GetTickCount(); /* Get memory for fcnotify header */ msize = sizeof(fcnotify_header) + (filecount - 1) * sizeof(size_t); pnotify->fcheader = (fcnotify_header *)alloc_get_cacheheader(pnotify->fcalloc, msize, CACHE_TYPE_FCNOTIFY); if(pnotify->fcheader == NULL) { result = FATAL_FCNOTIFY_INITIALIZE; goto Finished; } header = pnotify->fcheader; /* Create reader writer lock for the file change notification hashtable */ result = lock_create(&pnotify->fclock); if(FAILED(result)) { goto Finished; } result = lock_initialize(pnotify->fclock, "FILE_CHANGE_NOTIFY", 1, locktype, LOCK_USET_SREAD_XWRITE, &header->rdcount TSRMLS_CC); if(FAILED(result)) { goto Finished; } /* Create IO completion port */ pnotify->port_handle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)0, 0); if(pnotify->port_handle == NULL) { result = FATAL_FCNOTIFY_INITIALIZE; goto Finished; } /* Create listener thread */ pnotify->listen_thread = CreateThread(NULL, 0, change_notification_thread, (void *)pnotify, 0, NULL); if(pnotify->listen_thread == NULL) { result = FATAL_FCNOTIFY_INITIALIZE; goto Finished; } /* Create pidhandles hashtable */ pnotify->pidhandles = (HashTable *)alloc_pemalloc(sizeof(HashTable)); if(pnotify->pidhandles == NULL) { result = FATAL_OUT_OF_LMEMORY; goto Finished; } zend_hash_init(pnotify->pidhandles, 0, NULL, NULL, 1); Finished: if(FAILED(result)) { dprintimportant("failure %d in fcnotify_initialize", result); _ASSERT(result > WARNING_COMMON_BASE); if(pnotify->listen_thread != NULL) { CloseHandle(pnotify->listen_thread); pnotify->listen_thread = NULL; } if(pnotify->port_handle != NULL) { CloseHandle(pnotify->port_handle); pnotify->port_handle = NULL; } if(pnotify->fclock != NULL) { lock_terminate(pnotify->fclock); lock_destroy(pnotify->fclock); pnotify->fclock = NULL; } if(pnotify->pidhandles != NULL) { zend_hash_destroy(pnotify->pidhandles); alloc_pefree(pnotify->pidhandles); pnotify->pidhandles = NULL; } pnotify->fcaplist = NULL; pnotify->fcheader = NULL; pnotify->fcalloc = NULL; } return result; }
API void ikgt_lock_initialize(ikgt_lock_t *lock) { lock_initialize((mon_lock_t *)lock); }
int fcache_initialize(fcache_context * pfcache, unsigned short islocal, unsigned short cachekey, unsigned int cachesize, unsigned int maxfsize TSRMLS_DC) { int result = NONFATAL; size_t size = 0; fcache_header * header = NULL; unsigned short mapclass = FILEMAP_MAP_SRANDOM; unsigned short locktype = LOCK_TYPE_SHARED; unsigned char isfirst = 1; char evtname[ MAX_PATH]; dprintverbose("start fcache_initialize"); _ASSERT(pfcache != NULL); _ASSERT(cachekey != 0); _ASSERT(cachesize >= FCACHE_SIZE_MINIMUM && cachesize <= FCACHE_SIZE_MAXIMUM); _ASSERT(maxfsize >= FILE_SIZE_MINIMUM && maxfsize <= FILE_SIZE_MAXIMUM); /* Initialize memory map to store code files */ result = filemap_create(&pfcache->pfilemap); if(FAILED(result)) { goto Finished; } pfcache->cachekey = cachekey; if(islocal) { mapclass = FILEMAP_MAP_LRANDOM; locktype = LOCK_TYPE_LOCAL; pfcache->islocal = islocal; } /* shmfilepath = NULL to use page file for shared memory */ result = filemap_initialize(pfcache->pfilemap, FILEMAP_TYPE_FILECONTENT, cachekey, mapclass, cachesize, NULL TSRMLS_CC); if(FAILED(result)) { goto Finished; } pfcache->memaddr = (char *)pfcache->pfilemap->mapaddr; size = filemap_getsize(pfcache->pfilemap TSRMLS_CC); /* Create allocator for filecache segment */ result = alloc_create(&pfcache->palloc); if(FAILED(result)) { goto Finished; } /* initmemory = 1 for all page file backed shared memory allocators */ result = alloc_initialize(pfcache->palloc, islocal, "FILECONTENT_SEGMENT", cachekey, pfcache->memaddr, size, 1 TSRMLS_CC); if(FAILED(result)) { goto Finished; } /* Get memory for cache header */ pfcache->header = (fcache_header *)alloc_get_cacheheader(pfcache->palloc, sizeof(fcache_header), CACHE_TYPE_FILECONTENT); if(pfcache->header == NULL) { result = FATAL_FCACHE_INITIALIZE; goto Finished; } header = pfcache->header; /* Create xread xwrite lock for the filecache */ result = lock_create(&pfcache->prwlock); if(FAILED(result)) { goto Finished; } result = lock_initialize(pfcache->prwlock, "FILECONTENT_CACHE", cachekey, locktype, LOCK_USET_XREAD_XWRITE, NULL TSRMLS_CC); if(FAILED(result)) { goto Finished; } result = lock_getnewname(pfcache->prwlock, "FCACHE_INIT", evtname, MAX_PATH); if(FAILED(result)) { goto Finished; } pfcache->hinitdone = CreateEvent(NULL, TRUE, FALSE, evtname); if(pfcache->hinitdone == NULL) { result = FATAL_FCACHE_INIT_EVENT; goto Finished; } if(GetLastError() == ERROR_ALREADY_EXISTS) { _ASSERT(islocal == 0); isfirst = 0; /* Wait for other process to initialize completely */ WaitForSingleObject(pfcache->hinitdone, INFINITE); } /* Initialize the fcache_header if its not initialized already */ if(islocal || isfirst) { lock_writelock(pfcache->prwlock); header->mapcount = 1; header->itemcount = 0; header->hitcount = 0; header->misscount = 0; SetEvent(pfcache->hinitdone); lock_writeunlock(pfcache->prwlock); } else { /* Increment the mapcount */ InterlockedIncrement(&header->mapcount); } /* Keep maxfsize in fcache_context */ pfcache->maxfsize = maxfsize * 1024; Finished: if(FAILED(result)) { dprintimportant("failure %d in fcache_initialize", result); _ASSERT(result > WARNING_COMMON_BASE); if(pfcache->palloc != NULL) { alloc_terminate(pfcache->palloc); alloc_destroy(pfcache->palloc); pfcache->palloc = NULL; } if(pfcache->pfilemap != NULL) { filemap_terminate(pfcache->pfilemap); filemap_destroy(pfcache->pfilemap); pfcache->pfilemap = NULL; } if(pfcache->prwlock != NULL) { lock_terminate(pfcache->prwlock); lock_destroy(pfcache->prwlock); pfcache->prwlock = NULL; } if(pfcache->hinitdone != NULL) { CloseHandle(pfcache->hinitdone); pfcache->hinitdone = NULL; } } dprintverbose("end fcache_initialize"); return result; }
static int mod_init(void) { unsigned int timer_sets,set; unsigned int roundto_init; LM_INFO("TM - initializing...\n"); /* checking if we have sufficient bitmap capacity for given maximum number of branches */ if (MAX_BRANCHES+1>31) { LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n", MAX_BRANCHES ); return -1; } fix_flag_name(minor_branch_flag_str, minor_branch_flag); minor_branch_flag = get_flag_id_by_name(FLAG_TYPE_BRANCH, minor_branch_flag_str); if (minor_branch_flag!=-1) { if (minor_branch_flag > (8*sizeof(int)-1)) { LM_CRIT("invalid minor branch flag\n"); return -1; } minor_branch_flag = 1<<minor_branch_flag; } else { minor_branch_flag = 0; } /* if statistics are disabled, prevent their registration to core */ if (tm_enable_stats==0) #ifdef STATIC_TM tm_exports.stats = 0; #else exports.stats = 0; #endif if (init_callid() < 0) { LM_CRIT("Error while initializing Call-ID generator\n"); return -1; } /* how many timer sets do we need to create? */ timer_sets = (timer_partitions<=1)?1:timer_partitions ; /* try first allocating all the structures needed for syncing */ if (lock_initialize( timer_sets )==-1) return -1; /* building the hash table*/ if (!init_hash_table( timer_sets )) { LM_ERR("initializing hash_table failed\n"); return -1; } /* init static hidden values */ init_t(); if (!tm_init_timers( timer_sets ) ) { LM_ERR("timer init failed\n"); return -1; } /* the ROUNDTO macro taken from the locking interface */ #ifdef ROUNDTO roundto_init = ROUNDTO; #else roundto_init = sizeof(void *); #endif while (roundto_init != 1) { tm_timer_shift++; roundto_init >>= 1; } LM_DBG("timer set shift is %d\n", tm_timer_shift); /* register the timer functions */ for ( set=0 ; set<timer_sets ; set++ ) { if (register_timer( "tm-timer", timer_routine, (void*)(long)set, 1, TIMER_FLAG_DELAY_ON_DELAY) < 0 ) { LM_ERR("failed to register timer for set %d\n",set); return -1; } if (register_utimer( "tm-utimer", utimer_routine, (void*)(long)set, 100*1000, TIMER_FLAG_DELAY_ON_DELAY)<0) { LM_ERR("failed to register utimer for set %d\n",set); return -1; } } if (uac_init()==-1) { LM_ERR("uac_init failed\n"); return -1; } if (init_tmcb_lists()!=1) { LM_CRIT("failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); if (init_twrite_sock() < 0) { LM_ERR("failed to create socket\n"); return -1; } /* register post-script clean-up function */ if (register_script_cb( do_t_cleanup, POST_SCRIPT_CB|REQ_TYPE_CB, 0)<0 ) { LM_ERR("failed to register POST request callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQ_TYPE_CB , 0)<0 ) { LM_ERR("failed to register PRE request callback\n"); return -1; } if(register_pv_context("request", tm_pv_context_request)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if(register_pv_context("reply", tm_pv_context_reply)< 0) { LM_ERR("Failed to register pv contexts\n"); return -1; } if ( parse_avp_spec( &uac_ctx_avp, &uac_ctx_avp_id)<0 ) { LM_ERR("failed to register AVP name <%s>\n",uac_ctx_avp.s); return -1; } if ( register_async_script_handlers( t_handle_async, t_resume_async )<0 ) { LM_ERR("failed to register async handler to core \n"); return -1; } return 0; }
void lock_initialize_read_write_lock(VMM_READ_WRITE_LOCK* lock) { (void)lock; lock_initialize(&lock->lock); lock->readers = 0; }