HCIACLPDU AclEngine::Implementation::ChannelList::Channel::Send::getPdu(bool &isSendablePdu)
{
    CriticalSection::Lock lock(mCs);
    HCIACLPDU pdu(null_pdu);

    while (true)
    {
        fillQueue();
        if (queue.empty())
        {
            isSendablePdu = false;
            return pdu;
        }
        else if (queue.front()->getPdu(pdu))
        {
            ++tokensUsed;
            isSendablePdu = true;
            return pdu;
        }
        else
        {
            queue.pop_front();
        }
    }
}
TEST_F(MpscQueueTest, shouldFailToOfferToFullQueue)
{
    int64_t element = CAPACITY + 1;

    fillQueue();
    EXPECT_EQ(aeron_mpsc_concurrent_array_queue_size(&m_q), CAPACITY);
    EXPECT_EQ(aeron_mpsc_concurrent_array_queue_offer(&m_q, (void *)element), AERON_OFFER_FULL);
}
Exemple #3
0
	Token raven::Lexer::peek(int i) {
		if (fillQueue(i)) {
			return deque.front();
		}
		else {
			return Token::EofToken();
		}
	}
Exemple #4
0
int main()
{
	CQueue *pQueue;
	pQueue = new CQueue();
	fillQueue(pQueue, 3);
	pQueue->printJobs();
	pQueue->pop();
	pQueue->printJobs();
	return 0;
}
Exemple #5
0
	Token raven::Lexer::read() {
		Token t;
		if (fillQueue(0)) {
			t = deque.front();
			deque.pop_front();
			return t;
		}
		else {
			return Token::EofToken();
		}
	}
