Example #1
0
//--------------------------------------------------------------------------
bool VeJob::Start() noexcept
{
	IncRefCount();
	{
		std::lock_guard<vtd::spin_lock> lock(m_kLock);
		if (m_u32Pointer == 0 && m_u32Wait == 0 && m_kTaskArray.size())
		{
			VE_ASSERT(m_kRelatedJobs.empty());
			m_u32Pointer = 1;
		}
		else
		{
			return false;
		}
	}
	auto& kAtom = m_kTaskArray.front();
	if (kAtom.m_eExecute == VeJob::EXE_BACKGROUND)
	{
		ve_job_sys.m_akBGQueues[kAtom.m_ePriority].push(this);
		ve_job_sys.m_i32BGJobNum.fetch_add(1, std::memory_order_relaxed);
		auto pt = ve_job_sys.m_kWaitingThreads.pop();
		if (pt)
		{
			pt->loop.set();
		}
	}
	else
	{
		size_t stFrame = ve_job_sys.m_u32FrameCount.load(std::memory_order_relaxed) & 1;
		stFrame = kAtom.m_eExecute == VeJob::EXE_FG_CURRENT ? stFrame : (!stFrame);
		ve_job_sys.m_akFGQueues[stFrame][kAtom.m_ePriority].push(this);
	}
	return true;
}
Example #2
0
 CObject(const CObject& obj)
 : m_PyObject(obj)
 // , m_Ownership(eOwned)
 {
     _ASSERT(Get());
     IncRefCount(Get());
 }
Example #3
0
// copy constructor
MojoId::MojoId( const MojoId& other )
{
  m_HashValue = other.m_HashValue;
  if( m_HashValue )
  {
    IncRefCount( m_HashValue );
  }
}
Example #4
0
 explicit CObject(PyObject* obj, EOwnership ownership = eAcquireOwnership)
 : m_PyObject(obj)
 // , m_Ownership(eAcquireOwnership ? eAcquired : eOwned)  // !!! Currently this parameter does not much value of "ownership"
 {
     _ASSERT(Get());
     if ( ownership == eAcquireOwnership ) {
         IncRefCount(Get());
     }
 }
Example #5
0
MojoId& MojoId::operator= ( const MojoId& other )
{
  if( m_HashValue != other.m_HashValue )
  {
    if( !other.IsNull() ) IncRefCount( other.m_HashValue );
    if( !IsNull() )       DecRefCount( m_HashValue );
    m_HashValue = other.m_HashValue;
  }
  return *this;
}
Example #6
0
    /// Not exception-safe this time
    void Set(PyObject* obj, EOwnership ownership = eAcquireOwnership)
    {
        _ASSERT(obj);

        Release();
        m_PyObject = obj;
        if ( ownership == eAcquireOwnership )
        {
            IncRefCount(*this);
        }
    }
