Пример #1
0
void _my_free(void* p)
{
	struct alloc_debug_node* m = (struct alloc_debug_node*)p;
	--m;

	WRITELOCK(_g_alloc_debug_list._locker);
	double_list_remove(&_g_alloc_debug_list._link,&m->_link_node);
	_g_alloc_debug_list._count --;
	WRITEUNLOCK(_g_alloc_debug_list._locker);

	free(m);
}
Пример #2
0
void uninit_squeue_node_pool()
{
	struct squeue_node* node;
	WRITELOCK(_g_squeue_pool._locker);
	while(_g_squeue_pool._head)
	{
		node = _g_squeue_pool._head;
		_g_squeue_pool._head = _g_squeue_pool._head->_next;
		my_free(node);
	}
	_g_squeue_pool._count = 0;
	WRITEUNLOCK(_g_squeue_pool._locker);
}
Пример #3
0
void* _my_malloc(size_t size,const char* file,int line)
{
	struct alloc_debug_node* m = (struct alloc_debug_node*)malloc(sizeof(struct alloc_debug_node)+size);
	m->_file = file;
	m->_line = line;
	m->_size = (int)size;

	WRITELOCK(_g_alloc_debug_list._locker);
	double_list_add_tail(&_g_alloc_debug_list._link,&m->_link_node);
	_g_alloc_debug_list._count ++;
	WRITEUNLOCK(_g_alloc_debug_list._locker);

	return m+1;
}
Пример #4
0
struct squeue_node* get_squeue_node()
{
	struct squeue_node* node = NULL;

	WRITELOCK(_g_squeue_pool._locker);
	if(_g_squeue_pool._head && _g_squeue_pool._head->_free_time < get_mytime())
	{
		node = _g_squeue_pool._head;
		_g_squeue_pool._head = _g_squeue_pool._head->_next;
		-- _g_squeue_pool._count;
	}
	WRITEUNLOCK(_g_squeue_pool._locker);

	if(NULL == node)
	{
		node = my_new(struct squeue_node);
	}
Пример #5
0
void free_squeue_node(struct squeue_node* node)
{
	node->_next = NULL;
	node->_free_time = get_mytime()+60;

	WRITELOCK(_g_squeue_pool._locker);
	if(_g_squeue_pool._tail)
	{
		_g_squeue_pool._tail->_next = node;
	}
	else
	{
		_g_squeue_pool._head = node;
	}
	_g_squeue_pool._tail = node;
	++ _g_squeue_pool._count;
	WRITEUNLOCK(_g_squeue_pool._locker);
}
Пример #6
0
void print_unfree_record()
{
	struct alloc_debug_node* m;
	struct double_list_node* node;
	int fd;
	WRITELOCK(_g_alloc_debug_list._locker);
	if(_g_alloc_debug_list._count > 0)
	{
		fd = open("alloc_debug.log",O_CREAT|O_WRONLY|O_APPEND,0666);
		assert(fd != -1);
		_write_alloc_debug_title(fd,_g_alloc_debug_list._count);
		node = (struct double_list_node*)_g_alloc_debug_list._link._head;
		while(node)
		{
			m = (struct alloc_debug_node*)node;
			_write_alloc_debug_log(fd,m->_file,m->_line,m->_size);
			node = node->_next;
		}
		close(fd);
	}
	WRITEUNLOCK(_g_alloc_debug_list._locker);
}
Пример #7
0
void TcpServer::incomingConnection(qintptr socketDescriptor) {

    if (threadPool.size() < maxConnections) {
        QThread *thread = new QThread;
        Client *client = new Client(socketDescriptor);
        client->moveToThread(thread);

        connect(thread, SIGNAL(started()), client, SLOT(run()));

        connect(client, SIGNAL(newGame(QString, QString, QList<QString>)),this,SLOT(newGame(QString, QString, QList<QString>)));
        connect(client, SIGNAL(startGame(QString)),this,SLOT(readyToStart(QString)));
        connect(this, SIGNAL(sendData(QList<QPair<QString,Snake*> >,QList<Food*>)), client, SLOT(sendData(QList<QPair<QString,Snake*> >,QList<Food*>)));

        connect(this, SIGNAL(transmit(Client*,QList<QString>)), client, SLOT(transmit(Client*,QList<QString>)));

        connect(client, SIGNAL(changeDirect(int,QString)), this, SLOT(setDirect(int,QString)));
        connect(client, SIGNAL(disconnected(Client*)), this, SLOT(removeClient(Client*)));
        connect(this, SIGNAL(endOfGame(QString,QString)), client, SLOT(gameOver(QString,QString)));                  //end of the game

        thread->start();

        WRITELOCK(threadPool.insert(client,thread));
    }