TEST_F(MpscQueueTest, shouldDrainSingleElementFromFullQueue)
{
    fillQueue();

    m_drain = [&](volatile void *e)
    {
        ASSERT_EQ(e, (void *)1);
    };

    EXPECT_EQ(aeron_mpsc_concurrent_array_queue_drain(&m_q, MpscQueueTest::drain_func, this, 1), 1u);
    EXPECT_EQ(aeron_mpsc_concurrent_array_queue_size(&m_q), CAPACITY - 1);
}
TEST_F(MpscQueueTest, shouldDrainFullQueue)
{
    fillQueue();

    int64_t counter = 1;
    m_drain = [&](volatile void *e)
    {
        ASSERT_EQ(e, (void *)counter);
        counter++;
    };

    EXPECT_EQ(aeron_mpsc_concurrent_array_queue_drain_all(&m_q, MpscQueueTest::drain_func, this), CAPACITY);
    EXPECT_EQ(aeron_mpsc_concurrent_array_queue_size(&m_q), 0u);
}
TEST_F(MpscQueueTest, shouldDraingFullQueueWithLimit)
{
    uint64_t limit = CAPACITY / 2;
    fillQueue();

    int64_t counter = 1;
    m_drain = [&](volatile void *e)
    {
        ASSERT_EQ(e, (void *)counter);
        counter++;
    };

    EXPECT_EQ(aeron_mpsc_concurrent_array_queue_drain(&m_q, MpscQueueTest::drain_func, this, limit), limit);
    EXPECT_EQ(aeron_mpsc_concurrent_array_queue_size(&m_q), CAPACITY - limit);
}
Exemple #9
0
int main(){
	time_t t1, t2;
	double t0;
	time(&t1);
	
	FILE *dataFile;
	dataFile = fopen("cs451.conf", "r");
	if (dataFile == NULL)
	{
		printf("cannot open file\n");
		exit(0);
	}
	char temp[128];
	char item[128];
	char maxProcesses[42], timeQuantum[42];
	while(fscanf(dataFile, "%s", temp) != EOF)
	{
		if (strstr(temp, "processes:") != NULL)
		{
			fscanf(dataFile, "%s", maxProcesses);
		}
		else if (strstr(temp, "quantum:") != NULL)
		{
			fscanf(dataFile, "%s", timeQuantum);
		}
		else if (strstr(temp, ":") != NULL)
		{
			fscanf(dataFile, "%s", item);
		}
	}
	fclose(dataFile);
	
	createFiles();
	
	fillQueue(atoi(maxProcesses));
	//printQueue();
	simulate(atoi(maxProcesses));
	freeStuff();
	
	deleteFiles();
	
	time(&t2);
	t0 = difftime(t2, t1);
	printf("Program run-time: %.0f seconds\n", t0);
}
Exemple #10
0
int main(){
	FILE *dataFile;
	dataFile = fopen("cs451.conf", "r");
	if (dataFile == NULL)
	{
		printf("cannot open file\n");
		exit(0);
	}
	char temp[128];
	char item[128];
	char maxProcesses[42], timeQuantum[42];
	while(fscanf(dataFile, "%s", temp) != EOF)
	{
		if (strstr(temp, "processes:") != NULL)
		{
			fscanf(dataFile, "%s", maxProcesses);
		}
		else if (strstr(temp, "quantum:") != NULL)
		{
			fscanf(dataFile, "%s", timeQuantum);
		}
		else if (strstr(temp, ":") != NULL)
		{
			fscanf(dataFile, "%s", item);
			//enqueue item
			//enqueue(atoi(item)); 
			//printf("%s\n", item);
		}
	}
	fclose(dataFile);
	
	fillQueue(atoi(maxProcesses));
	//printQueue();
	simulate();
	freeStuff();
}
Exemple #11
0
void SoundStream::streamData()
{
    // Create the buffers
    alCheck(alGenBuffers(BufferCount, m_buffers));
    for (int i = 0; i < BufferCount; ++i)
        m_endBuffers[i] = false;

    // Fill the queue
    bool requestStop = fillQueue();

    // Play the sound
    alCheck(alSourcePlay(m_source));

    while (m_isStreaming)
    {
        // The stream has been interrupted!
        if (SoundSource::getStatus() == Stopped)
        {
            if (!requestStop)
            {
                // Just continue
                alCheck(alSourcePlay(m_source));
            }
            else
            {
                // End streaming
                m_isStreaming = false;
            }
        }

        // Get the number of buffers that have been processed (ie. ready for reuse)
        ALint nbProcessed = 0;
        alCheck(alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &nbProcessed));

        while (nbProcessed--)
        {
            // Pop the first unused buffer from the queue
            ALuint buffer;
            alCheck(alSourceUnqueueBuffers(m_source, 1, &buffer));

            // Find its number
            unsigned int bufferNum = 0;
            for (int i = 0; i < BufferCount; ++i)
                if (m_buffers[i] == buffer)
                {
                    bufferNum = i;
                    break;
                }

            // Retrieve its size and add it to the samples count
            if (m_endBuffers[bufferNum])
            {
                // This was the last buffer: reset the sample count
                m_samplesProcessed = 0;
                m_endBuffers[bufferNum] = false;
            }
            else
            {
                ALint size, bits;
                alCheck(alGetBufferi(buffer, AL_SIZE, &size));
                alCheck(alGetBufferi(buffer, AL_BITS, &bits));
                m_samplesProcessed += size / (bits / 8);
            }

            // Fill it and push it back into the playing queue
            if (!requestStop)
            {
                if (fillAndPushBuffer(bufferNum))
                    requestStop = true;
            }
        }

        // Leave some time for the other threads if the stream is still playing
        if (SoundSource::getStatus() != Stopped)
            sleep(milliseconds(10));
    }

    // Stop the playback
    alCheck(alSourceStop(m_source));

    // Unqueue any buffer left in the queue
    clearQueue();

    // Delete the buffers
    alCheck(alSourcei(m_source, AL_BUFFER, 0));
    alCheck(alDeleteBuffers(BufferCount, m_buffers));
}
Exemple #12
0
void SoundStream::streamData()
{
    bool requestStop = false;

    {
        Lock lock(m_threadMutex);

        // Check if the thread was launched Stopped
        if (m_threadStartState == Stopped)
        {
            m_isStreaming = false;
            return;
        }
    }

    // Create the buffers
    alCheck(alGenBuffers(BufferCount, m_buffers));
    for (int i = 0; i < BufferCount; ++i)
        m_endBuffers[i] = false;

    // Fill the queue
    requestStop = fillQueue();

    // Play the sound
    alCheck(alSourcePlay(m_source));

    {
        Lock lock(m_threadMutex);

        // Check if the thread was launched Paused
        if (m_threadStartState == Paused)
            alCheck(alSourcePause(m_source));
    }

    for (;;)
    {
        {
            Lock lock(m_threadMutex);
            if (!m_isStreaming)
                break;
        }

        // The stream has been interrupted!
        if (SoundSource::getStatus() == Stopped)
        {
            if (!requestStop)
            {
                // Just continue
                alCheck(alSourcePlay(m_source));
            }
            else
            {
                // End streaming
                Lock lock(m_threadMutex);
                m_isStreaming = false;
            }
        }

        // Get the number of buffers that have been processed (i.e. ready for reuse)
        ALint nbProcessed = 0;
        alCheck(alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &nbProcessed));

        while (nbProcessed--)
        {
            // Pop the first unused buffer from the queue
            ALuint buffer;
            alCheck(alSourceUnqueueBuffers(m_source, 1, &buffer));

            // Find its number
            unsigned int bufferNum = 0;
            for (int i = 0; i < BufferCount; ++i)
                if (m_buffers[i] == buffer)
                {
                    bufferNum = i;
                    break;
                }

            // Retrieve its size and add it to the samples count
            if (m_endBuffers[bufferNum])
            {
                // This was the last buffer: reset the sample count
                m_samplesProcessed = 0;
                m_endBuffers[bufferNum] = false;
            }
            else
            {
                ALint size, bits;
                alCheck(alGetBufferi(buffer, AL_SIZE, &size));
                alCheck(alGetBufferi(buffer, AL_BITS, &bits));

                // Bits can be 0 if the format or parameters are corrupt, avoid division by zero
                if (bits == 0)
                {
                    err() << "Bits in sound stream are 0: make sure that the audio format is not corrupt "
                          << "and initialize() has been called correctly" << std::endl;

                    // Abort streaming (exit main loop)
                    Lock lock(m_threadMutex);
                    m_isStreaming = false;
                    requestStop = true;
                    break;
                }
                else
                {
                    m_samplesProcessed += size / (bits / 8);
                }
            }

            // Fill it and push it back into the playing queue
            if (!requestStop)
            {
                if (fillAndPushBuffer(bufferNum))
                    requestStop = true;
            }
        }

        // Leave some time for the other threads if the stream is still playing
        if (SoundSource::getStatus() != Stopped)
            sleep(milliseconds(10));
    }

    // Stop the playback
    alCheck(alSourceStop(m_source));

    // Dequeue any buffer left in the queue
    clearQueue();

    // Delete the buffers
    alCheck(alSourcei(m_source, AL_BUFFER, 0));
    alCheck(alDeleteBuffers(BufferCount, m_buffers));
}