Пример #1
0
        // Build tree top down, assigning to older objects.
        static void Populate(int iDepth, Node thisNode) {
                if (iDepth<=0) {
                        return;
                } else {
                        iDepth--;
#			ifndef GC
                          thisNode->left  = new Node0();
                          thisNode->right = new Node0();
#			else
                          thisNode->left  = new (GC_NEW(Node0)) Node0();
                          thisNode->right = new (GC_NEW(Node0)) Node0();
#			endif
                        Populate (iDepth, thisNode->left);
                        Populate (iDepth, thisNode->right);
                }
        }
Пример #2
0
hlt_exception* hlt_exception_new(hlt_exception_type* type, void* arg, const char* location,
                                 hlt_execution_context* ctx)
{
    hlt_exception* excpt = GC_NEW(hlt_exception, ctx);
    _hlt_exception_init(excpt, type, arg, location, ctx);
    return excpt;
}
Пример #3
0
// Build tree top down, assigning to older objects.
static void Populate(int iDepth, Node thisNode) {
        if (iDepth<=0) {
                return;
        } else {
                iDepth--;
#		ifdef GC
                  thisNode->left  = GC_NEW(Node0); HOLE();
                  thisNode->right = GC_NEW(Node0); HOLE();
#		else
                  thisNode->left  = calloc(1, sizeof(Node0));
                  thisNode->right = calloc(1, sizeof(Node0));
#		endif
                Populate (iDepth, thisNode->left);
                Populate (iDepth, thisNode->right);
        }
}
Пример #4
0
        // Build tree bottom-up
        static Node MakeTree(int iDepth) {
                if (iDepth<=0) {
#		     ifndef GC
                        return new Node0();
#		     else
                        return new (GC_NEW(Node0)) Node0();
#		     endif
                } else {
#		     ifndef GC
                        return new Node0(MakeTree(iDepth-1),
                                         MakeTree(iDepth-1));
#		     else
                        return new (GC_NEW(Node0)) Node0(MakeTree(iDepth-1),
                                         		 MakeTree(iDepth-1));
#		     endif
                }
        }