Example #7
0
//--------------------------------------------------------------------------
VeFilePath::WriteTask::WriteTask(const VeChar8* pcFullPath,
	const VeMemoryOStreamPtr& spContent,
	VeRefNode<WriteCallback>& kCallback,
	bool bAppend) noexcept
	: m_kFullPath(pcFullPath), m_spData(spContent)
{
	IncRefCount();
	m_kNode.m_Content = this;
	ve_sys.Collect(m_kNode);
	m_kCallback.attach_back(kCallback);
	m_kTask.m_Content = [this,bAppend](VeTaskQueue& kMgr) noexcept
	{
		FILE* pkFile(nullptr);
		const VeChar8* pcMode = bAppend ? "ab" : "wb";
#		ifdef VE_PLATFORM_WIN
		fopen_s(&pkFile, m_kFullPath, pcMode);
#		else
		pkFile = fopen(m_kFullPath, pcMode);
#		endif
		if (pkFile)
		{
			VeSizeT stWrite = fwrite(m_spData->GetDataForRead(),
				1, m_spData->RemainingLength(), pkFile);
			fclose(pkFile);
			if (stWrite == m_spData->RemainingLength())
			{
				m_eResult = VE_S_OK;
			}
			else
			{
				m_eResult = VE_E_FILE_WRITE;
			}
			m_spData->AfterReadData(stWrite);
		}
		else
		{
			m_eResult = VE_E_FILE_CREATE;
		}
		m_kTask.m_Content = [this](VeTaskQueue& kMgr) noexcept
		{
			for (auto call : m_kCallback)
			{
				call(m_eResult);
			}
			DecRefCount();
		};
		kMgr.AddFGTask(m_kTask);
	};
	ve_res_mgr.GetTaskQueue(VeResourceManager::TASK_FILE).AddBGTask(m_kTask);
}
Example #8
0
//--------------------------------------------------------------------------
VeFilePath::ReadTask::ReadTask(const VeChar8* pcFullPath,
	VeRefNode<ReadCallback>& kCallback) noexcept
	: m_kFullPath(pcFullPath)
{
	IncRefCount();
	m_kNode.m_Content = this;
	ve_sys.Collect(m_kNode);
	m_kCallback.attach_back(kCallback);
	m_kTask.m_Content = [this](VeTaskQueue& kMgr) noexcept
	{
		if (VE_SUCCEEDED(VeAccess(m_kFullPath, ACCESS_R_OK)))
		{
			FILE* pkFile(nullptr);
#			ifdef VE_PLATFORM_WIN
			fopen_s(&pkFile, m_kFullPath, "rb");
#			else
			pkFile = fopen(m_kFullPath, "rb");
#			endif
			if (pkFile)
			{
				fseek(pkFile, 0, SEEK_END);
				VeSizeT stLen = ftell(pkFile);
				fseek(pkFile, 0, SEEK_SET);
				VeBlobPtr spBlob = VE_NEW VeBlob(stLen);
				VeSizeT stRead = fread(spBlob->GetBuffer(), 1, stLen, pkFile);
				fclose(pkFile);
				if (stRead == stLen)
				{
					m_spData = VE_NEW VeMemoryIStream(spBlob);
				}
			}
		}
		m_kTask.m_Content = [this](VeTaskQueue& kMgr) noexcept
		{
			for (auto call : m_kCallback)
			{
				call(m_spData);
			}
			DecRefCount();
		};
		kMgr.AddFGTask(m_kTask);
	};
	ve_res_mgr.GetTaskQueue(VeResourceManager::TASK_FILE).AddBGTask(m_kTask);
}
Example #9
0
uint64_t MojoIdManager::Insert( const char* c_string )
{
    uint64_t hash_code = MojoFnv64( c_string );
    if( hash_code && !m_Status )
    {
        Entry entry = m_HashMap.Find( hash_code );
        if( !entry.m_CString )
        {
            size_t length = strlen( c_string );
            char* string_mem = ( char * )m_Alloc->Allocate( length + 1, "MojoId string" );
            memcpy( string_mem, c_string, length );
            string_mem[ length ] = 0;
            entry.m_RefCount = 0;
            entry.m_CString = string_mem;
            m_HashMap.Insert( hash_code, entry );
        }
        IncRefCount( hash_code );
    }
    return hash_code;
}
Example #10
0
//--------------------------------------------------------------------------
VeAssetPath::ReadTask::ReadTask(const VeChar8* pcFullPath,
	VeRefNode<ReadCallback>& kCallback) noexcept
	: m_kFullPath(pcFullPath)
{
	IncRefCount();
	m_kNode.m_Content = this;
	ve_sys.Collect(m_kNode);
	m_kCallback.attach_back(kCallback);
	m_kTask.m_Content = [this](VeTaskQueue& kMgr) noexcept
	{
		AAsset* pkAsset = AAssetManager_open(s_pkAssetManager,
			m_kFullPath, AASSET_MODE_UNKNOWN);
		if (pkAsset)
		{
			VeInt32 i32Len = AAsset_getLength(pkAsset);
			if (i32Len)
			{
				VeBlobPtr spBlob = VE_NEW VeBlob(i32Len);
				VeInt32 i32Read = AAsset_read(pkAsset,
					spBlob->GetBuffer(), i32Len);
				if (i32Read == i32Len)
				{
					m_spData = VE_NEW VeMemoryIStream(spBlob);
				}
			}
			AAsset_close(pkAsset);
		}
		m_kTask.m_Content = [this](VeTaskQueue& kMgr) noexcept
		{
			for (auto call : m_kCallback)
			{
				call(m_spData);
			}
			DecRefCount();
		};
		kMgr.AddFGTask(m_kTask);
	};
	ve_res_mgr.GetTaskQueue(VeResourceManager::TASK_FILE).AddBGTask(m_kTask);
}
Example #11
0
 /// Creates a python None object
 CObject(void)
 : m_PyObject(Py_None)
 // , m_Ownership(eOwned)
 {
     IncRefCount(Get());
 }
