コード例 #1
0
ファイル: Allocator.cpp プロジェクト: JohanAberg/duke
	void* allocate() {
		assert(isNotFull());
		const unsigned char index = findFreeSlot();
		--m_AvailableSlots;
		m_UsedSlot[index] = true;
		return m_SlotData[index];
	}
コード例 #2
0
void vp_os_thread_create(THREAD_ROUTINE entry, THREAD_PARAMS data, THREAD_HANDLE *handle, ...)
{
  int32_t priority;
  char* name;
  void* stack_base;
  unsigned int stack_size;
  SUP_THREAD** thread_pointer;
  va_list va;

#ifdef __ARMCC_VERSION
  va_start(va, handle);
#else
  va_start(va, (char*)handle);
#endif

  priority    = va_arg(va, int32_t);
  name        = va_arg(va, char *);
  stack_base  = va_arg(va, void *);
  stack_size  = va_arg(va, unsigned int);
  thread_pointer = va_arg(va,SUP_THREAD**);
  va_end(va);

  SUP_THREAD* thread = findFreeSlot();
  (*thread_pointer) = thread;

  sup_thread_create(handle, thread, priority, entry, data, stack_size, name);
  sup_thread_resume(*handle);
}
コード例 #3
0
ファイル: ParticleSystem.cpp プロジェクト: Sudoka/ssg
void
ParticleSystem::update ( float dt ) 
{
  // create new particles
  int slot=0;
  for ( int i = 0; i < generators.size(); i++ ) {
      for ( int k = 0; k < PARTICLES_PER_FRAME_PER_GENERATOR; k++ ) {
	slot = findFreeSlot ( slot );
	if (slot == -1) {
	  continue;
	}
	pos[slot] = generators[i];
	oldpos[slot] = pos[slot];
	vel[slot] = initialVelocity();
	pos[slot] += vel[slot] * urand() * 0.033f; // offset within a frame.
	age[slot] = 0.0;
      }
    }
  // update particles.
  for ( int i = 0; i < pos.size(); i++ ) { 
    if ( age[i] <= MAX_AGE ) {
      age[i] += dt;
      vel[i] += accelerationAt ( pos[i] ) * static_cast<float>(dt);
      float speed = glm::length(vel[i]);
      if (speed > MAX_SPEED )
	vel[i] = glm::normalize(vel[i]) * MAX_SPEED;
      oldpos[i] = pos[i];
      pos[i] += vel[i] * static_cast<float>(dt);
    }
  }
}
コード例 #4
0
/* The occupancy of the table after the call will be about 50% */
static UA_StatusCode
expand(UA_NodeMap *ns) {
    UA_UInt32 osize = ns->size;
    UA_UInt32 count = ns->count;
    /* Resize only when table after removal of unused elements is either too
       full or too empty */
    if(count * 2 < osize && (count * 8 > osize || osize <= UA_NODEMAP_MINSIZE))
        return UA_STATUSCODE_GOOD;

    UA_NodeMapEntry **oentries = ns->entries;
    UA_UInt32 nindex = higher_prime_index(count * 2);
    UA_UInt32 nsize = primes[nindex];
    UA_NodeMapEntry **nentries = (UA_NodeMapEntry **)UA_calloc(nsize, sizeof(UA_NodeMapEntry*));
    if(!nentries)
        return UA_STATUSCODE_BADOUTOFMEMORY;

    ns->entries = nentries;
    ns->size = nsize;
    ns->sizePrimeIndex = nindex;

    /* recompute the position of every entry and insert the pointer */
    for(size_t i = 0, j = 0; i < osize && j < count; ++i) {
        if(oentries[i] <= UA_NODEMAP_TOMBSTONE)
            continue;
        UA_NodeMapEntry **e = findFreeSlot(ns, &oentries[i]->node.nodeId);
        UA_assert(e);
        *e = oentries[i];
        ++j;
    }

    UA_free(oentries);
    return UA_STATUSCODE_GOOD;
}
コード例 #5
0
ファイル: sound_manager.cpp プロジェクト: 86400/scummvm
int QSoundManager::playWave(CWaveFile *waveFile, int iChannel, uint flags, CProximity &prox) {
	if (!waveFile || !waveFile->isLoaded())
		return 0;

	prox._channelVolume = CLIP(prox._channelVolume, 0, 100);
	prox._balance = CLIP(prox._balance, -100, 100);

	int slotIndex = findFreeSlot();
	if (slotIndex == -1)
		return -1;

	// Set the volume
	setChannelVolume(iChannel, prox._channelVolume, prox._channelMode);

	switch (prox._positioningMode) {
	case POSMODE_POLAR:
		qsWaveMixSetPolarPosition(iChannel, 8, QSPOLAR(prox._azimuth, prox._range, prox._elevation));
		qsWaveMixEnableChannel(iChannel, QMIX_CHANNEL_ELEVATION, true);
		qsWaveMixSetDistanceMapping(iChannel, 8, QMIX_DISTANCES(5.0, 3.0, 1.0));
		break;

	case POSMODE_VECTOR:
		qsWaveMixSetSourcePosition(iChannel, 8, QSVECTOR(prox._posX, prox._posY, prox._posZ));
		qsWaveMixEnableChannel(iChannel, QMIX_CHANNEL_ELEVATION, true);
		qsWaveMixSetDistanceMapping(iChannel, 8, QMIX_DISTANCES(5.0, 3.0, 1.0));
		break;

	default:
		qsWaveMixEnableChannel(iChannel, QMIX_CHANNEL_ELEVATION, true);
		qsWaveMixSetPolarPosition(iChannel, 8, QSPOLAR(0.0, 1.0, 0.0));
		break;
	}

	if (prox._frequencyMultiplier || prox._frequencyAdjust != 1.875) {
		uint freq = (uint)(waveFile->getFrequency() * prox._frequencyMultiplier);
		qsWaveMixSetFrequency(iChannel, 8, freq);
	}

	_sounds.add(waveFile, iChannel, prox._endTalkerFn, prox._talker);

	QMIXPLAYPARAMS playParams;
	playParams.callback = soundFinished;
	playParams.dwUser = this;
	if (!qsWaveMixPlayEx(iChannel, flags, waveFile, prox._repeated ? -1 : 0, playParams)) {
		Slot &slot = _slots[slotIndex];
		slot._handle = _handleCtr++;
		slot._channel = iChannel;
		slot._waveFile = waveFile;
		slot._positioningMode = prox._positioningMode;

		return slot._handle;
	} else {
		_sounds.flushChannel(waveFile, iChannel);
		if (prox._disposeAfterUse == DisposeAfterUse::YES)
			delete waveFile;
		return 0;
	}
}
コード例 #6
0
/*!
  This slot is called when the user clicks the "Pick a date" button.
*/
void KOEditorFreeBusy::slotPickDate()
{
  QDateTime start = mDtStart;
  QDateTime end = mDtEnd;
  bool success = findFreeSlot( start, end );

  if( success ) {
    if ( start == mDtStart && end == mDtEnd ) {
      KMessageBox::information( this,
          i18n( "The meeting already has suitable start/end times." ), QString::null,
          "MeetingTimeOKFreeBusy" );
    } else {
      emit dateTimesChanged( start, end );
      slotUpdateGanttView( start, end );
      KMessageBox::information( this,
          i18n( "The meeting has been moved to\nStart: %1\nEnd: %2." )
          .arg( start.toString() ).arg( end.toString() ), QString::null,
          "MeetingMovedFreeBusy" );
    }
  } else
    KMessageBox::sorry( this, i18n( "No suitable date found." ) );
}
コード例 #7
0
ファイル: recom.c プロジェクト: KhaosResearch/MORPHY
static int pinNode(recompVectors *rvec, int nodenum, int mxtips)
{
  int 
    slot;

  assert(!isNodePinned(rvec, nodenum, mxtips));

  if(rvec->allSlotsBusy)
    slot = findUnpinnableSlot(rvec, mxtips);
  else
    slot = findFreeSlot(rvec, mxtips);

  assert(slot >= 0);

  pinAtomicNode(rvec, nodenum, slot, mxtips);

  if(slot > rvec->maxVectorsUsed)
    rvec->maxVectorsUsed = slot;

  assert(slot == rvec->iNode[nodenum - mxtips - 1]);

  return slot;
}
コード例 #8
0
// Bulk of work will be here 
// handling records in a table
RC insertRecord(RM_TableData *rel, Record *record) {
	RM_TableMgmtData *tableMgmtData = rel->mgmtData;
	BM_MgmtData *bufferMgmtData = tableMgmtData->bufferPool.mgmtData;
	RID *rid = &record->id;
	RM_Page *page;
	char *slotOffset;

	//  Do we have a free slot?
	if (tableMgmtData->nextFreeSlot > 0) {
		// We have a free slot for the record
		rid->page = tableMgmtData->nextFreeSlot;
		// Pin page to insert record
		RC pinPageResult;
		if (pinPageResult = pinPage(&tableMgmtData->bufferPool, &tableMgmtData->pageHandle, rid->page) != RC_OK) {
			return pinPageResult;
		}

		page = (RM_Page*)tableMgmtData->pageHandle.data;

		// Find the free slot for the record and save it
		rid->slot = findFreeSlot(page, rel->schema);

		if (rid->slot == NO_SLOT) { // Append new page, out of space
			RC unpinPageResult;
			if (unpinPageResult = unpinPage(&tableMgmtData->bufferPool, &tableMgmtData->pageHandle) != RC_OK) {
				return unpinPageResult;
			}

			if (appendEmptyBlock(&bufferMgmtData->fh) != RC_OK) {
				return RC_RM_INSERT_RECORD_FAIL;
			}

			rid->page = bufferMgmtData->fh.totalNumPages - 1;

			RC pinPageResult;
			if (pinPageResult = pinPage(&tableMgmtData->bufferPool, &tableMgmtData->pageHandle, rid->page) != RC_OK) {
				return pinPageResult;
			}
			
			//new page, set slot to 0 (first slot)
			page = (RM_Page*)tableMgmtData->pageHandle.data;
			rid->slot = 0;
		}
	}
	else {
	// No free slot so make new page for record
		RC appendEmptyBlockResult;
		if (appendEmptyBlock(&bufferMgmtData->fh) != RC_OK) {
			return RC_RM_INSERT_RECORD_FAIL;
		}

		rid->page = bufferMgmtData->fh.totalNumPages - 1;

		RC pinPageResult;
		if (pinPageResult = pinPage(&tableMgmtData->bufferPool, &tableMgmtData->pageHandle, rid->page) != RC_OK) {
			return pinPageResult;
		}
		page = (RM_Page*)tableMgmtData->pageHandle.data;

		rid->slot = 0;
	
	}

	// Finish writing the record now that we have slot information
	RC markDirtyResult;
	if (markDirtyResult = markDirty(&tableMgmtData->bufferPool, &tableMgmtData->pageHandle) != RC_OK) {
		return markDirtyResult;
	}
	
	// Add header offset to slot position for slot offset
	slotOffset = ((char*)&page->data) + (rid->slot * getRecordSize(rel->schema));

	int recordSize = getRecordSize(rel->schema);
	memcpy(slotOffset + 1, record->data, recordSize);

	// Mark first byte of slot with tombstone information info
	*(char*)slotOffset = 1;

	// Update free slot information
	if (findFreeSlot(page, rel->schema) != NO_SLOT) {
		int pageNum = rid->page;
		addFreeSlot(tableMgmtData, page, rid->page);
	}

	RC unpinPageResult;
	if (unpinPageResult = unpinPage(&tableMgmtData->bufferPool, &tableMgmtData->pageHandle) != RC_OK) {
		return unpinPageResult;
	}
	tableMgmtData->numTuples++;

	return RC_OK;
}
コード例 #9
0
static UA_StatusCode
UA_NodeMap_insertNode(void *context, UA_Node *node,
                      UA_NodeId *addedNodeId) {
    UA_NodeMap *ns = (UA_NodeMap*)context;
    BEGIN_CRITSECT(ns);
    if(ns->size * 3 <= ns->count * 4) {
        if(expand(ns) != UA_STATUSCODE_GOOD) {
            END_CRITSECT(ns);
            return UA_STATUSCODE_BADINTERNALERROR;
        }
    }

    UA_NodeMapEntry **slot;
    if(node->nodeId.identifierType == UA_NODEIDTYPE_NUMERIC &&
            node->nodeId.identifier.numeric == 0) {
        /* create a random nodeid */
        /* start at least with 50,000 to make sure we don not conflict with nodes from the spec */
        /* if we find a conflict, we just try another identifier until we have tried all possible identifiers */
        /* since the size is prime and we don't change the increase val, we will reach the starting id again */
        /* E.g. adding a nodeset will create children while there are still other nodes which need to be created */
        /* Thus the node ids may collide */
        UA_UInt32 size = ns->size;
        UA_UInt64 identifier = mod(50000 + size+1, UA_UINT32_MAX); // start value, use 64 bit container to avoid overflow
        UA_UInt32 increase = mod2(ns->count+1, size);
        UA_UInt32 startId = (UA_UInt32)identifier; // mod ensures us that the id is a valid 32 bit

        do {
            node->nodeId.identifier.numeric = (UA_UInt32)identifier;
            slot = findFreeSlot(ns, &node->nodeId);
            if(slot)
                break;
            identifier += increase;
            if(identifier >= size)
                identifier -= size;
        } while((UA_UInt32)identifier != startId);
    } else {
        slot = findFreeSlot(ns, &node->nodeId);
    }

    if(!slot) {
        deleteEntry(container_of(node, UA_NodeMapEntry, node));
        END_CRITSECT(ns);
        return UA_STATUSCODE_BADNODEIDEXISTS;
    }

    /* Copy the NodeId */
    UA_StatusCode retval = UA_STATUSCODE_GOOD;
    if(addedNodeId) {
        retval = UA_NodeId_copy(&node->nodeId, addedNodeId);
        if(retval != UA_STATUSCODE_GOOD) {
            deleteEntry(container_of(node, UA_NodeMapEntry, node));
            END_CRITSECT(ns);
            return retval;
        }
    }

    /* Insert the node */
    UA_NodeMapEntry *oldEntry = *slot;
    UA_NodeMapEntry *newEntry = container_of(node, UA_NodeMapEntry, node);
    if(oldEntry > UA_NODEMAP_TOMBSTONE ||
       UA_atomic_cmpxchg((void**)slot, oldEntry,
                         newEntry) != oldEntry) {
        deleteEntry(container_of(node, UA_NodeMapEntry, node));
        END_CRITSECT(ns);
        return UA_STATUSCODE_BADNODEIDEXISTS;
    }
    ++ns->count;
    END_CRITSECT(ns);
    return retval;
}