int JackAndroidThread::AcquireRealTimeImp(jack_native_thread_t thread, int priority)
{
    struct sched_param rtparam;
    int res;
    memset(&rtparam, 0, sizeof(rtparam));
    rtparam.sched_priority = priority;

    jack_log("JackAndroidThread::AcquireRealTimeImp priority = %d", priority);

#ifndef JACK_ANDROID_REALTIME_SCHED
    if ((res = pthread_setschedparam(thread, JACK_SCHED_POLICY, &rtparam)) != 0) {
        jack_error("Cannot use real-time scheduling (RR/%d)"
                   "(%d: %s)", rtparam.sched_priority, res,
                   strerror(res));
        return -1;
    }
#else
    pthread_internal_t* thread_;
    thread_ = reinterpret_cast<pthread_internal_t*>(thread);

//    if ((res = android::requestPriority(getpid(), thread_->tid, priority)) != 0) {
//        jack_log("Failed to get SCHED_FIFO priority pid %d tid %d; error %d",
//		    getpid(), thread_->tid, res);
//        return -1;
//    }
	RequestPriority(getpid(), thread_->tid, priority);
#endif
    return 0;
}
		int AIScriptRelay::cpp_flee(lua_State *lua)
		{
			Vec2d pos;
			RequestPriority priority = PriorityNormal;
			int n = lua_gettop(lua);

			if (n >= 2)
			{
				pos.x = mCurrentScript->getArgFloat(1);
				pos.y = mCurrentScript->getArgFloat(2);
			}
			else
				return 0;

			if (n == 3)
				priority = RequestPriority(mCurrentScript->getArgInteger(3));

			mCurrentScript->mSteeringBehaviors->flee(pos, priority);

			return 0;
		}
		int AIScriptRelay::cpp_pursuit(lua_State *lua)
		{
			int id;
			RequestPriority priority = PriorityNormal;
			int n = lua_gettop(lua);

			if (n >= 1)
				id = mCurrentScript->getArgInteger(1);
			else
				return 0;

			if (n == 2)
				priority = RequestPriority(mCurrentScript->getArgInteger(2));

			AI *ai = mCurrentScript->getRecentAiReference(id);

			if (ai)
				mCurrentScript->mSteeringBehaviors->pursuit(ai, priority);

			return 0;
		}
		int AIScriptRelay::cpp_wander(lua_State *lua)
		{
			mCurrentScript->mSteeringBehaviors->wander(RequestPriority(mCurrentScript->getArgInteger(1)));
			return 0;
		}