Exemplo n.º 1
0
void g_scheduler::deleteCurrent() {

	g_task_entry* entry_to_remove = current_entry;
	g_thread* thread = entry_to_remove->value;

	// remove from run queue
	g_task_entry* entry_from_run_queue = removeFromQueue(&run_queue, thread);

	// remove from wait queue
	if (entry_from_run_queue == 0) {
		g_task_entry* entry_from_wait_queue = removeFromQueue(&wait_queue, thread);

		if (entry_from_wait_queue == 0) {
			g_log_warn("%! failed to properly delete thread %i, was not assigned to a queue", "scheduler", thread->id);
			return;
		}
	}

	// delete the task
	g_thread_manager::deleteTask(thread);
	delete entry_to_remove;

	// let scheduling choose new one next time
	current_entry = 0;
}
Exemplo n.º 2
0
Texture::~Texture() {
	removeFromQueue(kQueueNewTexture);
	removeFromQueue(kQueueTexture);

	if (_textureID != 0)
		GfxMan.abandon(&_textureID, 1);

	delete _txi;
	delete _image;
}
Exemplo n.º 3
0
void removeParentFromBlockedQueue(Thread *thread) {
	Thread *parent = thread->parent;
	
	if(parent != NULL)
		removeFromQueue(parent->children, thread);

	if(!isQueueEmpty(blockedQueue) && isPresent(blockedQueue, parent)) {
		
		if(isQueueEmpty(parent->children) || (parent->waitingFor == thread)) {
			removeFromQueue(blockedQueue, parent);
			parent->waitingFor = NULL;
			insertIntoQueue(readyQueue, parent);
		}	
	}
}	
Exemplo n.º 4
0
void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result) {
	if (requestId) {
		--queue->queries;
		requestId = 0;
	}
	if (offset == currentOffset()) {
		int32 limit = locationType ? DocumentDownloadPartSize : DownloadPartSize;
		const MTPDupload_file &d(result.c_upload_file());
		const string &bytes(d.vbytes.c_string().v);
		if (bytes.size()) {
			if (file.isOpen()) {
				if (file.write(bytes.data(), bytes.size()) != qint64(bytes.size())) {
					return finishFail();
				}
			} else {
				data.append(bytes.data(), bytes.size());
			}
		}
		if (bytes.size() && !(bytes.size() % 1024)) { // good next offset
//			offset += bytes.size();
		} else {
			type = d.vtype;
			complete = true;
			if (file.isOpen()) {
				file.close();
				psPostprocessFile(QFileInfo(file).absoluteFilePath());
			}
			removeFromQueue();
			App::wnd()->update();
			App::wnd()->psUpdateNotifies();
		}
		emit progress(this);
	}
	loadNext();
}
Exemplo n.º 5
0
void webFileLoader::onFinished(const QByteArray &data) {
	if (_fileIsOpen) {
		if (_file.write(data.constData(), data.size()) != qint64(data.size())) {
			return cancel(true);
		}
	} else {
		_data = data;
	}
	if (!_fname.isEmpty() && (_toCache == LoadToCacheAsWell)) {
		if (!_fileIsOpen) _fileIsOpen = _file.open(QIODevice::WriteOnly);
		if (!_fileIsOpen) {
			return cancel(true);
		}
		if (_file.write(_data) != qint64(_data.size())) {
			return cancel(true);
		}
	}
	_type = mtpc_storage_filePartial;
	_complete = true;
	if (_fileIsOpen) {
		_file.close();
		_fileIsOpen = false;
		psPostprocessFile(QFileInfo(_file).absoluteFilePath());
	}
	removeFromQueue();

	if (_localStatus == LocalNotFound || _localStatus == LocalFailed) {
		Local::writeWebFile(_url, _data);
	}
	emit progress(this);
	FileDownload::ImageLoaded().notify();
	loadNext();
}
Exemplo n.º 6
0
mtpFileLoader::~mtpFileLoader() {
	if (_localTaskId) {
		Local::cancelTask(_localTaskId);
	}
	removeFromQueue();
	cancelRequests();
}
Exemplo n.º 7
0
static CacheData *getCacheData(int device, int block) {
	CacheData *cacheData = findCacheData(device, block);
	if (cacheData==NULL) {
		CacheData *temp = startFreeEntry;	
		while (temp!=NULL && temp->nextFree!=startFreeEntry) {
			if (temp->count==0) {
				if (cacheData==NULL || BADNESS(temp)<BADNESS(cacheData)) {
					cacheData = temp;
					if (BADNESS(temp)==0) {
						break;
					}				
				}				
			}
			temp = temp->nextFree;
		}		
		cacheData->count = 1;
		cacheData->isDirty = false;
		cacheData->isUptoDate = false;
		removeFromQueue(cacheData);
		cacheData->device = device;
		cacheData->block = block;
		insertIntoQueue(cacheData);
	}
	return cacheData;	
}
Exemplo n.º 8
0
    void scheduleNext(std::list<Process*>& readyQueue, unsigned int tick) {
        // No work to do
        if (readyQueue.empty()) {
            executing = NULL;
            return;
        }
        // If there's nothing that was executing before (first run),
        // Grab the first process in the ready queue
        if (executing == NULL) {
            queueLoc = readyQueue.begin();
        }
        executing = *queueLoc;
        // Run the next scheduled process and increment wait times
        executing->run();
        incrWait(readyQueue, executing);
        // If executing process is done, remove it from the ready queue
        // safely
        if (executing->isDone()) {
            removeFromQueue(readyQueue, executing);
        }
        // Round robin, 'rotate' the queue
        else {
            rotateQueue(readyQueue);
        }
        return;

    }