Example #12
0
BOOL CSocketObj::ConnectSer(CCustomIOCPBaseList &IOCPList, LPCTSTR SerAddr, int Port, int IncRefNumber)
{
	BOOL resu = FALSE;
	ADDRINFOT _Hints;
	int _Retval;
	PADDRINFOT _ResultAddInfo;
	PADDRINFOT _NextAddInfo;
	DWORD _AddrStringLen;
	LPTSTR _AddrString;

	assert(mIsSerSocket == FALSE);
	ZeroMemory(&_Hints, sizeof(_Hints));
	_Hints.ai_family = AF_UNSPEC;
	_Hints.ai_socktype = SOCK_STREAM;
	_Hints.ai_protocol = IPPROTO_TCP;
	_Retval = GetAddrInfo(SerAddr, to_tstring(Port).c_str(), &_Hints, &_ResultAddInfo);
	if (_Retval != 0) {
		return FALSE;
	}
	_NextAddInfo = _ResultAddInfo;

	// 申请缓冲区
	_AddrString = new TCHAR[ADDR_STRING_MAX_LEN];

	while (_NextAddInfo != NULL) {
		_AddrStringLen = ADDR_STRING_MAX_LEN;
		// 获取
#ifdef _DEBUG
		if (WSAAddressToString(_NextAddInfo->ai_addr, (DWORD)_NextAddInfo->ai_addrlen, NULL,
			_AddrString, &_AddrStringLen) == 0) {
			// 改为真实长度,这里的_AddrStringLen包含了末尾的字符#0,所以要减去这个#0的长度
			_AddrStringLen--;
			OutputDebugStr(_T("ai_addr:%s,ai_flags:%d,ai_canonname=%s\n"),
				_AddrString, _NextAddInfo->ai_flags, _NextAddInfo->ai_canonname);
		} else {
			OutputDebugStr(_T("WSAAddressToString Error:%d\n"), WSAGetLastError());
		}
#endif
		mSock = WSASocket(_NextAddInfo->ai_family, _NextAddInfo->ai_socktype,
			_NextAddInfo->ai_protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
		if (mSock != INVALID_SOCKET) {
			if (connect(mSock, _NextAddInfo->ai_addr, (INT)_NextAddInfo->ai_addrlen) == SOCKET_ERROR) {
				DWORD LastError = WSAGetLastError();

				OutputDebugStr(_T("连接%s失败:%d\n"), _AddrString, LastError);

				closesocket(mSock);
				WSASetLastError(LastError);
				mSock = INVALID_SOCKET;
			} else {
				mOwner = &IOCPList;
				// 增加引用
				IncRefCount(IncRefNumber);
				resu = IOCPList.AddSockBase(this);
				if (!resu) {
					DWORD LastError = WSAGetLastError();
					OutputDebugStr(_T("添加%s到列表中失败:%d\n"), _AddrString, LastError);
					closesocket(mSock);
					WSASetLastError(LastError);
					mSock = INVALID_SOCKET;
					// 减少引用
					DecRefCount(IncRefNumber);
				}
				break;
			}
		}
		_NextAddInfo = _NextAddInfo->ai_next;
	}
	delete[] _AddrString;
	FreeAddrInfo(_ResultAddInfo);
	return resu;
}