Пример #1
0
void Thread::CreateDaemon(string name) {
#ifdef WIN32_
    new (&mutex) std::mutex();
#endif
#ifdef POSIX_
    new (&this->mutex) std::mutex();
#endif
    this->name.init();
    this->name = name;
    this->id = Thread::tid++;
    this->dataStack = NULL;
    this->callStack = NULL;
    this->currentThread.object=NULL;
    this->args.object=NULL;
    this->calls=0;
    this->starting=0;
    this->priority=THREAD_PRIORITY_NORM;
    this->current = NULL;
    this->suspendPending = false;
    this->exceptionThrown = false;
    this->suspended = false;
    this->exited = false;
    this->daemon = true;
    this->terminated = false;
    this->throwable.init();
    this->state = THREAD_CREATED;
    this->exitVal = 0;
    this->stack_lmt=0;
    this->fp=0;
    this->sp=NULL;
    this->main=NULL;

    pushThread(this);
}
Пример #2
0
void LuaInterface::setGlobalEnvironment(int env)
{
    pushThread();
    getRef(env);
    assert(isTable());
    setEnv();
    pop();
}
int main()
{
  std::thread pushThread(push);
  std::thread popThread(pop);

  if(pushThread.joinable())
    pushThread.join();

  if(popThread.joinable())
    popThread.join();

  return 0;
}
Пример #4
0
/**
 * API level thread create called from Sharp
 *
 * @param methodAddress
 * @param stack_size
 * @return
 */
int32_t Thread::Create(int32_t methodAddress, unsigned long stack_size) {
    if(methodAddress < 0 || methodAddress >= manifest.methods)
        return -1;
    Method* method = &env->methods[methodAddress];
    if(method->paramSize>0)
        return -2;
    if(stack_size <= method->paramSize)
        return -3;

    Thread* thread = (Thread*)malloc(
            sizeof(Thread)*1);

#ifdef WIN32_
    new (&thread->mutex) std::mutex();
#endif
#ifdef POSIX_
    new (&thread->mutex) std::mutex();
#endif
    thread->name.init();
    thread->main = method;
    thread->id = Thread::tid++;
    thread->dataStack = NULL;
    thread->callStack = NULL;
    thread->currentThread.object=NULL;
    thread->args.object=NULL;
    thread->calls=0;
    thread->starting=0;
    thread->current = NULL;
    thread->priority=THREAD_PRIORITY_NORM;
    thread->suspendPending = false;
    thread->exceptionThrown = false;
    thread->suspended = false;
    thread->throwable.init();
    thread->exited = false;
    thread->daemon = false;
    thread->terminated = false;
    thread->state = THREAD_CREATED;
    thread->exitVal = 0;
    thread->stack_lmt = stack_size;
    thread->fp=0;
    thread->sp=NULL;

    pushThread(thread);

    stringstream ss;
    ss << "Thread@" << thread->id;
    thread->name = ss.str();
    return thread->id;
}
Пример #5
0
/**
 * this is an escalonator, operator() para o asio
 */
void JavaVM::execThreads() //Each thread needs to have his stack
{
	StackFrame * currentThread = NULL;
	while(true) //TODO while this program is alive, for asio remove it
	{
		currentThread = popThread();
		if(currentThread == NULL)
			continue; //need to be async, e criar isso sendo algo para o boost::asio

		if (execThread(currentThread, 2000))
		{
			pushThread(currentThread);
		}
		else
		{
			//this thread's done
		}
	}
}
Пример #6
0
void Thread::Create(string name) {
#ifdef WIN32_
    new (&mutex) std::mutex();
#endif
#ifdef POSIX_
    new (&this->mutex) std::mutex();
#endif
    this->name.init();
    this->currentThread.object=NULL;
    this->args.object=NULL;
    this->name = name;
    this->starting = 0;
    this->id = Thread::tid++;
    this->dataStack = (StackElement*)__malloc(sizeof(StackElement)*STACK_SIZE);
    this->suspendPending = false;
    this->exceptionThrown = false;
    this->suspended = false;
    this->exited = false;
    this->priority=THREAD_PRIORITY_HIGH;
    this->throwable.init();
    this->daemon = false;
    this->terminated = false;
    this->state = THREAD_CREATED;
    this->exitVal = 0;
    this->stack_lmt = STACK_SIZE;
    this->callStack = NULL;
    this->calls=0;
    this->fp=0;
    this->sp=dataStack-1;

    for(unsigned long i = 0; i < STACK_SIZE; i++) {
        this->dataStack[i].object.object = NULL;
        this->dataStack[i].var=0;
    }

    pushThread(this);
}
Пример #7
0
void LuaInterface::init()
{
    createLuaState();

    // store global environment reference
    pushThread();
    getEnv();
    m_globalEnv = ref();
    pop();

    // check if demangle_class is working as expected
    assert(stdext::demangle_class<LuaObject>() == "LuaObject");

    // register LuaObject, the base of all other objects
    registerClass<LuaObject>();
    bindClassMemberFunction<LuaObject>("getUseCount", &LuaObject::getUseCount);
    bindClassMemberFunction<LuaObject>("getClassName", &LuaObject::getClassName);

    registerClassMemberFunction<LuaObject>("getFieldsTable", (LuaCppFunction) ([](LuaInterface* lua) -> int {
        LuaObjectPtr obj = g_lua.popObject();
        obj->luaGetFieldsTable();
        return 1;
    }));
}
Пример #8
0
void LuaInterface::setGlobalEnvironment()
{
    pushThread();
    insert(-2);
    setEnv();
}
Пример #9
0
void LuaInterface::getGlobalEnvironment()
{
    pushThread();
    getEnv();
    remove(-2);
}