Exemplo n.º 9
0
NETWORK_PROTOCOL_RESULT QuickProtocol::receiveMessage(unsigned char * type, Buffer * data)
{    
    if(receiveQueueBuffer.getSize() < 1+2+1) // Smallest possible
    {
        return NETWORK_PROTOCOL_OUT_OF_BUFFER;
    }
    
	QUICKPROTOCOL_UNPACK_RESULT unpackResult = QuickProtocolPacker::unpackBuffer(&receiveQueueBuffer,type,data);
    if(unpackResult == QUICKPROTOCOL_UNPACK_ERROR)
    {
        receiveQueueBuffer.setSize(0); //trash the queue TODO: recovery ?
        
        
        return NETWORK_PROTOCOL_ERROR;
    }
	else if(unpackResult == QUICKPROTOCOL_UNPACK_NOTCOMPLETE)
	{
		return NETWORK_PROTOCOL_OUT_OF_BUFFER;
	}
    

    removeFromQueue(1+2+data->getSize()+1);
    
    return NETWORK_PROTOCOL_OK;
}
Exemplo n.º 10
0
/*
 This is the main Thread function.
 Every thread gets its job (file) from
 global file list and starts processing.
 */
void *findUniqueIP(void *threadargs)
{
    struct threadArguments *threadArgPtr = (struct threadArguments*)threadargs;
    size_t len = 1000;      //the length of bytes getline will allocate
    size_t read;
    char *line = NULL;
    char *fileToProcess;

    char *curIP = (char *)malloc(MAX_IP_LEN * sizeof(char));
    FILE *file;
 
    pthread_mutex_lock (&fileQueueUpdateLock);
    fileToProcess = removeFromQueue(&globalFileQueue);
    pthread_mutex_unlock (&fileQueueUpdateLock);
    
    while (fileToProcess != NULL)
    {
        file = fopen(fileToProcess, "r");
        
        if(file){
            // Print out each line in the file
            while ((read = getline(&line, &len, file)) != -1)
            {

                myIPstrcopy(curIP, line);
                
                //fprintf(stderr, "\n(%s) (%d)", curIP,strlen(curIP));
                
                insertIP(curIP, strlen(curIP), threadArgPtr);
            }
            fclose(file);
        }
        
        free(fileToProcess);
        
        pthread_mutex_lock (&fileQueueUpdateLock);
        fileToProcess = removeFromQueue(&globalFileQueue);
        pthread_mutex_unlock (&fileQueueUpdateLock);

    //fprintf(stderr, "\n Final unique Count = %u by %u", threadArgPtr->uniqueCount, threadArgPtr->tid);
    }

    destroyThreadArguments(threadArgPtr);

    pthread_exit(NULL);
}
Exemplo n.º 11
0
void g_scheduler::pushInWait(g_thread* thread) {
	g_task_entry* entry = removeFromQueue(&wait_queue, thread);

	if (entry) {
		entry->next = wait_queue;
		wait_queue = entry;
	}
}
Exemplo n.º 12
0
/* free_QueueElements
 * free up memory used by arrayQueue elements
 * queue: the queue being freed
 */