Пример #5
0
//--------------------------------------------------------------------------
// Name         New_Ast 
//
// TODO: allocate different length depending on the code
//--------------------------------------------------------------------------
AST New_Ast ( AstCode_t code, const yyltype * loc )
{
  TAstNode * res = GC_NEW( TAstNode );

  res->code = code;
  if (loc)
    res->loc = *loc;
};
Пример #6
0
static hlt_match_token_state* _match_token_init(hlt_regexp* re, hlt_exception** excpt, hlt_execution_context* ctx)
{
    hlt_match_token_state* state = GC_NEW(hlt_match_token_state, ctx);
    GC_INIT(state->re, re, hlt_regexp, ctx);
    state->acc = 0;
    state->first = JRX_ASSERTION_BOL | JRX_ASSERTION_BOD;
    jrx_match_state_init(&re->regexp, 0, &state->ms);

    return state;
}
Пример #7
0
void worker_state_init(void) {
    worker_next_priority = 0;
    worker_ready_to_run =
        heap_new(WORKER_READY_QUEUE_SIZE, (Cmpfunc) worker_priority_cmp);
    worker_thread_pool = NULL;
    worker_biglock = GC_NEW(pthread_mutex_t);
    assert(worker_biglock != NULL);
    pthread_mutex_init(worker_biglock, NULL);
    worker_active = 0;
}
Пример #8
0
// Build tree bottom-up
static Node MakeTree(int iDepth) {
	Node result;
        if (iDepth<=0) {
#	    ifndef GC
		result = calloc(1, sizeof(Node0));
#	    else
		result = GC_NEW(Node0); HOLE();
#	    endif
	    /* result is implicitly initialized in both cases. */
	    return result;
        } else {
	    Node left = MakeTree(iDepth-1);
	    Node right = MakeTree(iDepth-1);
#	    ifndef GC
		result = malloc(sizeof(Node0));
#	    else
		result = GC_NEW(Node0); HOLE();
#	    endif
	    init_Node(result, left, right);
	    return result;
        }
}
Пример #9
0
Файл: csv.c Проект: adh/dfsch
dfsch_csv_params_t* dfsch_csv_params(dfsch_object_t* args){
  dfsch_csv_params_t* params = GC_NEW(dfsch_csv_params_t);
  memcpy(params, &default_params, sizeof(dfsch_csv_params_t));

  DFSCH_KEYWORD_PARSER_BEGIN(args);
  DFSCH_KEYWORD_GENERIC("delimiter", params->delim, 
                        dfsch_number_to_long);
  DFSCH_KEYWORD_GENERIC("quote-character", params->quote, 
                        dfsch_number_to_long);
  DFSCH_KEYWORD_GENERIC("escape-character", params->escape, 
                        dfsch_number_to_long);
  DFSCH_KEYWORD_PARSER_END(args);

  return params;
}
Пример #10
0
binpac_sink* binpachilti_sink_new(hlt_exception** excpt, hlt_execution_context* ctx)
{
    binpac_sink* sink = GC_NEW(binpac_sink, ctx);
    sink->head = 0;
    sink->filter = 0;
    sink->size = 0;
    sink->auto_trim = 1;
    sink->initial_seq = 0;
    sink->policy = hlt_enum_value(BinPAC_ReassemblyPolicy_First, excpt, ctx);
    sink->cur_rseq = 0;
    sink->last_reassem_rseq = 0;
    sink->trim_rseq = 0;
    sink->first_chunk = 0;
    sink->last_chunk = 0;
    return sink;
}
Пример #11
0
Lease *lease_new(char *pathname, Address *addr, int isexit, Claim *claim,
        int readonly)
{
    Lease *l = GC_NEW(Lease);
    assert(l != NULL);

    l->wait_for_update = NULL;
    l->inflight = 0;

    l->changeinprogress = 0;
    l->changeexits = NULL;
    l->changefids = NULL;

    l->pathname = pathname;
    l->addr = addr;

    l->wavefront = NULL;

    l->isexit = isexit;

    if (isexit) {
        l->claim = NULL;
        l->fids = NULL;
        l->claim_cache = NULL;
        l->dir_cache = NULL;
    } else {
        l->claim = claim;
        l->claim->lease = l;
        l->fids = hash_create(LEASE_FIDS_HASHTABLE_SIZE,
                (Hashfunc) fid_hash,
                (Cmpfunc) fid_cmp);
        l->claim_cache = hash_create(
                LEASE_CLAIM_HASHTABLE_SIZE,
                (Hashfunc) string_hash,
                (Cmpfunc) strcmp);
        l->dir_cache = hash_create(
                LEASE_DIR_HASHTABLE_SIZE,
                (Hashfunc) dir_block_hash,
                (Cmpfunc) dir_block_cmp);
    }

    l->readonly = readonly;
    l->lastchange = now_double();

    return l;
}
Пример #12
0
        static void TimeConstruction(int depth) {
                long    tStart, tFinish;
                int     iNumIters = NumIters(depth);
                Node    tempTree;

                cout << "Creating " << iNumIters
                     << " trees of depth " << depth << endl;
                
                tStart = currentTime();
                for (int i = 0; i < iNumIters; ++i) {
#			ifndef GC
                          tempTree = new Node0();
#			else
                          tempTree = new (GC_NEW(Node0)) Node0();
#			endif
                        Populate(depth, tempTree);
#		        ifndef GC
                          delete tempTree;
#			endif
                        tempTree = 0;
                }
                tFinish = currentTime();
                cout << "\tTop down construction took "
                     << elapsedTime(tFinish - tStart) << " msec" << endl;
                     
                tStart = currentTime();
                for (int i = 0; i < iNumIters; ++i) {
                        tempTree = MakeTree(depth);
#			ifndef GC
                          delete tempTree;
#			endif
                        tempTree = 0;
                }
                tFinish = currentTime();
                cout << "\tBottom up construction took "
                     << elapsedTime(tFinish - tStart) << " msec" << endl;

        }
