Example #1
0
int
lockFile(int fd, dev_t dev, ino_t ino, int for_writing)
{
    Lock key, *lock;

    key.device = dev;
    key.inode  = ino;

    lock = lookupHashTable(obj_hash, (StgWord)&key);

    if (lock == NULL)
    {
        lock = stgMallocBytes(sizeof(Lock), "lockFile");
        lock->device = dev;
        lock->inode  = ino;
        lock->readers = for_writing ? -1 : 1;
        insertHashTable(obj_hash, (StgWord)lock, (void *)lock);
        insertHashTable(fd_hash, fd, lock);
        return 0;
    }
    else
    {
        // single-writer/multi-reader locking:
        if (for_writing || lock->readers < 0) {
            return -1;
        }
        lock->readers++;
        return 0;
    }
}
Example #2
0
File: Hpc.c Project: alexbiehl/ghc
void
hs_hpc_module(char *modName,
              StgWord32 modCount,
              StgWord32 modHashNo,
              StgWord64 *tixArr)
{
  HpcModuleInfo *tmpModule;
  uint32_t i;

  if (moduleHash == NULL) {
      moduleHash = allocStrHashTable();
  }

  tmpModule = lookupHashTable(moduleHash, (StgWord)modName);
  if (tmpModule == NULL)
  {
      // Did not find entry so add one on.
      tmpModule = (HpcModuleInfo *)stgMallocBytes(sizeof(HpcModuleInfo),
                                                  "Hpc.hs_hpc_module");
      tmpModule->modName = modName;
      tmpModule->tickCount = modCount;
      tmpModule->hashNo = modHashNo;

      tmpModule->tixArr = tixArr;
      for(i=0;i < modCount;i++) {
          tixArr[i] = 0;
      }
      tmpModule->next = modules;
      tmpModule->from_file = false;
      modules = tmpModule;
      insertHashTable(moduleHash, (StgWord)modName, tmpModule);
  }
  else
  {
      if (tmpModule->tickCount != modCount) {
          failure("inconsistent number of tick boxes");
      }
      ASSERT(tmpModule->tixArr != 0);
      if (tmpModule->hashNo != modHashNo) {
          fprintf(stderr,"in module '%s'\n",tmpModule->modName);
          failure("module mismatch with .tix/.mix file hash number");
          if (tixFilename != NULL) {
              fprintf(stderr,"(perhaps remove %s ?)\n",tixFilename);
          }
          stg_exit(EXIT_FAILURE);
      }
      // The existing tixArr was made up when we read the .tix file,
      // whereas this is the real tixArr, so copy the data from the
      // .tix into the real tixArr.
      for(i=0;i < modCount;i++) {
          tixArr[i] = tmpModule->tixArr[i];
      }

      if (tmpModule->from_file) {
          stgFree(tmpModule->modName);
          stgFree(tmpModule->tixArr);
      }
      tmpModule->from_file = false;
  }
}
Example #3
0
void
LDV_recordDead( StgClosure *c, nat size )
{
    void *id;
    nat t;
    counter *ctr;

    if (era > 0 && closureSatisfiesConstraints(c)) {
        size -= sizeofW(StgProfHeader);
        ASSERT(LDVW(c) != 0);
        if ((LDVW((c)) & LDV_STATE_MASK) == LDV_STATE_CREATE) {
            t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
            if (t < era) {
                if (RtsFlags.ProfFlags.bioSelector == NULL) {
                    censuses[t].void_total   += (long)size;
                    censuses[era].void_total -= (long)size;
                    ASSERT(censuses[t].void_total < censuses[t].not_used);
                } else {
                    id = closureIdentity(c);
                    ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
                    ASSERT( ctr != NULL );
                    ctr->c.ldv.void_total += (long)size;
                    ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
                    if (ctr == NULL) {
                        ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
                        initLDVCtr(ctr);
                        insertHashTable(censuses[era].hash, (StgWord)id, ctr);
                        ctr->identity = id;
                        ctr->next = censuses[era].ctrs;
                        censuses[era].ctrs = ctr;
                    }
                    ctr->c.ldv.void_total -= (long)size;
                }
            }
        } else {
Example #4
0
void parseHTML(WebPage *currpage, List *currlist, HashTable *currhash, int initdepth){
  int position = 0;
  char* newurl;// = NULL;
  char *end;
  //Parsed through the HTML file and gets every URL
  while((position=GetNextURL(currpage->html, position, currpage->url, &newurl)) > 0 ){
    //Normalized the URL and if it is bad, it will be freed right away
    if (NormalizeURL(newurl)){
      //Deals with internal references
      if((end=strchr(newurl,'#'))){
	*end='\0';
      }
      // checks to make sure that the URL has the defined domain
      if( strstr(newurl,URL_PREFIX) != NULL ){
	if ( insertHashTable(currhash,newurl) == 0 ){
	  //Creates a new webpage for the found url and adds it to the our List if it successfully adds to the hashtable
	  char* dummyurl = (char *)malloc(strlen(newurl)+1);
	  strcpy(dummyurl,newurl);
	  WebPage *newpage=createWebPage(dummyurl, initdepth);
	  addtolist(currlist,newpage);
	  free(newurl);
	} else free(newurl);
      } else free(newurl);
    } else free(newurl);
  } 
  free(end);
}
Example #5
0
extern void DEBUG_LoadSymbols( const char *name )
{
    bfd* abfd;
    char **matching;

    bfd_init();
    abfd = bfd_openr(name, "default");
    if (abfd == NULL) {
        barf("can't open executable %s to get symbol table", name);
    }
    if (!bfd_check_format_matches (abfd, bfd_object, &matching)) {
        barf("mismatch");
    }

    {
        long storage_needed;
        asymbol **symbol_table;
        long number_of_symbols;
        long num_real_syms = 0;
        long i;

        storage_needed = bfd_get_symtab_upper_bound (abfd);

        if (storage_needed < 0) {
            barf("can't read symbol table");
        }
        symbol_table = (asymbol **) stgMallocBytes(storage_needed,"DEBUG_LoadSymbols");

        number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);

        if (number_of_symbols < 0) {
            barf("can't canonicalise symbol table");
        }

        if (add_to_fname_table == NULL)
            add_to_fname_table = allocHashTable();

        for( i = 0; i != number_of_symbols; ++i ) {
            symbol_info info;
            bfd_get_symbol_info(abfd,symbol_table[i],&info);
            if (isReal(info.type, info.name)) {
                insertHashTable(add_to_fname_table,
                                info.value, (void*)info.name);
                num_real_syms += 1;
            }
        }

        IF_DEBUG(interpreter,
                 debugBelch("Loaded %ld symbols. Of which %ld are real symbols\n",
                         number_of_symbols, num_real_syms)
                 );

        stgFree(symbol_table);
    }
}
Example #6
0
static void
updateThreadLabel(StgWord key, void *data)
{
  removeThreadLabel(key);

  ACQUIRE_LOCK(&threadLabels_mutex);

  insertHashTable(threadLabels,key,data);

  RELEASE_LOCK(&threadLabels_mutex);
}
Example #7
0
File: CNF.c Project: goldfirere/ghc
void
insertCompactHash (Capability *cap,
                   StgCompactNFData *str,
                   StgClosure *p, StgClosure *to)
{
    insertHashTable(str->hash, (StgWord)p, (const void*)to);
    if (str->header.info == &stg_COMPACT_NFDATA_CLEAN_info) {
        str->header.info = &stg_COMPACT_NFDATA_DIRTY_info;
        recordClosureMutated(cap, (StgClosure*)str);
    }
}
void insertToAnotherTable(HashTable* hashtableFrom,HashTable* hashtableTo){
    int i;
    for (i=0; i<HASHSIZE; i++) {
        hashNode* hashcontent= hashtableFrom->content[i];
        while(hashcontent){
            hashNode* n =searchHashTable(hashtableTo, hashcontent->key);
            if(n) n->value=n->value+hashcontent->value;
            else insertHashTable(hashtableTo, hashcontent->key, hashcontent->value);
            hashcontent=hashcontent->next;
        }
    }
}
Example #9
0
void hs_spt_insert_stableptr(StgWord64 key[2], StgStablePtr *entry) {
  // hs_spt_insert is called from constructor functions, so
  // the SPT needs to be initialized here.
  if (spt == NULL) {
    spt = allocHashTable_(hashFingerprint, compareFingerprint);
#if defined(THREADED_RTS)
    initMutex(&spt_lock);
#endif
  }

  ACQUIRE_LOCK(&spt_lock);
  insertHashTable(spt, (StgWord)key, entry);
  RELEASE_LOCK(&spt_lock);
}
Example #10
0
File: Stable.c Project: Eufavn/ghc
void
updateStablePtrTable(rtsBool full)
{
    snEntry *p, *end_stable_ptr_table;
    
    if (full && addrToStableHash != NULL) {
	freeHashTable(addrToStableHash,NULL);
	addrToStableHash = allocHashTable();
    }
    
    end_stable_ptr_table = &stable_ptr_table[SPT_size];
    
    // NOTE: _starting_ at index 1; index 0 is unused.
    for (p = stable_ptr_table + 1; p < end_stable_ptr_table; p++) {
	
	if (p->addr == NULL) {
	    if (p->old != NULL) {
		// The target has been garbage collected.  Remove its
		// entry from the hash table.
		removeHashTable(addrToStableHash, (W_)p->old, NULL);
		p->old = NULL;
	    }
	}
	else if (p->addr < (P_)stable_ptr_table 
		 || p->addr >= (P_)end_stable_ptr_table) {
	    // Target still alive, Re-hash this stable name 
	    if (full) {
		insertHashTable(addrToStableHash, (W_)p->addr, 
				(void *)(p - stable_ptr_table));
	    } else if (p->addr != p->old) {
		removeHashTable(addrToStableHash, (W_)p->old, NULL);
		insertHashTable(addrToStableHash, (W_)p->addr, 
				(void *)(p - stable_ptr_table));
	    }
	}
    }
}
Example #11
0
/*Executa a leitura das estruturas de dados*/
void leitura(AAVL clnt, AAVL prod, Contabilidade contClnt, HashTable ht, Comp compra, int valid[],char* comprastxt) {
	int i, *cresceu=(int*) malloc(sizeof(int)), clntInv=0, prodInv=0;	
	BOOLEAN validaClnt=FALSE, validaProd=FALSE, validaCmpr=FALSE;
	int countCompras=0, compras_invalidas=0;
	char linha[MAX_LINE];
	FILE *clientes, *produtos, *fcompras;

	clientes=fopen("clientes.txt","r"); 
	produtos=fopen("produtos.txt","r");
	fcompras=fopen(comprastxt,"r");

	for(i=0; fgets(linha, MAX_LINE, clientes); i++) {
			linha[strlen(linha)-1]='\0';
			trim(linha);
			insertCatalogo_Clientes(clnt, linha, cresceu);
	}
	for(i=0; fgets(linha, MAX_LINE, produtos); i++) { 
			linha[strlen(linha)-1]='\0';
			trim(linha);
			insertCatalogo_Produtos(prod, linha, cresceu);
	}

	for(i=0; fgets(linha, MAX_LINE, fcompras); i++) {
			linha[strlen(linha)-1] = '\0';
			trim(linha);
			tokenizer(compra, linha);
			validaClnt=validateClnt((*compra), clnt);
			validaProd=validateProd((*compra), prod);
			validaCmpr=validateCompras((*compra));
			if(validaClnt==FALSE) clntInv++;
			if(validaProd==FALSE) prodInv++;
			if(validaClnt==FALSE || validaProd==FALSE || validaCmpr==FALSE) compras_invalidas++;
			else {
				insertContabilidade(contClnt, compra, cresceu);
				ht = insertHashTable(ht,compra);	
			}
			countCompras++;
	}

	fclose(clientes);
	fclose(produtos);
	fclose(fcompras);

	valid[0]=countCompras;
	valid[1]=clntInv;
	valid[2]=prodInv;
	valid[3]=compras_invalidas;
	valid[4]=countCompras-compras_invalidas;
}
Example #12
0
static void checkAddress (HashTable *addrs, void *addr)
{
    ObjectCode *oc;

    if (!lookupHashTable(addrs, (W_)addr)) {
        insertHashTable(addrs, (W_)addr, addr);

        for (oc = unloaded_objects; oc; oc = oc->next) {
            if ((W_)addr >= (W_)oc->image &&
                (W_)addr <  (W_)oc->image + oc->fileSize) {
                oc->referenced = 1;
                break;
            }
        }
    }
}
Example #13
0
AdjustorWritable allocateExec(W_ bytes, AdjustorExecutable *exec_ret)
{
    AdjustorWritable writ;
    ffi_closure* cl;
    if (bytes != sizeof(ffi_closure)) {
        barf("allocateExec: for ffi_closure only");
    }
    ACQUIRE_SM_LOCK;
    cl = writ = ffi_closure_alloc((size_t)bytes, exec_ret);
    if (cl != NULL) {
        if (allocatedExecs == NULL) {
            allocatedExecs = allocHashTable();
        }
        insertHashTable(allocatedExecs, (StgWord)*exec_ret, writ);
    }
    RELEASE_SM_LOCK;
    return writ;
}
Example #14
0
StgWord
lookupStableName (StgPtr p)
{
  StgWord sn;
  const void* sn_tmp;

  stableLock();

  if (stable_name_free == NULL) {
    enlargeStableNameTable();
  }

  /* removing indirections increases the likelihood
   * of finding a match in the stable name hash table.
   */
  p = (StgPtr)removeIndirections((StgClosure*)p);

  // register the untagged pointer.  This just makes things simpler.
  p = (StgPtr)UNTAG_CLOSURE((StgClosure*)p);

  sn_tmp = lookupHashTable(addrToStableHash,(W_)p);
  sn = (StgWord)sn_tmp;

  if (sn != 0) {
    ASSERT(stable_name_table[sn].addr == p);
    debugTrace(DEBUG_stable, "cached stable name %ld at %p",sn,p);
    stableUnlock();
    return sn;
  }

  sn = stable_name_free - stable_name_table;
  stable_name_free  = (snEntry*)(stable_name_free->addr);
  stable_name_table[sn].addr = p;
  stable_name_table[sn].sn_obj = NULL;
  /* debugTrace(DEBUG_stable, "new stable name %d at %p\n",sn,p); */

  /* add the new stable name to the hash table */
  insertHashTable(addrToStableHash, (W_)p, (void *)sn);

  stableUnlock();

  return sn;
}
Example #15
0
void hs_spt_insert(StgWord64 key[2],void *spe_closure) {
  // hs_spt_insert is called from constructor functions, so
  // the SPT needs to be initialized here.
  if (spt == NULL) {
    spt = allocHashTable_( (HashFunction *)hashFingerprint
                         , (CompareFunction *)compareFingerprint
                         );
#ifdef THREADED_RTS
    initMutex(&spt_lock);
#endif
  }

  StgStablePtr * entry = stgMallocBytes( sizeof(StgStablePtr)
                                       , "hs_spt_insert: entry"
                                       );
  *entry = getStablePtr(spe_closure);
  ACQUIRE_LOCK(&spt_lock);
  insertHashTable(spt, (StgWord)key, entry);
  RELEASE_LOCK(&spt_lock);
}
Example #16
0
static void checkAddress (HashTable *addrs, void *addr)
{
    ObjectCode *oc;
    int i;

    if (!lookupHashTable(addrs, (W_)addr)) {
        insertHashTable(addrs, (W_)addr, addr);

        for (oc = unloaded_objects; oc; oc = oc->next) {
            for (i = 0; i < oc->n_sections; i++) {
                if (oc->sections[i].kind != SECTIONKIND_OTHER) {
                    if ((W_)addr >= (W_)oc->sections[i].start &&
                        (W_)addr <  (W_)oc->sections[i].start
                                    + oc->sections[i].size) {
                        oc->referenced = 1;
                        return;
                    }
                }
            }
        }
    }
}
void g_readFile(char* filename, HashTable* hashtable){
    FILE* fb;
    fb=fopen(filename,"r");
    while (1) {
        char tag[100];
        int ret = fscanf(fb,"%s",tag);
        if(ret == EOF) break;
        int i;
        for (i=0; i<strlen(tag); i++) {
            if(!(tag[i]>='a'&&tag[i]<='z')&&!(tag[i]>='A'&&tag[i]<='Z')) tag[i]=';';
        }
        char* ch=tag;
        char* val;
        while ((val=strsep(&ch,";"))) {
            if(strlen(val)==0) continue;
            hashNode* n = searchHashTable(hashtable, val);
            if (n) n->value=n->value+1;
            else insertHashTable(hashtable, val, 1);
        }
    }
    fclose(fb);
}
Example #18
0
/* ========================================================================== */
int main(int argc, char* argv[]) {
  int filenum=1;
  int initdepth=1;
  // check command line arguments
  if (argcheck(argc,argv) == 1){
    exit(1);
  }

  char *starturl = argv[1];
  char *targetdir = argv[2];
  int depth = atoi(argv[3]);
  
  //initialize our hashtables and url list
  HashTable *myhashtable;
  List *mylist;
  myhashtable=initializeHashTable();
  mylist=initializelist();
  
  // init curl
  curl_global_init(CURL_GLOBAL_ALL);
  
  // setup seed page
  WebPage *startpage = createWebPage(starturl,0);

  // get seed webpage.  If the url is invalid, quit and send an error message.
  if ( GetWebPage(startpage) == 0 ){
    printf("The url that you entered was invalid.  Please try again.");
    free(startpage->html);
    free(startpage);
    exit(1);
  }
    
  // write seed file
  createfile(startpage,targetdir,filenum);
  filenum++;
  
  // add seed page to hashtable
  insertHashTable(myhashtable,startpage->url);

  // extract urls from seed page
  if( depth > 0 ){
    parseHTML(startpage,mylist,myhashtable,initdepth);
   }

  // while there are urls to crawl
  while ( mylist->head != NULL ){
    // get next url from list
    WebPage *nextpage = listpop(mylist);
    int currdepth = nextpage->depth;
 
   // get webpage for url
    // If the url is invalid, quit and free the memory
    if (GetWebPage(nextpage) != 0 ){
      createfile(nextpage,targetdir,filenum);
      filenum++;
      // extract urls from webpage
      if ( currdepth < depth ){
	parseHTML(nextpage, mylist, myhashtable, currdepth+1);
      }
    }
    free(nextpage->html);
    free(nextpage->url);
    free(nextpage);
    sleep(SLEEPTIME);
  }
  // cleanup curl
  free(startpage->html);
  free(startpage);
  freeHashTable(myhashtable);
  freelist(mylist);
  curl_global_cleanup();
  return 0;
}
Example #19
0
File: Hpc.c Project: alexbiehl/ghc
static void
readTix(void) {
  unsigned int i;
  HpcModuleInfo *tmpModule;
  const HpcModuleInfo *lookup;

  ws();
  expect('T');
  expect('i');
  expect('x');
  ws();
  expect('[');
  ws();

  while(tix_ch != ']') {
    tmpModule = (HpcModuleInfo *)stgMallocBytes(sizeof(HpcModuleInfo),
                                                "Hpc.readTix");
    tmpModule->from_file = true;
    expect('T');
    expect('i');
    expect('x');
    expect('M');
    expect('o');
    expect('d');
    expect('u');
    expect('l');
    expect('e');
    ws();
    tmpModule -> modName = expectString();
    ws();
    tmpModule -> hashNo = (unsigned int)expectWord64();
    ws();
    tmpModule -> tickCount = (int)expectWord64();
    tmpModule -> tixArr = (StgWord64 *)calloc(tmpModule->tickCount,sizeof(StgWord64));
    ws();
    expect('[');
    ws();
    for(i = 0;i < tmpModule->tickCount;i++) {
      tmpModule->tixArr[i] = expectWord64();
      ws();
      if (tix_ch == ',') {
        expect(',');
        ws();
      }
    }
    expect(']');
    ws();

    lookup = lookupHashTable(moduleHash, (StgWord)tmpModule->modName);
    if (lookup == NULL) {
        debugTrace(DEBUG_hpc,"readTix: new HpcModuleInfo for %s",
                   tmpModule->modName);
        insertHashTable(moduleHash, (StgWord)tmpModule->modName, tmpModule);
    } else {
        ASSERT(lookup->tixArr != 0);
        ASSERT(!strcmp(tmpModule->modName, lookup->modName));
        debugTrace(DEBUG_hpc,"readTix: existing HpcModuleInfo for %s",
                   tmpModule->modName);
        if (tmpModule->hashNo != lookup->hashNo) {
            fprintf(stderr,"in module '%s'\n",tmpModule->modName);
            failure("module mismatch with .tix/.mix file hash number");
            if (tixFilename != NULL) {
                fprintf(stderr,"(perhaps remove %s ?)\n",tixFilename);
            }
            stg_exit(EXIT_FAILURE);
        }
        for (i=0; i < tmpModule->tickCount; i++) {
            lookup->tixArr[i] = tmpModule->tixArr[i];
        }
        stgFree(tmpModule->tixArr);
        stgFree(tmpModule->modName);
        stgFree(tmpModule);
    }

    if (tix_ch == ',') {
      expect(',');
      ws();
    }
  }
  expect(']');
  fclose(tixFile);
}
Example #20
0
static void
updateThreadLabel(StgWord key, void *data)
{
  removeThreadLabel(key);
  insertHashTable(threadLabels,key,data);
}