void free_QueueElements (Queue* queue)
{
	int i;
	for (i = 0; i < (*queue).max_capacity; ++i ) {
		void* element  = (void*) displayQueueFront(queue);
		removeFromQueue(queue);
		free(element);
	}
}
Exemplo n.º 13
0
bool Texture::reload(ImageDecoder *image, const TXI *txi) {
	removeFromQueue(kQueueNewTexture);
	removeFromQueue(kQueueTexture);

	if (txi) {
		delete _txi;
		_txi = new TXI(*txi);
	}

	delete _image;

	load(image);

	addToQueue(kQueueTexture);
	addToQueue(kQueueNewTexture);

	return true;
}
Exemplo n.º 14
0
Cube::~Cube() {
	removeFromQueue(kQueueGLContainer);

	for (int i = 0; i < 6; i++)
		delete _sides[i];

	if (_list != 0)
		GfxMan.abandon(_list, 1);
}
TEST(CircularBuffer, EmptyToFullToEmpty)
{
	fillTheQueue(100, buffer->Capacity());

	CHECK(buffer->IsFull());

	removeFromQueue(buffer->Capacity());

	CHECK(buffer->IsEmpty());
}
Exemplo n.º 16
0
void GSVWrapper::removeReadyRequests()
{
    QStringList ids;
    foreach(QSharedPointer<Request> req, requestQueue) {
        if(req->state() == Request::Ready)
            ids.append(req->id);
    }
    foreach(QString str, ids)
        removeFromQueue(str);
}
/*
 This is the main Thread function.
 Every thread gets its job (file) from
 global file list and starts processing.
 */
void *PrintData(void *threadargs)
{
    struct threadArguments *threadArgPtr = (struct threadArguments*)threadargs;
    size_t len = 1000;      //the length of bytes getline will allocate
    size_t read;
    char *line = NULL;
    char *fileToProcess;
   
    FILE *file;
    
    pthread_mutex_lock (&fileQueueUpdateLock);
    fileToProcess = removeFromQueue(&globalFileQueue);
    pthread_mutex_unlock (&fileQueueUpdateLock);
    
    while (fileToProcess != NULL)
    {
        file = fopen(fileToProcess, "r");
        
        if(file){
            // Print out each line in the file
            while ((read = getline(&line, &len, file)) != -1)
            {
                printf("Retrieved line of length %d- threadId = %d  (%s):\n", read, threadArgPtr->tid, fileToProcess);
                printf("%s", line);
            }
            fclose(file);
        }
        
        free(fileToProcess);
        
        pthread_mutex_lock (&fileQueueUpdateLock);
        fileToProcess = removeFromQueue(&globalFileQueue);
        pthread_mutex_unlock (&fileQueueUpdateLock);
        
        //fprintf(stderr, "\n Final unique Count = %u", threadArgPtr->uniqueCount);
    }
    
    destroyThreadArguments(threadArgPtr);
    
    pthread_exit(NULL);
}
TEST(CircularBuffer, FillEmptyThenPrint)
{
	MockPrinter mock;

	fillTheQueue(200, buffer->Capacity());
	removeFromQueue(buffer->Capacity());
	buffer->Print(&mock);
	//	const char* expected = "Circular buffer content:\n"
	//		"<>\n";

	//	CHECK_EQUAL(expected, mock.getOutput());
}
Exemplo n.º 19
0
void g_scheduler::moveToRunQueue(g_thread* thread) {

	g_task_entry* move_entry = removeFromQueue(&wait_queue, thread);

	if (move_entry == 0) {
		// entry is already in run queue
		return;
	}

	// put to start of run queue
	move_entry->next = run_queue;
	run_queue = move_entry;
}
Exemplo n.º 20
0
/*
 * 发送一个推迟消息,该消息将在下次改变状态机状态时被处理
 * 参数:
 *     msg          - 目标消息
 * 返回值:
 */
