Ejemplo n.º 1
0
static int ll_send (lutok::state& state) {
	LuaSDL::LuaThread *p;
	if (state.is_string(1)){
		std::string & channel = state.to_string(1);
		SDL_mutexP(kernel_access);
		p = searchmatch(channel.c_str(), &waitreceive);
		if (p) { /* found a matching receiver? */
			movevalues(&state, p->state); /* move values to receiver */
			p->channel = NULL; /* mark receiver as not waiting */
			SDL_CondSignal(p->cond); /* wake it up */
		}
		else
			waitonlist(state, channel.c_str(), &waitsend);
		SDL_mutexV(kernel_access);
	}
	return 0;
}
static int ll_send(lua_State *L) {
  Proc *p;
  const char *channel = luaL_checkstring(L, 1);

  pthread_mutex_lock(&kernel_access);

  p = searchmatch(channel, &waitreceive);
  if (p) {
    movevalues(L, p->L);
    p->channel = NULL;
    pthread_cond_signal(&p->cond);
  } else
    waitonlist(L, channel, &waitsend);

  pthread_mutex_unlock(&kernel_access);
  return 0;
}
Ejemplo n.º 3
0
static int ll_receive (lutok::state& state) {
	LuaSDL::LuaThread *p;
	if (state.is_string(1)){
		std::string & channel = state.to_string(1);
		state.set_top(1);
		SDL_mutexP(kernel_access);
		p = searchmatch(channel.c_str(), &waitsend);
		if (p) { /* found a matching sender? */
			movevalues(p->state, &state); /* get values from sender */
			p->channel = NULL; /* mark sender as not waiting */
			SDL_CondSignal(p->cond); /* wake it up */
		}
		else
			waitonlist(state, channel.c_str(), &waitreceive);
		SDL_mutexV(kernel_access);
		/* return all stack values but channel */
		return state.get_top() - 1;
	}else{
		return 0;
	}
}