コード例 #1
0
ファイル: pl-funct.c プロジェクト: DouglasRMiles/swipl-devel
functor_t
isCurrentFunctor(atom_t atom, size_t arity)
{ GET_LD
  unsigned int v;
  int buckets;
  FunctorDef *table;
  FunctorDef f;
  functor_t rc = 0;

redo:
  acquire_functor_table(table, buckets);

  v = (unsigned int)pointerHashValue(atom, buckets);
  for(f = table[v]; f; f = f->next)
  { if ( FUNCTOR_IS_VALID(f->flags) && atom == f->name && f->arity == arity )
    { release_functor_table();
      rc = f->functor;
      break;
    }
  }

  release_functor_table();

  if ( !rc && functorDefTable->buckets * 2 < GD->statistics.functors )
  { LOCK();
    rehashFunctors();
    UNLOCK();
  }
  if ( table != functorDefTable->table )
    goto redo;

  return rc;
}
コード例 #2
0
ファイル: pl-funct.c プロジェクト: DouglasRMiles/swipl-devel
functor_t
lookupFunctorDef(atom_t atom, size_t arity)
{ GET_LD
  int v;
  FunctorDef *table;
  int buckets;
  FunctorDef f, head;

redo:

  acquire_functor_table(table, buckets);

  v = (int)pointerHashValue(atom, buckets);
  head = table[v];

  DEBUG(9, Sdprintf("Lookup functor %s/%d = ", stringAtom(atom), arity));
  for(f = table[v]; f; f = f->next)
  { if (atom == f->name && f->arity == arity)
    { DEBUG(9, Sdprintf("%p (old)\n", f));
      if ( !FUNCTOR_IS_VALID(f->flags) )
      { goto redo;
      }
      release_functor_table();
      return f->functor;
    }
  }

  if ( functorDefTable->buckets * 2 < GD->statistics.functors )
  { LOCK();
    rehashFunctors();
    UNLOCK();
  }

  if ( !( head == table[v] && table == functorDefTable->table ) )
    goto redo;

  f = (FunctorDef) allocHeapOrHalt(sizeof(struct functorDef));
  f->functor = 0L;
  f->name    = atom;
  f->arity   = arity;
  f->flags   = 0;
  f->next    = table[v];
  if ( !( COMPARE_AND_SWAP(&table[v], head, f) &&
          table == functorDefTable->table) )
  { PL_free(f);
    goto redo;
  }
  registerFunctor(f);

  ATOMIC_INC(&GD->statistics.functors);
  PL_register_atom(atom);

  DEBUG(9, Sdprintf("%p (new)\n", f));

  release_functor_table();

  return f->functor;
}
コード例 #3
0
ファイル: pl-funct.c プロジェクト: brayc0/nlfetdb
functor_t
lookupFunctorDef(atom_t atom, unsigned int arity)
{ int v;
  FunctorDef f;

  LOCK();
  v = (int)pointerHashValue(atom, functor_buckets);

  DEBUG(9, Sdprintf("Lookup functor %s/%d = ", stringAtom(atom), arity));
  for(f = functorDefTable[v]; f; f = f->next)
  { if (atom == f->name && f->arity == arity)
    { DEBUG(9, Sdprintf("%p (old)\n", f));
      UNLOCK();
      return f->functor;
    }
  }
  f = (FunctorDef) allocHeapOrHalt(sizeof(struct functorDef));
  f->functor = 0L;
  f->name    = atom;
  f->arity   = arity;
  if ( atom == ATOM_call && arity > 8 )
    f->flags = CONTROL_F;
  else
    f->flags   = 0;
  f->next    = functorDefTable[v];
  functorDefTable[v] = f;
  registerFunctor(f);
  GD->statistics.functors++;
  PL_register_atom(atom);

  DEBUG(9, Sdprintf("%p (new)\n", f));

  if ( functor_buckets * 2 < GD->statistics.functors )
    rehashFunctors();

  UNLOCK();

  return f->functor;
}