aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/libjin/libjin.vcxproj1
-rw-r--r--build/libjin/libjin.vcxproj.filters6
-rw-r--r--libjin/Thread/Thread.cpp23
-rw-r--r--libjin/Thread/Thread.h4
-rw-r--r--libjin/Utils/Proxy/lock.h4
-rw-r--r--test/03Thread/threadtest.cpp3
6 files changed, 37 insertions, 4 deletions
diff --git a/build/libjin/libjin.vcxproj b/build/libjin/libjin.vcxproj
index 4f90bf7..d2f70d0 100644
--- a/build/libjin/libjin.vcxproj
+++ b/build/libjin/libjin.vcxproj
@@ -121,6 +121,7 @@
<ClInclude Include="..\..\libjin\Utils\Json\Json.h" />
<ClInclude Include="..\..\libjin\Utils\Log.h" />
<ClInclude Include="..\..\libjin\Utils\macros.h" />
+ <ClInclude Include="..\..\libjin\Utils\Proxy\lock.h" />
<ClInclude Include="..\..\libjin\Utils\utils.h" />
<ClInclude Include="..\..\libjin\Utils\XML\XML.h" />
</ItemGroup>
diff --git a/build/libjin/libjin.vcxproj.filters b/build/libjin/libjin.vcxproj.filters
index 7115265..261d25d 100644
--- a/build/libjin/libjin.vcxproj.filters
+++ b/build/libjin/libjin.vcxproj.filters
@@ -100,6 +100,9 @@
<Filter Include="3rdparty\Box2D\Common">
<UniqueIdentifier>{5de638b5-bb1a-4b71-aaee-1ca813ce3a95}</UniqueIdentifier>
</Filter>
+ <Filter Include="Utils\Proxy">
+ <UniqueIdentifier>{84e2ae2f-5cec-4904-9611-330a0362a288}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\libjin\3rdparty\GLee\GLee.c">
@@ -406,6 +409,9 @@
<ClInclude Include="..\..\libjin\Utils\XML\XML.h">
<Filter>Utils\XML</Filter>
</ClInclude>
+ <ClInclude Include="..\..\libjin\Utils\Proxy\lock.h">
+ <Filter>Utils\Proxy</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\libjin\README.md" />
diff --git a/libjin/Thread/Thread.cpp b/libjin/Thread/Thread.cpp
index ae6498d..81db72c 100644
--- a/libjin/Thread/Thread.cpp
+++ b/libjin/Thread/Thread.cpp
@@ -144,17 +144,20 @@ namespace thread
void Thread::ThreadData::set(std::string name, Value value)
{
+ Lock l(mutex);
//if (share.count(name) != 0);
share[name] = value;
}
Thread::Value Thread::ThreadData::get(std::string name)
{
+ Lock l(mutex);
return share[name];
}
bool Thread::ThreadData::exist(const std::string& name)
{
+ Lock l(mutex);
return share.count(name) == 1;
}
@@ -169,6 +172,14 @@ namespace thread
//////////////////////////////////////////////////////////////////////
+ int Thread::ThreadFunciton(void* p)
+ {
+ Thread* thread = (Thread*)p;
+ if (thread->threadRunner != nullptr)
+ thread->threadRunner(thread);
+ return 0;
+ }
+
Thread::Thread(const std::string tname, ThreadRunner runner)
: name(tname)
, running(false)
@@ -209,7 +220,7 @@ namespace thread
#endif
}
#if JIN_THREAD_SDL
- handle = SDL_CreateThread(threadRunner, name.c_str(), this);
+ handle = SDL_CreateThread(ThreadFunciton, name.c_str(), this);
#elif JIN_THREAD_CPP
handle = new std::thread();
#endif
@@ -264,6 +275,16 @@ namespace thread
Thread::Value Thread::demand(std::string name)
{
+ /**
+ * pthread_mutex_lock(mtx);
+ * while(pass == 0)
+ * {
+ * pthread_mutex_unlock(mtx);
+ * pthread_cond_just_wait(cv);
+ * pthread_mutex_lock(mtx);
+ * }
+ * pthread_mutex_unlock(mtx);
+ */
lock();
while (!common->exist(name))
{
diff --git a/libjin/Thread/Thread.h b/libjin/Thread/Thread.h
index 5b849cf..b2087eb 100644
--- a/libjin/Thread/Thread.h
+++ b/libjin/Thread/Thread.h
@@ -74,7 +74,7 @@ namespace thread
};
public:
- typedef int(ThreadRunner)(void* /*ThreadData*/);
+ typedef int(ThreadRunner)(Thread* thread);
Thread(const std::string name, ThreadRunner threadfuncs);
~Thread();
bool start();
@@ -103,6 +103,8 @@ namespace thread
std::string name; // thread name
bool running; // running
+ static int ThreadFunciton(void* p);
+
};
} // thread
diff --git a/libjin/Utils/Proxy/lock.h b/libjin/Utils/Proxy/lock.h
new file mode 100644
index 0000000..29194a1
--- /dev/null
+++ b/libjin/Utils/Proxy/lock.h
@@ -0,0 +1,4 @@
+class Lock
+{
+
+}; \ No newline at end of file
diff --git a/test/03Thread/threadtest.cpp b/test/03Thread/threadtest.cpp
index 5d03893..08eb69d 100644
--- a/test/03Thread/threadtest.cpp
+++ b/test/03Thread/threadtest.cpp
@@ -29,9 +29,8 @@ void onDraw()
}
-int thread2Runner(void* p)
+int thread2Runner(Thread* t)
{
- Thread* t = (Thread*)p;
int i = 0;
while (true)
{