Пример #13
0
static void TimeConstruction(int depth) {
        long    tStart, tFinish;
        int     iNumIters = NumIters(depth);
        Node    tempTree;
	int 	i;

	printf("Creating %d trees of depth %d\n", iNumIters, depth);
        
        tStart = currentTime();
        for (i = 0; i < iNumIters; ++i) {
#		ifndef GC
                  tempTree = calloc(1, sizeof(Node0));
#		else
                  tempTree = GC_NEW(Node0);
#		endif
                Populate(depth, tempTree);
#		ifndef GC
                  destroy_Node(tempTree);
#		endif
                tempTree = 0;
        }
        tFinish = currentTime();
        printf("\tTop down construction took %d msec\n",
               elapsedTime(tFinish - tStart));
             
        tStart = currentTime();
        for (i = 0; i < iNumIters; ++i) {
                tempTree = MakeTree(depth);
#		ifndef GC
                  destroy_Node(tempTree);
#		endif
                tempTree = 0;
        }
        tFinish = currentTime();
        printf("\tBottom up construction took %d msec\n",
               elapsedTime(tFinish - tStart));

}
Пример #14
0
void worker_create(void (*func)(Worker *, void *), void *arg) {
    if (null(worker_thread_pool)) {
        pthread_t newthread;
        pthread_attr_t attr;
        Worker *t = GC_NEW(Worker);
        assert(t != NULL);
        t->sleep = cond_new();

        t->func = func;
        t->arg = arg;
        t->priority = worker_next_priority++;
        t->blocking = NULL;

        pthread_attr_init(&attr);
        pthread_attr_setstacksize(&attr, max(PTHREAD_STACK_MIN, 1024 * 1024));
        pthread_create(&newthread, &attr,
                       (void *(*)(void *)) worker_loop, (void *) t);
        pthread_detach(newthread);
    } else {
        Worker *t = car(worker_thread_pool);
        worker_thread_pool = cdr(worker_thread_pool);

        t->func = func;
        t->arg = arg;
        t->priority = worker_next_priority++;
        t->blocking = NULL;

        if (!heap_isempty(worker_ready_to_run)) {
            /* wait for older threads that are ready to run */
            worker_wake_up_next();
            heap_add(worker_ready_to_run, t);
        } else {
            cond_signal(t->sleep);
        }
    }
}
Пример #15
0
hlt_classifier* hlt_classifier_new(int64_t num_fields, const hlt_type_info* rtype, const hlt_type_info* vtype, hlt_exception** excpt, hlt_execution_context* ctx)
{
    hlt_classifier* c = GC_NEW(hlt_classifier, ctx);
    _hlt_classifier_init(c, num_fields, rtype, vtype, excpt, ctx);
    return c;
}
Пример #16
0
        void main() {
                Node    root;
                Node    longLivedTree;
                Node    tempTree;
                long    tStart, tFinish;
                long    tElapsed;

#ifdef GC
// GC_full_freq = 30;
GC_enable_incremental();
#endif
                cout << "Garbage Collector Test" << endl;
                cout << " Live storage will peak at "
                     << 2 * sizeof(Node0) * TreeSize(kLongLivedTreeDepth) +
                        sizeof(double) * kArraySize
                     << " bytes." << endl << endl;
                cout << " Stretching memory with a binary tree of depth "
                     << kStretchTreeDepth << endl;
                PrintDiagnostics();
               
                tStart = currentTime();
                
                // Stretch the memory space quickly
                tempTree = MakeTree(kStretchTreeDepth);
#		ifndef GC
                  delete tempTree;
#		endif
                tempTree = 0;

                // Create a long lived object
                cout << " Creating a long-lived binary tree of depth "
                     << kLongLivedTreeDepth << endl;
#		ifndef GC
                  longLivedTree = new Node0();
#		else 
                  longLivedTree = new (GC_NEW(Node0)) Node0();
#		endif
                Populate(kLongLivedTreeDepth, longLivedTree);

                // Create long-lived array, filling half of it
                cout << " Creating a long-lived array of "
                     << kArraySize << " doubles" << endl;
#		ifndef GC
                  double *array = new double[kArraySize];
#		else
                  double *array = (double *)
				GC_MALLOC_ATOMIC(sizeof(double) * kArraySize);
#		endif
                for (int i = 0; i < kArraySize/2; ++i) {
                        array[i] = 1.0/i;
                }
                PrintDiagnostics();

                for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2)
{
                        TimeConstruction(d);
                }

                if (longLivedTree == 0 || array[1000] != 1.0/1000)
                        cout << "Failed" << endl;
                                        // fake reference to LongLivedTree
                                        // and array
                                        // to keep them from being optimized away

                tFinish = currentTime();
                tElapsed = elapsedTime(tFinish-tStart);
                PrintDiagnostics();
                cout << "Completed in " << tElapsed << " msec" << endl;
