void intern_res(ResolutionComputation *G) { GC_REGISTER_FINALIZER(G, remove_res, 0, 0, 0); AO_t nfinalized = AO_fetch_and_add1(&res_nfinalized); if (M2_gbTrace >= 3) fprintf( stderr, "\n -- registering res %zd at %p\n", nfinalized, (void *)G); }
pthread_rwlock_t* dfsch_create_finalized_rwlock(){ pthread_rwlock_t* lock = GC_MALLOC_ATOMIC(sizeof(pthread_rwlock_t)); #ifdef DFSCH_THREADS_FINALIZE GC_REGISTER_FINALIZER(lock, (GC_finalization_proc)rwlock_finalizer, NULL, NULL, NULL); #endif pthread_rwlock_init(lock, NULL); return lock; }
void intern_monideal(MonomialIdeal *G) { GC_REGISTER_FINALIZER(G, remove_monideal, 0, 0, 0); AO_t nfinalized = AO_fetch_and_add1(&monideals_nfinalized); if (M2_gbTrace >= 3) fprintf(stderr, "\n -- registering monomial ideal %zd at %p\n", nfinalized, (void *)G); }
void intern_SchreyerOrder(SchreyerOrder *G) { GC_REGISTER_FINALIZER(G, remove_SchreyerOrder, 0, 0, 0); AO_t nfinalized = AO_fetch_and_add1(&schorder_nfinalized); if (M2_gbTrace >= 3) fprintf(stderr, "\n -- registering SchreyerOrder %zd at %p\n", nfinalized, (void *)G); }
MutableMatrix *internMutableMatrix(MutableMatrix *G) { if (G == 0) return 0; GC_REGISTER_FINALIZER(G, remove_MutableMatrix, 0, 0, 0); AO_t nfinalized = AO_fetch_and_add1(&mutablematrices_nfinalized); if (M2_gbTrace >= 3) fprintf(stderr, "\n -- registering mutable matrix %zd at %p\n", nfinalized, (void *)G); return G; }
void intern_computation(EngineComputation *G) { GC_REGISTER_FINALIZER(G, remove_computation, 0, 0, 0); AO_t nfinalized = AO_fetch_and_add1(&comp_nfinalized); if (M2_gbTrace >= 3) { // -- there is no gettid under Solaris // int tid = static_cast<int>(syscall(SYS_gettid)); // fprintf(stderr, "\n -- thread %d registering gb %zd at %p\n", tid, // nfinalized, (void *)G); fprintf( stderr, "\n -- registering gb %zd at %p\n", nfinalized, (void *)G); } }
dfsch_object_t* dfsch_regex_compile(char* expression, int flags){ dfsch_regex_t* r = (dfsch_regex_t*)dfsch_make_object(®ex_type); regex_compile(&(r->regex), expression, flags); if ((flags & REG_NOSUB) == REG_NOSUB){ r->sub_count = 0; }else{ r->sub_count = get_sub_count(expression, flags); } GC_REGISTER_FINALIZER(r, (GC_finalization_proc)regex_finalizer, NULL, NULL, NULL); return (dfsch_object_t*)r; }
dfsch_object_t* dfsch_make_file_port(FILE* file, int close, char* name){ file_port_t* port = (file_port_t*)dfsch_make_object((dfsch_type_t*) DFSCH_FILE_PORT_TYPE); port->file = file; port->close = close; port->name = name; port->open = 1; /* Creating closed ports makes no sense */ if (close){ GC_REGISTER_FINALIZER(port, (GC_finalization_proc)file_port_finalizer, NULL, NULL, NULL); } return (dfsch_object_t*)port; }
static dfsch_object_t* spawn_port(dfsch_object_t* klass, char* cmd_line){ process_port_t* p = dfsch_make_object(klass); p->cmd_line = cmd_line; if (klass == DFSCH_PROCESS_INPUT_PORT_TYPE){ p->file = popen(cmd_line, "r"); } else { p->file = popen(cmd_line, "w"); } if (!p->file){ dfsch_error("Cannot spawn process", dfsch_make_string_cstr(strerror(errno))); } GC_REGISTER_FINALIZER(p, (GC_finalization_proc)port_finalizer, NULL, NULL, NULL); p->open = 1; return (dfsch_object_t*)p; }
int hashitem( register struct hash *hp, HASHDATA **data, int enter ) { register ITEM *i; OBJECT *b = (*data)->key; unsigned int keyval = hash_keyval(b); #ifdef HASH_DEBUG_PROFILE profile_frame prof[1]; if ( DEBUG_PROFILE ) profile_enter( 0, prof ); #endif if ( enter && !hp->items.more ) hashrehash( hp ); if ( !enter && !hp->items.nel ) { #ifdef HASH_DEBUG_PROFILE if ( DEBUG_PROFILE ) profile_exit( prof ); #endif return 0; } i = hash_search( hp, keyval, (*data)->key, 0 ); if (i) { *data = &i->data; #ifdef HASH_DEBUG_PROFILE if ( DEBUG_PROFILE ) profile_exit( prof ); #endif return !0; } if ( enter ) { ITEM * * base = hash_bucket(hp,keyval); /* try to grab one from the free list */ if ( hp->items.free ) { i = hp->items.free; hp->items.free = i->hdr.next; assert( i->data.key == 0 ); } else { i = (ITEM *)hp->items.next; hp->items.next += hp->items.size; } hp->items.more--; memcpy( (char *)&i->data, (char *)*data, hp->items.datalen ); i->hdr.next = *base; *base = i; *data = &i->data; #ifdef OPT_BOEHM_GC if (sizeof(HASHDATA) == hp->items.datalen) { GC_REGISTER_FINALIZER(i->data.key,&hash_mem_finalizer,hp,0,0); } #endif } #ifdef HASH_DEBUG_PROFILE if ( DEBUG_PROFILE ) profile_exit( prof ); #endif return 0; }
tn * mktree(int n) { tn * result = (tn *)GC_MALLOC(sizeof(tn)); collectable_count++; # if defined(MACOS) /* get around static data limitations. */ if (!live_indicators) live_indicators = (GC_word*)NewPtrClear(MAX_FINALIZED * sizeof(GC_word)); if (!live_indicators) { GC_printf("Out of memory\n"); exit(1); } # endif if (n == 0) return(0); if (result == 0) { GC_printf("Out of memory\n"); exit(1); } result -> level = n; result -> lchild = mktree(n-1); result -> rchild = mktree(n-1); if (counter++ % 17 == 0 && n >= 2) { tn * tmp = result -> lchild -> rchild; result -> lchild -> rchild = result -> rchild -> lchild; result -> rchild -> lchild = tmp; } if (counter++ % 119 == 0) { int my_index; { # ifdef PCR PCR_ThCrSec_EnterSys(); # endif # if defined(GC_PTHREADS) static pthread_mutex_t incr_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&incr_lock); # elif defined(GC_WIN32_THREADS) EnterCriticalSection(&incr_cs); # endif /* Losing a count here causes erroneous report of failure. */ finalizable_count++; my_index = live_indicators_count++; # ifdef PCR PCR_ThCrSec_ExitSys(); # endif # if defined(GC_PTHREADS) pthread_mutex_unlock(&incr_lock); # elif defined(GC_WIN32_THREADS) LeaveCriticalSection(&incr_cs); # endif } GC_REGISTER_FINALIZER((void *)result, finalizer, (void *)(GC_word)n, (GC_finalization_proc *)0, (void * *)0); if (my_index >= MAX_FINALIZED) { GC_printf("live_indicators overflowed\n"); FAIL; } live_indicators[my_index] = 13; if (GC_GENERAL_REGISTER_DISAPPEARING_LINK( (void * *)(&(live_indicators[my_index])), (void *)result) != 0) { GC_printf("GC_general_register_disappearing_link failed\n"); FAIL; } if (GC_unregister_disappearing_link( (void * *) (&(live_indicators[my_index]))) == 0) { GC_printf("GC_unregister_disappearing_link failed\n"); FAIL; } if (GC_GENERAL_REGISTER_DISAPPEARING_LINK( (void * *)(&(live_indicators[my_index])), (void *)result) != 0) { GC_printf("GC_general_register_disappearing_link failed 2\n"); FAIL; } GC_reachable_here(result); } return(result); }