void defer_message(MSG* msg)
{
    ENTER_LOG();

    if (msg==NULL) {
        LEAVE_LOG();
        return;
    }

    removeFromQueue(msg);
    addToQueue(msg, &msg->handler->defer_msg_queue);

    LEAVE_LOG();
}
Exemplo n.º 21
0
bool Texture::reload(const Common::UString &name) {
	if (!name.empty())
		_name = name;

	if (_name.empty())
		// Yeah, we don't know the resource name, so we can't reload the texture
		return false;

	removeFromQueue(kQueueNewTexture);
	removeFromQueue(kQueueTexture);

	delete _txi;
	delete _image;

	_txi = new TXI();

	load(_name);

	addToQueue(kQueueTexture);
	addToQueue(kQueueNewTexture);

	return true;
}
Exemplo n.º 22
0
static void test_remove_from_queue() {
    Queue *queue = (Queue *)malloc(sizeof(Queue));
    initializeQueue(queue);
    Thread *thread1 = malloc(sizeof(Thread));
    Thread *thread2 = malloc(sizeof(Thread));
    Thread *thread3 = malloc(sizeof(Thread));
    insertIntoQueue(queue, thread1);
    insertIntoQueue(queue, thread2);
    insertIntoQueue(queue, thread3);
    assert(sizeOfQueue(queue) == 3);
    removeFromQueue(queue, thread3);
    printQueue(queue);
    assert(sizeOfQueue(queue) == 2);
}
TEST(CircularBuffer, WrapAround)
{
	fillTheQueue(100, buffer->Capacity());

	CHECK(buffer->IsFull());
	LONGS_EQUAL(100, buffer->Get());
	CHECK(!buffer->IsFull());
	buffer->Put(1000);
	CHECK(buffer->IsFull());

	removeFromQueue(buffer->Capacity() - 1);

	LONGS_EQUAL(1000, buffer->Get());
	CHECK(buffer->IsEmpty());
}
TEST(CircularBuffer, PrintBoundary)
{
	MockPrinter mock;

	fillTheQueue(200, buffer->Capacity());
	removeFromQueue(buffer->Capacity() - 2);
	buffer->Put(888);
	fillTheQueue(300, buffer->Capacity() - 1);

	buffer->Print(&mock);
	//	const char* expected = "Circular buffer content:\n"
	//		"<888, 300, 301, 302, 303>\n";

	//	CHECK_EQUAL(expected, mock.getOutput());
}
Exemplo n.º 25
0
FskErr androidAudioOutStop(FskAudioOut audioOut) {
	androidAudioExt	*ext;
	FskSampleTime pos;
	SLresult	res;
	FskErr err = kFskErrNone;

	FskAudioNativePrintfVerbose("audioOutStop %x", audioOut);

	BAIL_IF_NULL(audioOut, err, kFskErrNone);

	ext = (androidAudioExt*)audioOut->ext;
	BAIL_IF_NULL(ext, err, kFskErrNone);

	if (ext->flushTimer) {
		FskAudioNativePrintfVerbose("%x -- Disposing of flushTimer", audioOut);
		FskTimeCallbackDispose(ext->flushTimer);
		ext->flushTimer = NULL;
	}

	if (!audioOut->playing) {
		FskAudioNativePrintfDebug(" -- wuzn't playin");
		BAIL(kFskErrNone);
	}


	androidAudioOutGetSamplePosition(audioOut, &ext->stoppedAtSamplePosition);	// get final pos before we shut it down
	FskAudioNativePrintfVerbose("stoppedAtSamplePosition = %lld", ext->stoppedAtSamplePosition);

	audioOut->playing = false;
	FskAudioNativePrintfVerbose("-- stopping audioOut: %x", audioOut);

	res = (*ext->playItf)->SetPlayState(ext->playItf, SL_PLAYSTATE_STOPPED);
	CheckErr(" audioOutStop - set playstate stopped", res);

	if (gActiveAudioOut == audioOut) {
		FskMutexAcquire(gActiveAudioMutex);
		gActiveAudioOut = NULL;
		FskMutexRelease(gActiveAudioMutex);
	}

	androidAudioOutFlush(audioOut);

bail:
	removeFromQueue(audioOut, kAll);

	return err;
}
Exemplo n.º 26
0
void flushAndRefill(void *arg0, void *arg1, void *arg2, void *arg3) {
	FskAudioOut audioOut = (FskAudioOut)arg0;
	androidAudioExt *ext;
	Boolean isValid = false;

//FskAudioNativePrintfDebug("- flushAndRefill");
	if ((kFskErrNone != FskAudioOutIsValid(audioOut, &isValid)) || !isValid)
		return;

	ext = (androidAudioExt*)audioOut->ext;

	removeFromQueue(audioOut, kUsed);
	if (false == audioOut->playing)
		return;

	refillQueue(audioOut);
}
Exemplo n.º 27
0
/* addToQueue
 * Adds node to back of queue
 * - queue: the queue being added to
 * - node: the node being added
 */
