Res ThreadRegister(Thread *threadReturn, Arena arena) { Res res; Thread thread; Ring ring; void *p; AVER(threadReturn != NULL); res = ControlAlloc(&p, arena, sizeof(ThreadStruct), /* withReservoirPermit */ FALSE); if(res != ResOK) return res; thread = (Thread)p; thread->arena = arena; RingInit(&thread->arenaRing); thread->sig = ThreadSig; thread->serial = arena->threadSerial; ++arena->threadSerial; AVERT(Thread, thread); ring = ArenaThreadRing(arena); AVER(RingCheckSingle(ring)); /* .single */ RingAppend(ring, &thread->arenaRing); *threadReturn = thread; return ResOK; }
Res ThreadRegister(Thread *threadReturn, Arena arena) { Res res; Thread thread; Ring ring; void *p; AVER(threadReturn != NULL); res = ControlAlloc(&p, arena, sizeof(ThreadStruct)); if (res != ResOK) return res; thread = (Thread)p; thread->arena = arena; RingInit(&thread->arenaRing); thread->serial = arena->threadSerial; ++arena->threadSerial; thread->alive = TRUE; thread->forking = FALSE; thread->port = mach_thread_self(); AVER(MACH_PORT_VALID(thread->port)); thread->sig = ThreadSig; AVERT(Thread, thread); ProtThreadRegister(); ring = ArenaThreadRing(arena); RingAppend(ring, &thread->arenaRing); *threadReturn = thread; return ResOK; }
symbol * HashReplace( symbol *sym ) /****************************************/ { symbol * newsym; if( sym->mod == NULL ) return sym; Ring2Prune( &sym->mod->publist, sym ); if( IS_SYM_COMMUNAL(sym) ) { sym->p.seg->isdead = TRUE; } if( !(LinkFlags & INC_LINK_FLAG) ) return sym; newsym = AddSym(); newsym->e.mainsym = sym; newsym->name = sym->name; newsym->namelen_cmp = sym->namelen_cmp; newsym->info = sym->info | SYM_DEAD | SYM_IS_ALTDEF; Ring2Append( &sym->mod->publist, newsym ); RingAppend( &sym->u.altdefs, newsym ); if( IS_SYM_NICOMDEF(sym) ) { sym->p.cdefsize = sym->p.seg->length; } return sym; }
Res ThreadRegister(Thread *threadReturn, Arena arena) { Res res; Thread thread; void *p; AVER(threadReturn != NULL); AVERT(Arena, arena); res = ControlAlloc(&p, arena, sizeof(ThreadStruct), /* withReservoirPermit */ FALSE); if(res != ResOK) return res; thread = (Thread)p; thread->id = pthread_self(); RingInit(&thread->arenaRing); thread->sig = ThreadSig; thread->serial = arena->threadSerial; ++arena->threadSerial; thread->arena = arena; thread->mfc = NULL; PThreadextInit(&thread->thrextStruct, thread->id); AVERT(Thread, thread); RingAppend(ArenaThreadRing(arena), &thread->arenaRing); *threadReturn = thread; return ResOK; }
pch_status PCHReadSegments( void ) { char *src_suffix; char *dest_suffix; char *class_name; size_t class_name_len; size_t suffix_len; size_t len; size_t old_module_len; size_t curr_module_len; size_t extra; fe_seg_id sib_id; PC_SEGMENT *curr; curr_module_len = strlen( ModuleName ); old_module_len = PCHReadUInt(); extra = 0; if( curr_module_len > old_module_len ) { extra = curr_module_len - old_module_len; } PCHRead( &seg_max, sizeof( seg_max ) ); PCHRead( &dgroup_size, sizeof( dgroup_size ) ); RingFree( &seg_list ); for(;;) { len = PCHReadUInt(); if( len == 0 ) break; curr = CMemAlloc( len + extra ); PCHRead( curr, len ); if( curr->module_prefix ) { if( old_module_len != curr_module_len ) { suffix_len = len; suffix_len -= sizeof( PC_SEGMENT ) - sizeof( char ); suffix_len -= old_module_len; src_suffix = &(curr->name[old_module_len]); dest_suffix = &(curr->name[curr_module_len]); memmove( dest_suffix, src_suffix, suffix_len ); } memcpy( curr->name, ModuleName, curr_module_len ); } curr->label = SymbolMapIndex( curr->label ); class_name_len = (size_t) curr->class_name; if( class_name_len != 0 ) { class_name = CPermAlloc( class_name_len ); PCHRead( class_name, class_name_len ); } else { class_name = NULL; } curr->class_name = class_name; RingAppend( &seg_list, curr ); } RingIterBeg( seg_list, curr ) { sib_id = (fe_seg_id) curr->sibling; if( sib_id != curr->seg_id ) { curr->sibling = segIdLookup( sib_id ); } else { curr->sibling = curr; } }
void FreeDtregObjs( // FREE OBJECT REGISTRATIONS (FUNCTION) void ) { DTREG_OBJ* curr; // - current entry RingIterBegSafe( ringDtregObj, curr ) { curr->offset = CgOffsetRw( curr->offset ); RingAppend( &ringDtregObjMod, curr ); } RingIterEndSafe( curr )
static Res BufferAbsInit(Buffer buffer, Pool pool, Bool isMutator, ArgList args) { Arena arena; AVER(buffer != NULL); AVERT(Pool, pool); AVER(BoolCheck(isMutator)); AVERT(ArgList, args); /* Superclass init */ InstInit(CouldBeA(Inst, buffer)); arena = PoolArena(pool); /* Initialize the buffer. See <code/mpmst.h> for a definition of the structure. sig and serial comes later .init.sig-serial */ buffer->arena = arena; buffer->pool = pool; RingInit(&buffer->poolRing); buffer->isMutator = isMutator; if (ArenaGlobals(arena)->bufferLogging) { buffer->mode = BufferModeLOGGED; } else { buffer->mode = 0; } buffer->fillSize = 0.0; buffer->emptySize = 0.0; buffer->alignment = PoolAlignment(pool); buffer->base = (Addr)0; buffer->initAtFlip = (Addr)0; /* In the next three assignments we really mean zero, not NULL, because the bit pattern is compared. It's pretty unlikely we'll encounter a platform where this makes a difference. */ buffer->ap_s.init = (mps_addr_t)0; buffer->ap_s.alloc = (mps_addr_t)0; buffer->ap_s.limit = (mps_addr_t)0; buffer->poolLimit = (Addr)0; buffer->rampCount = 0; /* .init.sig-serial: Now the vanilla stuff is initialized, sign the buffer and give it a serial number. It can then be safely checked in subclass methods. */ buffer->serial = pool->bufferSerial; /* .trans.mod */ ++pool->bufferSerial; SetClassOfPoly(buffer, CLASS(Buffer)); buffer->sig = BufferSig; AVERT(Buffer, buffer); /* Attach the initialized buffer to the pool. */ RingAppend(&pool->bufferRing, &buffer->poolRing); EVENT3(BufferInit, buffer, pool, BOOLOF(buffer->isMutator)); return ResOK; }
static stringblock * AllocNewBlock( stringtable *strtab ) /*******************************************************/ { stringblock *blk; _ChkAlloc( blk, sizeof(stringblock) ); blk->next = NULL; RingAppend( &strtab->data, blk ); blk->size = 0; return blk; }
static LIB_LIST *addNewLib( char *name, char priority ) { size_t len; LIB_LIST *new_lib; len = strlen( name ); new_lib = CMemAlloc( sizeof( *new_lib ) + 1 + len ); new_lib->name[0] = priority; strcpy( &(new_lib->name[1]), name ); RingAppend( &libRing, new_lib ); return( new_lib ); }
char *FNameAdd( // ADD AN FNAME char const *name ) // - name to be added { size_t len; FNAME *p; len = strlen( name ); p = CMemAlloc( offsetof( FNAME, name ) + len + 1 ); strcpy( p->name, name ); RingAppend( &fnameList, p ); return( p->name ); }
void CgInfoLibPCHRead( void ) /***************************/ { size_t len; LIB_LIST *lib_entry; CgInfoFreeLibs(); for(;;) { len = PCHReadUInt(); if( len == 0 ) break; lib_entry = CMemAlloc( len ); PCHRead( lib_entry, len ); RingAppend( &libRing, lib_entry ); } }
symbol * AddAltDef( symbol *sym, sym_info sym_type ) /*********************************************************/ { symbol * altsym; if( !(LinkFlags & INC_LINK_FLAG) ) return sym; altsym = AddSym(); SET_SYM_TYPE( altsym, sym_type ); altsym->info |= SYM_DEAD | SYM_IS_ALTDEF; altsym->mod = CurrMod; altsym->name = sym->name; altsym->e.mainsym = sym; Ring2Append( &CurrMod->publist, altsym ); RingAppend( &sym->u.altdefs, altsym ); return altsym; }
Res ThreadRegister(Thread *threadReturn, Arena arena) { Res res; Thread thread; HANDLE procHandle; BOOL b; void *p; AVER(threadReturn != NULL); AVERT(Arena, arena); res = ControlAlloc(&p, arena, sizeof(ThreadStruct), /* withReservoirPermit */ FALSE); if(res != ResOK) return res; thread = (Thread)p; /* avoid pun */ /* Duplicate handle gives us a new handle with updated privileges. * .thread.handle describes the ones needed. */ procHandle = GetCurrentProcess(); b = DuplicateHandle(procHandle, GetCurrentThread(), procHandle, &thread->handle, THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT, FALSE, 0); if(!b) return ResRESOURCE; thread->id = GetCurrentThreadId(); RingInit(&thread->arenaRing); thread->sig = ThreadSig; thread->serial = arena->threadSerial; ++arena->threadSerial; thread->arena = arena; AVERT(Thread, thread); RingAppend(ArenaThreadRing(arena), &thread->arenaRing); *threadReturn = thread; return ResOK; }
static void mapThreadRing(Ring threadRing, Ring deadRing, Bool (*func)(Thread)) { Ring node, next; AVERT(Ring, threadRing); AVERT(Ring, deadRing); AVER(FUNCHECK(func)); RING_FOR(node, threadRing, next) { Thread thread = RING_ELT(Thread, arenaRing, node); AVERT(Thread, thread); AVER(thread->alive); if (!(*func)(thread)) { thread->alive = FALSE; RingRemove(&thread->arenaRing); RingAppend(deadRing, &thread->arenaRing); } }
static DWIOBUFF *allocateBuffer(// ALLOCATE A NEW BUFFER void ) { DWIOBUFF *ctl; // - new buffer ctl = CMemAlloc( sizeof( *ctl ) ); ctl->next = NULL; ctl->disk_addr = 0; ctl->next_addr = 0; ctl->prev_addr = 0; ctl->current_offset = 0; ctl->block_num = 0; ctl->reading = 0; ctl->written = false; ctl->writing = false; RingAppend( &activeBufs, ctl ); return ctl; }
static void CleanAltDefs( symbol *sym ) /*************************************/ { symbol * testring; symbol * altsym; if( IS_SYM_ALIAS( sym ) || sym->info & SYM_DEAD || sym->u.altdefs == NULL ) return; testring = NULL; while( (altsym = RingPop( &sym->u.altdefs)) != NULL ) { if( altsym->info & SYM_KILL ) { if( altsym->info & SYM_HAS_DATA ) { altsym->u.datasym = NULL; RingAppend( &testring, altsym ); } } else if( !(altsym->info & SYM_HAS_DATA) ) { RingLookup( testring, SetNewDataSym, altsym ); } } }
static void mapThreadRing(Ring threadRing, Ring deadRing, Bool (*func)(Thread)) { Ring node, next; pthread_t self; AVERT(Ring, threadRing); AVERT(Ring, deadRing); AVER(FUNCHECK(func)); self = pthread_self(); RING_FOR(node, threadRing, next) { Thread thread = RING_ELT(Thread, arenaRing, node); AVERT(Thread, thread); AVER(thread->alive); if (!pthread_equal(self, thread->id) /* .thread.id */ && !(*func)(thread)) { thread->alive = FALSE; RingRemove(&thread->arenaRing); RingAppend(deadRing, &thread->arenaRing); } }
static Res arenaRememberSummaryOne(Globals global, Addr base, RefSet summary) { Arena arena; RememberedSummaryBlock block; AVER(summary != RefSetUNIV); arena = GlobalsArena(global); if(global->rememberedSummaryIndex == 0) { void *p; RememberedSummaryBlock newBlock; int res; res = ControlAlloc(&p, arena, sizeof *newBlock); if(res != ResOK) { return res; } newBlock = p; rememberedSummaryBlockInit(newBlock); RingAppend(GlobalsRememberedSummaryRing(global), &newBlock->globalRing); } block = RING_ELT(RememberedSummaryBlock, globalRing, RingPrev(GlobalsRememberedSummaryRing(global))); AVER(global->rememberedSummaryIndex < RememberedSummaryBLOCK); AVER(block->the[global->rememberedSummaryIndex].base == (Addr)0); AVER(block->the[global->rememberedSummaryIndex].summary == RefSetUNIV); block->the[global->rememberedSummaryIndex].base = base; block->the[global->rememberedSummaryIndex].summary = summary; ++ global->rememberedSummaryIndex; if(global->rememberedSummaryIndex >= RememberedSummaryBLOCK) { AVER(global->rememberedSummaryIndex == RememberedSummaryBLOCK); global->rememberedSummaryIndex = 0; } return ResOK; }
void CtxRegisterPostContext( // REGISTER A Note! MONITOR NESTED_POST_CONTEXT *blk ) // - registration block { RingAppend( ®istered_post_contexts, blk ); }
static void activateBuffer( // ACTIVATE A BUFFER FROM FREE RING DWIOBUFF *ctl ) // - buffer control { RingPrune( &freeBufs, ctl ); RingAppend( &activeBufs, ctl ); }