mirror of https://github.com/axmolengine/axmol.git
issue #854: pthread work ok on iOS
This commit is contained in:
parent
81b8fc0ce8
commit
522386a6b7
|
@ -1 +1 @@
|
|||
8575c43b860eea3c0f02d9543e58b74073e40e6d
|
||||
f75a8c50e01404209e0c065b8d040d973cfc0fc0
|
|
@ -1 +1 @@
|
|||
c1cdd4b0d66de5127dc37f73eb9895737ca3e18d
|
||||
f9ca064a5aba796aacdc647bb44c2f8a0658707c
|
|
@ -24,18 +24,16 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCThread.h"
|
||||
|
||||
#if CC_SUPPORT_MULTITHREAD
|
||||
NS_CC_BEGIN;
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
#include "win32/CCThread_win32.cpp"
|
||||
#endif // CC_PLATFORM_WIN32
|
||||
CCThread::~CCThread()
|
||||
{
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
|
||||
#include "wophone/CCThread_wophone.cpp"
|
||||
#endif // CC_PLATFORM_WOPHONE
|
||||
}
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#include "android/CCThread_android.cpp"
|
||||
#endif // CC_PLATFORM_ANDROID
|
||||
void CCThread::createAutoreleasePool()
|
||||
{
|
||||
|
||||
#endif // CC_SUPPORT_MULTITHREAD
|
||||
}
|
||||
|
||||
NS_CC_END;
|
|
@ -26,41 +26,24 @@ THE SOFTWARE.
|
|||
#define __CC_PLATFORM_THREAD_H__
|
||||
|
||||
#include "CCCommon.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
#if CC_SUPPORT_MULTITHREAD
|
||||
/**
|
||||
@brief The object for mutual-exclusion synchronization.
|
||||
|
||||
@warning Don't enter a CCLock twice in the same thread.
|
||||
*/
|
||||
class CC_DLL CCLock
|
||||
/* On iOS, should create autorelease pool when create a new thread
|
||||
* and release it when the thread end.
|
||||
*/
|
||||
class CC_DLL CCThread
|
||||
{
|
||||
public:
|
||||
CCLock();
|
||||
~CCLock();
|
||||
CCThread() : m_pAutoreasePool(0) {}
|
||||
~CCThread();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
void createAutoreleasePool();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
CCLock::Impl * m_pImp;
|
||||
void *m_pAutoreasePool;
|
||||
};
|
||||
#else // CC_SUPPORT_MULTITHREAD
|
||||
|
||||
class CC_DLL CCLock
|
||||
{
|
||||
public:
|
||||
CCLock() {}
|
||||
~CCLock() {}
|
||||
|
||||
void lock() {}
|
||||
void unlock() {}
|
||||
};
|
||||
|
||||
#endif // CC_SUPPORT_MULTITHREAD
|
||||
|
||||
NS_CC_END;
|
||||
|
||||
|
|
|
@ -291,7 +291,16 @@ namespace cocos2d {
|
|||
pRet->m_sString += pszFilename;
|
||||
return pRet->m_sString.c_str();
|
||||
}
|
||||
|
||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
||||
{
|
||||
CCDictionary<std::string, CCObject*> *ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
||||
ret->autorelease();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
||||
{
|
||||
NSString* pPath = [NSString stringWithUTF8String:pFileName];
|
||||
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
|
||||
|
@ -301,9 +310,10 @@ namespace cocos2d {
|
|||
id value = [pDict objectForKey:key];
|
||||
static_addValueToCCDict(key, value, pRet);
|
||||
}
|
||||
pRet->autorelease();
|
||||
|
||||
return pRet;
|
||||
}
|
||||
|
||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||
{
|
||||
unsigned char * pBuffer = NULL;
|
||||
|
|
|
@ -1,70 +1 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#if CCX_SUPPORT_MULTITHREAD
|
||||
|
||||
#include "ccxThread.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
class CCXLock::Impl
|
||||
{
|
||||
public:
|
||||
Impl() { InitializeCriticalSection(&m_cs); }
|
||||
~Impl() { DeleteCriticalSection(&m_cs); }
|
||||
|
||||
CRITICAL_SECTION m_cs;
|
||||
};
|
||||
|
||||
CCXLock::CCXLock()
|
||||
: m_pImp(new CCXLock::Impl)
|
||||
{
|
||||
}
|
||||
|
||||
CCXLock::~CCXLock()
|
||||
{
|
||||
CC_SAFE_DELETE(m_pImp);
|
||||
}
|
||||
|
||||
void CCXLock::lock()
|
||||
{
|
||||
if (m_pImp)
|
||||
{
|
||||
EnterCriticalSection(&m_pImp->m_cs);
|
||||
}
|
||||
}
|
||||
|
||||
void CCXLock::unlock()
|
||||
{
|
||||
if (m_pImp)
|
||||
{
|
||||
LeaveCriticalSection(&m_pImp->m_cs);
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_END;
|
||||
|
||||
#endif // CCX_SUPPORT_MULTITHREAD
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
</PreBuildEvent>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\OGLES;..\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\pthread;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\pthread;..\platform\third_party\win32\OGLES;..\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
|
@ -74,7 +74,7 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$
|
|||
</Command>
|
||||
</PreLinkEvent>
|
||||
<Link>
|
||||
<AdditionalDependencies>libEGL.lib;libgles_cm.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libiconv.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>libEGL.lib;libgles_cm.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libiconv.lib;pthreadVCE2.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
|
@ -95,7 +95,7 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$
|
|||
</Command>
|
||||
</PreBuildEvent>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\OGLES;..\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\pthread;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\OGLES;..\include;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
|
@ -110,7 +110,7 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$
|
|||
</Command>
|
||||
</PreLinkEvent>
|
||||
<Link>
|
||||
<AdditionalDependencies>libEGL.lib;libgles_cm.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libiconv.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>libEGL.lib;libgles_cm.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libiconv.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
|
||||
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<IgnoreSpecificDefaultLibraries> ;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
|
||||
|
|
|
@ -39,6 +39,7 @@ THE SOFTWARE.
|
|||
#include "support/ccUtils.h"
|
||||
#include "CCScheduler.h"
|
||||
#include "pthread.h"
|
||||
#include "CCThread.h"
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
|
@ -59,6 +60,10 @@ static AsyncStruct *s_pAsyncObject;
|
|||
|
||||
static void* loadImage(void* data)
|
||||
{
|
||||
// create autorelease pool for iOS
|
||||
CCThread thread;
|
||||
thread.createAutoreleasePool();
|
||||
|
||||
if (! ((AsyncStruct*)data)->filename.c_str())
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -1 +1 @@
|
|||
3aab8d3693dcaba52bbe6cf1d88bd085701c71bb
|
||||
84d1a5cd21bd26c8e2f08241d504b59fe40defc9
|
|
@ -1 +1 @@
|
|||
2905515c8c42c8a1603230ed28549aa28e4ae3f1
|
||||
36888561783556c80b0635d13bbdcc7e285fa0f3
|
|
@ -1 +1 @@
|
|||
b59f29f9bd284c46876e7ecc47b74bfaf8a00aa6
|
||||
866c5fd880bbb121951818d47d13a4ee914279ad
|
|
@ -1 +1 @@
|
|||
60da72586f63e425b1e85a7a0cee1d798e59c843
|
||||
6b542917dfd2180ff6c55bca6cd7b30c64c4a300
|
|
@ -1 +1 @@
|
|||
3df87510e48dfe7e5c768dcef3f4fd6eb99a129b
|
||||
0031a29bb750c1b41620d51dbb052daa823edcd4
|
|
@ -124,6 +124,7 @@
|
|||
<ClCompile Include="..\tests\DirectorTest\DirectorTest.cpp" />
|
||||
<ClCompile Include="..\tests\FontTest\FontTest.cpp" />
|
||||
<ClCompile Include="..\tests\Texture2dTest\Texture2dTest.cpp" />
|
||||
<ClCompile Include="..\tests\TextureCacheTest\TextureCacheTest.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="..\AppDelegate.cpp" />
|
||||
<ClCompile Include="..\tests\controller.cpp" />
|
||||
|
@ -210,6 +211,7 @@
|
|||
<ClInclude Include="..\tests\DirectorTest\DirectorTest.h" />
|
||||
<ClInclude Include="..\tests\FontTest\FontTest.h" />
|
||||
<ClInclude Include="..\tests\Texture2dTest\Texture2dTest.h" />
|
||||
<ClInclude Include="..\tests\TextureCacheTest\TextureCacheTest.h" />
|
||||
<ClInclude Include="main.h" />
|
||||
<ClInclude Include="..\AppDelegate.h" />
|
||||
<ClInclude Include="..\tests\controller.h" />
|
||||
|
|
|
@ -136,6 +136,9 @@
|
|||
<Filter Include="classes\tests\CurrentLanguageTest">
|
||||
<UniqueIdentifier>{178ed769-203d-47d0-92a4-de8668c4df58}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="classes\tests\TextureCacheTest">
|
||||
<UniqueIdentifier>{17b9b23c-1ef6-466e-a2ab-c558f4015698}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
|
@ -390,6 +393,9 @@
|
|||
<ClCompile Include="..\tests\CurrentLanguageTest\CurrentLanguageTest.cpp">
|
||||
<Filter>classes\tests\CurrentLanguageTest</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\tests\TextureCacheTest\TextureCacheTest.cpp">
|
||||
<Filter>classes\tests\TextureCacheTest</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="main.h">
|
||||
|
@ -704,5 +710,8 @@
|
|||
<ClInclude Include="..\tests\CurrentLanguageTest\CurrentLanguageTest.h">
|
||||
<Filter>classes\tests\CurrentLanguageTest</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\tests\TextureCacheTest\TextureCacheTest.h">
|
||||
<Filter>classes\tests\TextureCacheTest</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue