示例#1
0
void *OSMetaClass::preModLoad(const char *kmodName)
{
    if (!loadLock) {
        loadLock = mutex_alloc(ETAP_IO_AHA);
	mutex_lock(loadLock);
    }
    else
	mutex_lock(loadLock);

    sStalled = (StalledData *) kalloc(sizeof(*sStalled));
    if (sStalled) {
	sStalled->classes  = (OSMetaClass **)
			kalloc(kKModCapacityIncrement * sizeof(OSMetaClass *));
	if (!sStalled->classes) {
	    kfree((vm_offset_t) sStalled, sizeof(*sStalled));
	    return 0;
	}
	ACCUMSIZE((kKModCapacityIncrement * sizeof(OSMetaClass *)) + sizeof(*sStalled));

        sStalled->result   = kOSReturnSuccess;
	sStalled->capacity = kKModCapacityIncrement;
	sStalled->count	   = 0;
	sStalled->kmodName = kmodName;
	bzero(sStalled->classes, kKModCapacityIncrement * sizeof(OSMetaClass *));
    }

    return sStalled;
}
示例#2
0
文件: util.c 项目: jonasbits/bitc
void
Log_Init(const char *filename)
{
   time_t ltime;

   if (!filename) {
      return;
   }

   if (file_exists(filename)) {
      file_rotate(filename, 10);
   }

   logState.lock = mutex_alloc();
   logState.f = fopen(filename, "a");
   if (logState.f == NULL) {
      printf(LGPFX" Failed to create log file '%s'\n", filename);
   }
   file_chmod(filename, 0600);
   strncpy(logState.filePath, filename, sizeof logState.filePath);

   ltime = time(NULL);

   LogAlways(LGPFX" new log session: %s", asctime(localtime(&ltime)));
}
示例#3
0
IORecursiveLock * IORecursiveLockAlloc( void )
{
    _IORecursiveLock * lock;

    lock = IONew( _IORecursiveLock, 1);
    if( !lock)
        return( 0 );

    lock->mutex = mutex_alloc(ETAP_IO_AHA);
    if( lock->mutex) {
        lock->thread = 0;
        lock->count  = 0;
    } else {
        IODelete( lock, _IORecursiveLock, 1);
        lock = 0;
    }

    return( (IORecursiveLock *) lock );
}
示例#4
0
bool OSMetaClass::modHasInstance(const char *kmodName)
{
    bool result = false;

    if (!loadLock) {
        loadLock = mutex_alloc(ETAP_IO_AHA);
	mutex_lock(loadLock);
    }
    else
	mutex_lock(loadLock);

    do {
	OSSet *kmodClasses;
	OSCollectionIterator *iter;
	OSMetaClass *checkClass;

	kmodClasses = OSDynamicCast(OSSet,
				    sKModClassesDict->getObject(kmodName));
	if (!kmodClasses)
	    break;

	iter = OSCollectionIterator::withCollection(kmodClasses);
	if (!iter)
	    break;

	while ( (checkClass = (OSMetaClass *) iter->getNextObject()) )
	    if (checkClass->getInstanceCount()) {
		result = true;
		break;
	    }

	iter->release();
    } while (false);

    mutex_unlock(loadLock);

    return result;
}
示例#5
0
文件: bitc_ui.c 项目: jma127/bitc-rpc
int bitcui_start(bool withui) {
  int res;

  btcui->inuse = withui;
  btcui->lock = mutex_alloc();
  btcui->cv = condvar_alloc();
  btcui->blockProdIdx = -1;
  btcui->blockConsIdx = -1;

  if (btcui->inuse == 0) {
    return 0;
  }

  Log(LGPFX " starting ui thread.\n");

  res = pthread_create(&btcui->tid, NULL, bitcui_main, NULL);
  ASSERT(res == 0);

  mutex_lock(btcui->lock);
  condvar_wait(btcui->cv, btcui->lock);
  mutex_unlock(btcui->lock);

  return res;
}
示例#6
0
VALUE
rb_mutex_new(void)
{
    return mutex_alloc(rb_cMutex);
}
示例#7
0
IOLock * IOLockAlloc( void )
{
    return( mutex_alloc(ETAP_IO_AHA) );
}
示例#8
0
int blockstore_init(struct config *config, struct blockstore **blockStore) {
  struct blockstore *bs;
  char *file;
  bool s;
  int res;
  int i;

  *blockStore = NULL;

  file = blockstore_get_filename(config);
  Log(LGPFX " Using headers at '%s.\n", file);
  if (!file_exists(file)) {
    Log(LGPFX " file '%s' does not exist. Creating..\n", file);
    res = file_create(file);
    if (res) {
      Warning(LGPFX " failed to create file: %s\n", strerror(res));
      free(file);
      return res;
    }
    res = file_chmod(file, 0600);
    if (res != 0) {
      Warning(LGPFX " failed to chmod 0600 '%s': %s\n", file, strerror(res));
      free(file);
      return res;
    }
  }

  bs = safe_calloc(1, sizeof *bs);
  bs->height = -1;
  bs->hash_blk = hashtable_create();
  bs->hash_orphans = hashtable_create();

  const struct block_cpt_entry_str *arrayStr;
  struct block_cpt_entry *array;
  int n;

  if (btc->testnet) {
    n = ARRAYSIZE(cpt_testnet);
    array = block_cpt_testnet;
    arrayStr = cpt_testnet;
  } else {
    n = ARRAYSIZE(cpt_main);
    array = block_cpt_main;
    arrayStr = cpt_main;
  }

  for (i = 0; i < n; i++) {
    array[i].height = arrayStr[i].height;
    s = uint256_from_str(arrayStr[i].hashStr, &array[i].hash);
    ASSERT(s);
  }
  memcpy(&bs->genesis_hash.data, &array[0].hash.data, sizeof bs->genesis_hash);
  Log(LGPFX " Genesis: %s\n", arrayStr[0].hashStr);

  res = blockset_open(bs, file);
  free(file);
  if (res != 0) {
    goto exit;
  }

  Log(LGPFX " loaded %d headers.\n", bs->height + 1);

  bs->lock = mutex_alloc();
  *blockStore = bs;

  return 0;

exit:
  blockstore_exit(bs);

  return res;
}