mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Merge in channels from love-experiments
Rewritten love.thread and changed communication method from weird system before, to channels. --HG-- branch : minor
This commit is contained in:
@@ -70,7 +70,6 @@ private:
|
||||
// The reference count.
|
||||
int count;
|
||||
}; // Object
|
||||
|
||||
} // love
|
||||
|
||||
#endif // LOVE_OBJECT_H
|
||||
|
||||
+1
-11
@@ -19,24 +19,14 @@
|
||||
**/
|
||||
|
||||
#include "delay.h"
|
||||
#include <SDL.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
|
||||
void delay(unsigned int ms)
|
||||
{
|
||||
#if LOVE_THREADS == LOVE_THREADS_POSIX
|
||||
struct timespec ts1, ts2;
|
||||
|
||||
ts1.tv_sec = ms / 1000;
|
||||
ts1.tv_nsec = (ms % 1000) * 1000000;
|
||||
// FIXME: handle signals
|
||||
nanosleep(&ts1, &ts2);
|
||||
#elif LOVE_THREADS == LOVE_THREADS_WIN32
|
||||
Sleep(ms);
|
||||
#elif LOVE_THREADS == LOVE_THREADS_SDL
|
||||
SDL_Delay(ms);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // love
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#ifndef DELAY_H_
|
||||
#define DELAY_H_
|
||||
|
||||
#include <thread/threads.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
|
||||
|
||||
+10
-4
@@ -25,7 +25,7 @@
|
||||
#include "Object.h"
|
||||
#include "Reference.h"
|
||||
#include "StringMap.h"
|
||||
#include "thread/threads.h"
|
||||
#include <thread/threads.h>
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
@@ -35,7 +35,6 @@ namespace love
|
||||
|
||||
static thread::Mutex *gcmutex = 0;
|
||||
void *_gcmutex = 0;
|
||||
unsigned int _gcthread = 0;
|
||||
/**
|
||||
* Called when an object is collected. The object is released
|
||||
* once in this function, possibly deleting it.
|
||||
@@ -44,7 +43,7 @@ static int w__gc(lua_State *L)
|
||||
{
|
||||
if (!gcmutex)
|
||||
{
|
||||
gcmutex = new thread::Mutex();
|
||||
gcmutex = thread::newMutex();
|
||||
_gcmutex = (void *) gcmutex;
|
||||
}
|
||||
Proxy *p = (Proxy *)lua_touserdata(L, 1);
|
||||
@@ -52,7 +51,6 @@ static int w__gc(lua_State *L)
|
||||
if (p->own)
|
||||
{
|
||||
thread::Lock lock(gcmutex);
|
||||
_gcthread = thread::ThreadBase::threadId();
|
||||
t->release();
|
||||
}
|
||||
return 0;
|
||||
@@ -118,6 +116,13 @@ bool luax_optboolean(lua_State *L, int idx, bool b)
|
||||
return b;
|
||||
}
|
||||
|
||||
std::string luax_tostring(lua_State *L, int idx)
|
||||
{
|
||||
size_t len;
|
||||
const char *str = lua_tolstring(L, idx, &len);
|
||||
return std::string(str, len);
|
||||
}
|
||||
|
||||
std::string luax_checkstring(lua_State *L, int idx)
|
||||
{
|
||||
size_t len;
|
||||
@@ -462,6 +467,7 @@ StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[] =
|
||||
|
||||
// Thread
|
||||
{"Thread", THREAD_THREAD_ID},
|
||||
{"Channel", THREAD_CHANNEL_ID},
|
||||
|
||||
// The modules themselves. Only add abstracted modules here.
|
||||
{"filesystem", MODULE_FILESYSTEM_ID},
|
||||
|
||||
@@ -132,6 +132,15 @@ void luax_pushboolean(lua_State *L, bool b);
|
||||
**/
|
||||
bool luax_optboolean(lua_State *L, int idx, bool b);
|
||||
|
||||
/**
|
||||
* Converts the value at idx to a std::string. It takes care of the string
|
||||
* size and possible embedded nulls.
|
||||
* @param L The Lua state.
|
||||
* @param idx The index on the Lua stack.
|
||||
* @return Copy of the string at the specified index.
|
||||
**/
|
||||
std::string luax_tostring(lua_State *L, int idx);
|
||||
|
||||
/**
|
||||
* Converts the value at idx to a std::string. It takes care of the string
|
||||
* size and possible embedded nulls.
|
||||
|
||||
@@ -89,6 +89,7 @@ enum Type
|
||||
|
||||
// Thread
|
||||
THREAD_THREAD_ID,
|
||||
THREAD_CHANNEL_ID,
|
||||
|
||||
// The modules themselves. Only add abstracted modules here.
|
||||
MODULE_FILESYSTEM_ID,
|
||||
@@ -160,6 +161,7 @@ const bits PHYSICS_WHEEL_JOINT_T = (bits(1) << PHYSICS_WHEEL_JOINT_ID) | PHYSICS
|
||||
|
||||
// Thread.
|
||||
const bits THREAD_THREAD_T = (bits(1) << THREAD_THREAD_ID) | OBJECT_T;
|
||||
const bits THREAD_CHANNEL_T = (bits(1) << THREAD_CHANNEL_ID) | OBJECT_T;
|
||||
|
||||
// Modules.
|
||||
const bits MODULE_FILESYSTEM_T = (bits(1) << MODULE_FILESYSTEM_ID) | MODULE_T;
|
||||
|
||||
Reference in New Issue
Block a user