void addToQueue (Queue* queue, const void* node)
{
	// Check if there are already max capacity items
	if ( ((*queue).front + (*queue).rear) == ((*queue).max_capacity - 1) ) {
		(*queue).size = true;
	}
	// Remove the front from the queue if max capacity has been reached
	if ((*queue).size == true) {
		removeFromQueue(queue);
	}
	// If queue is initially empty, set index of first element to 0 in array queue
	if ((*queue).front == -1) {
		(*queue).front = 0;
	}
	// Increase the rear index by one and add element
	(*queue).rear = (*queue).rear + 1;
	(*queue).queue_elements[(*queue).rear] = node;
}
Exemplo n.º 28
0
void g_scheduler::moveToWaitQueue(g_thread* thread) {

	g_task_entry* move_entry = removeFromQueue(&run_queue, thread);

	if (move_entry == 0) {
		// entry is already in wait queue
		return;
	}

	// put to start of wait queue
	move_entry->next = wait_queue;
	wait_queue = move_entry;

	// may no more be the running entry
	if (move_entry == current_entry) {
		current_entry = nullptr;
	}
}
Exemplo n.º 29
0
// 把消息从所在列表中移除掉
void remove_from_list(MSG* msg)
{
    ENTER_LOG();
    if (msg==NULL) {
        LEAVE_LOG();
        return;
    }

    // 当loop中处理了该消息后,会自动删除,这边不要重复删除
    if (msg->ev.next!=NULL && msg->ev.prev!=NULL)
    {
        upil_printf(MSG_EXCESSIVE, "Remove event=%p\n", &msg->ev);
        uew_event_del(&msg->handler->loop, &msg->ev, 1);
    } else
        upil_printf(MSG_EXCESSIVE, "msg->ev is empty!");

    removeFromQueue(msg);
    --msg->handler->msg_count;

    LEAVE_LOG();
}
Exemplo n.º 30
0
/**
 * invokes the cache method on all queued audio events
 * (this will also remove them from the queue)
 *
 * in case the BulkCacher was constructed to work in
 * sequence, this method will cache the queue one event at a time
 * note that this method must be invoked after each cache-invocation
 * from the freshly cached event when it finishes its caching routine
 */
void BulkCacher::cacheQueue()
{
    int amount = _queue->size();

    //Debug::log( "BulkCacher::caching %d events", amount );

    for ( int i = 0; i < amount; i++ )
    {
        BaseCacheableAudioEvent* event = _queue->at( i );

        // (interesting detail must remove the event from the queue
        // BEFORE invoking cache (isn't executed synchronously and
        // would cause a recursive loop!)

        removeFromQueue( event );
        event->cache( _sequential );

        // just one when sequential

        if ( _sequential )
            return;
    }
    clearQueue(); // superfluous actually
}