#		ifdef GC
		  cout << "Completed " << GC_gc_no << " collections" <<endl;
		  cout << "Heap size is " << GC_get_heap_size() << endl;
#		endif
        }
Пример #17
0
pthread_cond_t *cond_new(void) {
    pthread_cond_t *cond = GC_NEW(pthread_cond_t);
    assert(cond != NULL);
    pthread_cond_init(cond, NULL);
    return cond;
}
Пример #18
0
hlt_regexp* hlt_regexp_new_from_regexp(hlt_regexp* other, hlt_exception** excpt, hlt_execution_context* ctx)
{
    hlt_regexp* re = GC_NEW(hlt_regexp, ctx);
    _hlt_regexp_new_from_regexp_init(re, other, excpt, ctx);
    return re;
}
Пример #19
0
int main() {
        Node    root;
        Node    longLivedTree;
        Node    tempTree;
        long    tStart, tFinish;
        long    tElapsed;
  	int	i, d;
	double 	*array;

#ifdef GC
 // GC_full_freq = 30;
 // GC_free_space_divisor = 16;
 // GC_enable_incremental();
#endif
	printf("Garbage Collector Test\n");
 	printf(" Live storage will peak at %d bytes.\n\n",
               2 * sizeof(Node0) * TreeSize(kLongLivedTreeDepth) +
               sizeof(double) * kArraySize);
        printf(" Stretching memory with a binary tree of depth %d\n",
               kStretchTreeDepth);
        PrintDiagnostics();
#	ifdef PROFIL
	    init_profiling();
#	endif
       
        tStart = currentTime();
        
        // Stretch the memory space quickly
        tempTree = MakeTree(kStretchTreeDepth);
#	ifndef GC
          destroy_Node(tempTree);
#	endif
        tempTree = 0;

        // Create a long lived object
        printf(" Creating a long-lived binary tree of depth %d\n",
               kLongLivedTreeDepth);
#	ifndef GC
          longLivedTree = calloc(1, sizeof(Node0));
#	else 
          longLivedTree = GC_NEW(Node0);
#	endif
        Populate(kLongLivedTreeDepth, longLivedTree);
        ggggc_collectFull();
        // Create long-lived array, filling half of it
	printf(" Creating a long-lived array of %d doubles\n", kArraySize);
#	ifndef GC
          array = malloc(kArraySize * sizeof(double));
#	else
#	  ifndef NO_PTRFREE
            array = GC_MALLOC_ATOMIC(sizeof(double) * kArraySize);
#	  else
            array = GC_MALLOC(sizeof(double) * kArraySize);
#	  endif
#	endif
        ggggc_collectFull();
        for (i = 0; i < kArraySize/2; ++i) {
                array[i] = 1.0/i;
        }
        PrintDiagnostics();

        for (d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
                TimeConstruction(d);
        }

        if (longLivedTree == 0 || array[1000] != 1.0/1000)
		fprintf(stderr, "Failed\n");
                                // fake reference to LongLivedTree
                                // and array
                                // to keep them from being optimized away

        tFinish = currentTime();
        tElapsed = elapsedTime(tFinish-tStart);
        PrintDiagnostics();
        printf("Completed in %d msec\n", tElapsed);
#	ifdef GC
	  printf("Completed %d collections\n", GC_gc_no);
	  printf("Heap size is %d\n", GC_get_heap_size());
#       endif
#	ifdef PROFIL
	  dump_profile();
#	endif
}
Пример #20
0
hlt_regexp* hlt_regexp_new(hlt_regexp_flags flags, hlt_exception** excpt, hlt_execution_context* ctx)
{
    hlt_regexp* re = GC_NEW(hlt_regexp, ctx);
    _hlt_regexp_init(re, flags, excpt, ctx);
    return re;
}