Beispiel #1
0
    void do_work (CompletionCounter)
    {
        if (m_called_stop.load () == 1)
            return;

        // We don't have any work to do at this time
        if (m_work.empty())
        {
            m_idle = true;
            m_journal.trace << "Sleeping";
            return;
        }

        if (m_work.front().names.empty())
            m_work.pop_front();

        std::string const name (m_work.front().names.back());
        HandlerType handler (m_work.front().handler);

        m_work.front().names.pop_back();

        HostAndPort const hp (parseName(name));

        if (hp.first.empty())
        {
            m_journal.error <<
                "Unable to parse '" << name << "'";

            m_io_service.post (m_strand.wrap (boost::bind (
                &NameResolverImpl::do_work, this,
                CompletionCounter(this))));

            return;
        }

        boost::asio::ip::tcp::resolver::query query (
            hp.first, hp.second);

        m_resolver.async_resolve (query, boost::bind (
            &NameResolverImpl::do_finish, this, name,
            boost::asio::placeholders::error, handler,
            boost::asio::placeholders::iterator,
            CompletionCounter(this)));
    }
Beispiel #2
0
 void operator()(clmdep_msgpack::object::with_zone& o, const std::deque<T, Alloc>& v) const {
     o.type = clmdep_msgpack::type::ARRAY;
     if(v.empty()) {
         o.via.array.ptr = MSGPACK_NULLPTR;
         o.via.array.size = 0;
     } else {
         uint32_t size = checked_get_container_size(v.size());
         clmdep_msgpack::object* p = static_cast<clmdep_msgpack::object*>(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size, MSGPACK_ZONE_ALIGNOF(clmdep_msgpack::object)));
         clmdep_msgpack::object* const pend = p + size;
         o.via.array.ptr = p;
         o.via.array.size = size;
         typename std::deque<T, Alloc>::const_iterator it(v.begin());
         do {
             *p = clmdep_msgpack::object(*it, o.zone);
             ++p;
             ++it;
         } while(p < pend);
     }
 }
Beispiel #3
0
 void operator()(msgpack::object::with_zone& o, const std::deque<T>& v) const {
     o.type = msgpack::type::ARRAY;
     if(v.empty()) {
         o.via.array.ptr = nullptr;
         o.via.array.size = 0;
     } else {
         uint32_t size = checked_get_container_size(v.size());
         msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
         msgpack::object* const pend = p + size;
         o.via.array.ptr = p;
         o.via.array.size = size;
         typename std::deque<T>::const_iterator it(v.begin());
         do {
             *p = msgpack::object(*it, o.zone);
             ++p;
             ++it;
         } while(p < pend);
     }
 }
Beispiel #4
0
std::deque<tgt::ivec2> Flow2D::flowPosToSlicePos(std::deque<tgt::vec2>& fps,
        const tgt::ivec2& sliceSize, const tgt::ivec2& offset) const
{
    std::deque<tgt::ivec2> sps;    // slice positions
    while (fps.empty() == false) {
        std::deque<tgt::vec2>::iterator it = fps.begin();

        // no call to overloaded flowPosToViewportPos() for performance
        //
        tgt::vec2 aux(*it / static_cast<tgt::vec2>(dimensions_));
        tgt::ivec2 sp(
            (static_cast<int>(tgt::round(aux.x * sliceSize.x)) + offset.x) % sliceSize.x,
            (static_cast<int>(tgt::round(aux.y * sliceSize.y)) + offset.y) % sliceSize.y);

        sps.push_back(sp);
        fps.erase(it);
    }
    return sps;
}
void InstallProviderSpecXml::add(
	const SmartPtrCInstallProviderSpecDoc installProviderSpecDoc,
	const SmartPtrCXmlElement thisXml) {
	CAF_CM_STATIC_FUNC_VALIDATE("InstallProviderSpecXml", "add");

	CAF_CM_ENTER {
		CAF_CM_VALIDATE_SMARTPTR(installProviderSpecDoc);
		CAF_CM_VALIDATE_SMARTPTR(thisXml);

		const std::string clientIdVal =
			BasePlatform::UuidToString(installProviderSpecDoc->getClientId());
		CAF_CM_VALIDATE_STRING(clientIdVal);
		thisXml->addAttribute("clientId", clientIdVal);

		const std::string providerNamespaceVal = installProviderSpecDoc->getProviderNamespace();
		CAF_CM_VALIDATE_STRING(providerNamespaceVal);
		thisXml->addAttribute("providerNamespace", providerNamespaceVal);

		const std::string providerNameVal = installProviderSpecDoc->getProviderName();
		CAF_CM_VALIDATE_STRING(providerNameVal);
		thisXml->addAttribute("providerName", providerNameVal);

		const std::string providerVersionVal = installProviderSpecDoc->getProviderVersion();
		CAF_CM_VALIDATE_STRING(providerVersionVal);
		thisXml->addAttribute("providerVersion", providerVersionVal);

		const std::deque<SmartPtrCMinPackageElemDoc> packageValVal =
			installProviderSpecDoc->getPackageCollection();
		CAF_CM_VALIDATE_STL(packageValVal);

		if (! packageValVal.empty()) {
			for (TConstIterator<std::deque<SmartPtrCMinPackageElemDoc> > packageValIter(packageValVal);
				packageValIter; packageValIter++) {
				const SmartPtrCXmlElement packageValXml =
					thisXml->createAndAddElement("package");
				MinPackageElemXml::add(*packageValIter, packageValXml);
			}
		}

		thisXml->addAttribute("version", "1.0");
	}
	CAF_CM_EXIT;
}
Beispiel #6
0
	void ProcessFrames()
	{
		while (!m_Frames.empty())
		{
			SFrame& frame = m_Frames.front();

			// Queries become available in order so we only need to check the last one
			GLint available = 0;
			pglGetQueryObjectivARB(frame.events.back().query, GL_QUERY_RESULT_AVAILABLE, &available);
			ogl_WarnIfError();
			if (!available)
				break;

			// The frame's queries are now available, so retrieve and record all their results:

			for (size_t i = 0; i < frame.events.size(); ++i)
			{
				GLuint64 queryTimestamp = 0;
				pglGetQueryObjectui64v(frame.events[i].query, GL_QUERY_RESULT, &queryTimestamp);
					// (use the non-suffixed function here, as defined by GL_ARB_timer_query)
				ogl_WarnIfError();

				// Convert to absolute CPU-clock time
				double t = frame.syncTimeStart + (double)(queryTimestamp - frame.syncTimestampStart) / 1e9;

				// Record a frame-start for syncing
				if (i == 0)
					m_Storage.RecordFrameStart(t);

				if (frame.events[i].isEnter)
					m_Storage.Record(CProfiler2::ITEM_ENTER, t, frame.events[i].id);
				else
					m_Storage.Record(CProfiler2::ITEM_LEAVE, t, frame.events[i].id);

				// Associate the frame number with the "frame" region
				if (i == 0)
					m_Storage.RecordAttributePrintf("%u", frame.num);
			}

			PopFrontFrame();
		}
	}
Beispiel #7
0
bool has_focus(const sdl_handler* hand, const SDL_Event* event)
{
	if(event_contexts.empty()) {
		return true;
	}

	if(hand->requires_event_focus(event) == false) {
		return true;
	}

	const handler_list::iterator foc = event_contexts.back().focused_handler;
	auto& handlers = event_contexts.back().handlers;

	// If no-one has focus at the moment, this handler obviously wants
	// focus, so give it to it.
	if(foc == handlers.end()) {
		focus_handler(hand);
		return true;
	}

	sdl_handler* const foc_hand = *foc;
	if(foc_hand == hand){
		return true;
	} else if(!foc_hand->requires_event_focus(event)) {
		// If the currently focused handler doesn't need focus for this event
		// allow the most recent interested handler to take care of it
		for(auto i = handlers.rbegin(); i != handlers.rend(); ++i) {
			sdl_handler* const thief_hand = *i;

			if(thief_hand != foc_hand && thief_hand->requires_event_focus(event)) {
				// Steal focus
				focus_handler(thief_hand);

				// Position the previously focused handler to allow stealing back
				handlers.splice(handlers.end(), handlers, foc);

				return thief_hand == hand;
			}
		}
	}
	return false;
}
Beispiel #8
0
/**	sorts a priority list by filter*/
void priority_sort(std::string filter){
	if(priority.size() == 1){
		ready.push(priority.front());
		priority.pop_front();
	}
	else{
		//if priority is bigger than 1, then need to sort
		int s = priority.size();
		struct Qu t[s];
		int i = 0;
		while(!priority.empty()){
			t[i] = priority.front();
			++i;
			priority.pop_front();
		}
		//sort in array, then add back to prioroity
		int j;
		for(j=0; j<s; ++j){
			int k;
			for(k=1; k<s; ++k){
				if(filter.compare("priority") == 0){
					if(t[j].priority>t[k].priority && j<k){
						struct Qu u = t[j];
						t[j] = t[k];
						t[k] = u;
					} }
				else if(filter.compare("sjf") == 0){
					if(t[j].cpu_burst>t[k].cpu_burst && j<k){
						struct Qu u = t[j];
						t[j] = t[k];
						t[k] = u;
					}
					else if(t[j].cpu_burst==t[k].cpu_burst && j<k){
						if(t[j].arrival_time > t[k].arrival_time){
							struct Qu u = t[j];
							t[j] = t[k];
							t[k] = u;
						} } }
				} }
		for(j=0; j<s; ++j) ready.push(t[j]);
	}
}
Beispiel #9
0
    // coalesce recent like messages
    bool coalesce_messages(std::string const &msg, game_message_type const type) {
        if (messages.empty()) {
            return false;
        }

        auto &last_msg = messages.back();
        if (last_msg.turn() + 3 < calendar::turn.get_turn()) {
            return false;
        }

        if (type != last_msg.type || msg != last_msg.message) {
            return false;
        }

        last_msg.count++;
        last_msg.time = calendar::turn;
        last_msg.type = type;

        return true;
    }
	const MutationCandidate<value_t> & getMutationCandidate() {
		if(mutationCandidates.empty()) {
			throw std::logic_error("No mutation candidates available.");
		}
		uint32_t & mutationCount = mutationCandidates.front().mutationCount;
		++mutationCount;

		// Find the first element with a value not less the new mutationCount
		auto firstElem = std::lower_bound(mutationCandidates.begin(),
										  mutationCandidates.end(),
										  mutationCount,
										  mutationCountLess);
		if(firstElem == mutationCandidates.begin()) {
			// If the only entry is the first one itself, nothing has to be done
			return mutationCandidates.front();
		}
		auto swapPosition = std::prev(firstElem);
		std::iter_swap(swapPosition, mutationCandidates.begin());
		return *swapPosition;
	}
Beispiel #11
0
	void FrameStart()
	{
		ProcessFrames();

		SFrame frame;
		frame.num = m_Profiler.GetFrameNumber();

		// On (at least) some NVIDIA Windows drivers, when GPU-bound, or when
		// vsync enabled and not CPU-bound, the first glGet* call at the start
		// of a frame appears to trigger a wait (to stop the GPU getting too
		// far behind, or to wait for the vsync period).
		// That will be this GL_TIMESTAMP get, which potentially distorts the
		// reported results. So we'll only do it fairly rarely, and for most
		// frames we'll just assume the clocks don't drift much
		
		const double RESYNC_PERIOD = 1.0; // seconds

		double now = m_Profiler.GetTime();

		if (m_Frames.empty() || now > m_Frames.back().syncTimeStart + RESYNC_PERIOD)
		{
			PROFILE2("profile timestamp resync");

			pglGetInteger64v(GL_TIMESTAMP, &frame.syncTimestampStart);
			ogl_WarnIfError();

			frame.syncTimeStart = m_Profiler.GetTime();
			// (Have to do GetTime again after GL_TIMESTAMP, because GL_TIMESTAMP
			// might wait a while before returning its now-current timestamp)
		}
		else
		{
			// Reuse the previous frame's sync data
			frame.syncTimeStart = m_Frames[m_Frames.size()-1].syncTimeStart;
			frame.syncTimestampStart = m_Frames[m_Frames.size()-1].syncTimestampStart;
		}

		m_Frames.push_back(frame);

		RegionEnter("frame");
	}
Beispiel #12
0
void gl_draw_scene() {
  int i;

  while (!pointclouds.empty()) {
    nsick_pointcloud pointcloud = pointclouds.front();
    pointclouds.pop_front();

    GLuint list_index = glGenLists(1);
    glNewList(list_index, GL_COMPILE);
    glBegin(GL_POINTS);
    for (int i = 0; i < pointcloud.num_points; ++i)
      glVertex3f(pointcloud.x[i], pointcloud.y[i], pointcloud.z[i]);
    glEnd();
    glEndList();

    lists.push_back(list_index);
    nsick_pointcloud_free(&pointcloud);

    if (lists.size() > MAX_POINTCLOUDS) {
      glDeleteLists(lists.front(), 1);
      lists.pop_front();
    }
  }

  for (std::deque<GLuint>::const_iterator it = lists.begin();
      it != lists.end(); ++it) {
    std::deque<GLuint>::const_iterator jt = it;
    ++jt;

    if (jt == lists.end()) {
      glPointSize(2.0);
      glColor3f(1, 0, 0);
    }
    else {
      glPointSize(1.0);
      glColor3f(0, 0, 0);
    }
    
    glCallList(*it);
  }
}
Beispiel #13
0
	void RegionEnter(const char* id)
	{
		ENSURE(!m_Frames.empty());
		SFrame& frame = m_Frames.back();

		SEvent event;
		event.id = id;
		event.isEnter = true;

		for (size_t i = 0; i < m_QueryTypes.size(); ++i)
		{
			GLuint id = NewQuery(i);
			pglBeginPerfQueryINTEL(id);
			ogl_WarnIfError();
			event.queries.push_back(id);
		}

		frame.activeRegions.push_back(frame.events.size());

		frame.events.push_back(event);
	}
Beispiel #14
0
// Worker Thread
void consumer ()
{
    packaged_task< _llu() > t;
    thread::id this_id = this_thread::get_id();
    while (1) {
	// Critical section
        {
            std::unique_lock<std::mutex> locker(mu);
	    // Lambda function is called for spurious wakeups
	    // 1. Unlock mutex
	    // 2. Suspend
	    // 3. Wakeup on notify and acquire mutex
            cond.wait(locker, []() {return !task_q.empty();});
            cout << "TID " << this_id << endl << flush;
            t = std::move(task_q.front());
            task_q.pop_front();
            locker.unlock();
        }
        t();
    }
}
Beispiel #15
0
	void RegionLeave(const char* id)
	{
		ENSURE(!m_Frames.empty());
		SFrame& frame = m_Frames.back();

		ENSURE(!frame.activeRegions.empty());
		SEvent& activeEvent = frame.events[frame.activeRegions.back()];

		for (size_t i = 0; i < m_QueryTypes.size(); ++i)
		{
			pglEndPerfQueryINTEL(activeEvent.queries[i]);
			ogl_WarnIfError();
		}

		frame.activeRegions.pop_back();

		SEvent event;
		event.id = id;
		event.isEnter = false;
		frame.events.push_back(event);
	}
Beispiel #16
0
std::deque<tgt::ivec3> Flow3D::toTexturePosition(std::deque<tgt::vec3>& fps, const tgt::ivec3& textureSize,
                                         const tgt::ivec3& offset) const
{
    const tgt::vec3 dim(static_cast<tgt::vec3>(dimensions_));
    const tgt::vec3 textureScaling(static_cast<tgt::vec3>(textureSize) / dim);

    std::deque<tgt::ivec3> tps;
    while (fps.empty() == false) {
        std::deque<tgt::vec3>::iterator it = fps.begin();
        const tgt::vec3& r = *it;
        tgt::ivec3 temp(
            (static_cast<int>(tgt::round(r.x * textureScaling.x)) + offset.x),
            (static_cast<int>(tgt::round(r.y * textureScaling.y)) + offset.y),
            (static_cast<int>(tgt::round(r.z * textureScaling.z)) + offset.z));
        temp = tgt::clamp(temp, tgt::ivec3::zero, textureSize);
        tps.push_back(temp);

        fps.erase(it);
    }
    return tps;
}
Beispiel #17
0
    void
    attach(upstream<OtherTag>&& u) {
        static_assert(
            detail::is_compatible<Tag, OtherTag>::value,
            "upstream protocol is not compatible with this message queue"
        );

        upstream_ = std::move(u.ptr);

        if(operations.empty()) {
            return;
        }

        aux::frozen_visitor_t visitor(upstream_);

        for(auto it = operations.begin(); it != operations.end(); ++it) {
            boost::apply_visitor(visitor, *it);
        }

        operations.clear();
    }
Beispiel #18
0
bool 
process(const std::deque<std::string>& words)
{
	if (words.empty()) return true;
	if (words.size() == 1) {
		if (!symbol_exist(words[0])) return false;
		cout << words[0] << " = " << symbols[words[0]] << endl;
		return true;
	}
	if (words.size() == 2) {
		cout << "ERROR: expected more than 2 words in statement" << endl;
		return false;
	}
	
	size_t i = 0;
	std::string sym;
	if (words[1] == "=") {
		sym = words[0];
		i += 2;
	}
	Int result;
	if (i+1 == words.size()) {
		if (!load_symbol_or_int(words[i], result)) return false;
	} else if (i+3 == words.size() && words[i+1] == "+") {
		Int first, second;
		if (!load_symbol_or_int(words[i], first)) return false;
		if (!load_symbol_or_int(words[i+2], second)) return false;
		result = first + second;
	} else {
		// for now only do plus:
		cout << "ERROR: expected plus statement" << endl;
		return false;
	}

	cout << result << endl;
	if (!sym.empty()) {
		symbols[sym] = result;
	}
	return true;
}
Beispiel #19
0
    void do_work (CompletionCounter)
    {
        if (m_stop_called == true)
            return;

        // We don't have any work to do at this time
        if (m_work.empty ())
            return;

        std::string const name (m_work.front ().names.back());
        HandlerType handler (m_work.front ().handler);

        m_work.front ().names.pop_back ();

        if (m_work.front ().names.empty ())
            m_work.pop_front();

        HostAndPort const hp (parseName (name));

        if (hp.first.empty ())
        {
            JLOG(m_journal.error()) <<
                "Unable to parse '" << name << "'";

            m_io_service.post (m_strand.wrap (std::bind (
                &ResolverAsioImpl::do_work, this,
                CompletionCounter (this))));

            return;
        }

        boost::asio::ip::tcp::resolver::query query (
            hp.first, hp.second);

        m_resolver.async_resolve (query, std::bind (
            &ResolverAsioImpl::do_finish, this, name,
                std::placeholders::_1, handler,
                    std::placeholders::_2,
                        CompletionCounter (this)));
    }
Beispiel #20
0
	void ProcessFrames()
	{
		while (!m_Frames.empty())
		{
			SFrame& frame = m_Frames.front();

			// Queries become available in order so we only need to check the last one
			GLint available = 0;
			pglGetQueryObjectivARB(frame.events.back().query, GL_QUERY_RESULT_AVAILABLE, &available);
			ogl_WarnIfError();
			if (!available)
				break;

			// The frame's queries are now available, so retrieve and record all their results:

			double t = frame.timeStart;
			m_Storage.RecordFrameStart(t);

			for (size_t i = 0; i < frame.events.size(); ++i)
			{
				if (frame.events[i].isEnter)
					m_Storage.Record(CProfiler2::ITEM_ENTER, t, frame.events[i].id);
				else
					m_Storage.Record(CProfiler2::ITEM_LEAVE, t, frame.events[i].id);

				// Associate the frame number with the "frame" region
				if (i == 0)
					m_Storage.RecordAttributePrintf("%u", frame.num);

				// Advance by the elapsed time to the next event
				GLuint64 queryElapsed = 0;
				pglGetQueryObjectui64vEXT(frame.events[i].query, GL_QUERY_RESULT, &queryElapsed);
					// (use the EXT-suffixed function here, as defined by GL_EXT_timer_query)
				ogl_WarnIfError();
				t += (double)queryElapsed / 1e9;
			}

			PopFrontFrame();
		}
	}
Beispiel #21
0
void OddEvenList(
        std::deque<T> a,
        std::function<void(T)> fodd,
        std::function<void(T)> feven)
{
    if(a.empty()) return;
    fodd(a.front());
    a.pop_front();
    struct q {
        static void Continue(std::deque<T> a, decltype(fodd) ffodd, decltype(feven) ffeven)
        {
            if(a.empty()) return;
            ffeven(a.front());
            a.pop_front();
            if(a.empty()) throw std::out_of_range("number of elements");
            ffodd(a.front());
            a.pop_front();
            Continue(a, ffodd, ffeven);
        }
    };
    q::Continue(a, fodd, feven);
}
Beispiel #22
0
	void OnResult(const Reply &r) override
	{
		/* This is a multi bulk reply of the results of the queued commands
		 * in this transaction
		 */

		Log(LOG_DEBUG_2) << "redis: transaction complete with " << r.multi_bulk.size() << " results";

		for (unsigned i = 0; i < r.multi_bulk.size(); ++i)
		{
			const Reply *reply = r.multi_bulk[i];

			if (interfaces.empty())
				break;

			Interface *inter = interfaces.front();
			interfaces.pop_front();

			if (inter)
				inter->OnResult(*reply);
		}
	}
Beispiel #23
0
void JsFile::Poll(fuse_req_t req, struct fuse_pollhandle *ph)
{
    Lock l(m_mutex);
    
    if (ph)
    {
        if (m_pollHandle && ph != m_pollHandle) {
            // Only keep 1 pollhandle going at any one time
            fuse_pollhandle_destroy(m_pollHandle);
        }
        m_pollHandle = ph;
    }
    
    unsigned revents = 0;
    if (!m_events.empty())
        revents |= POLLIN; // input available now
    
    fuse_reply_poll(req, revents);
    
    if (m_pollHandle)
        wakePipe.Notify(); // fuse wants to know when more input is available
}
Beispiel #24
0
/* Return the next key press or 0 if no key in the buffer.
 * The key returned will have been remaped to the correct ascii code for the
 * windows key map.
 * All key presses are buffered up (including windows auto repeat).
 */
UDWORD inputGetKey(utf_32_char *unicode)
{
	if (inputBuffer.empty())
	{
		return 0;
	}

	UDWORD retVal = inputBuffer.front().key;
	if (retVal == 0)
	{
		retVal = ' ';  // Don't return 0 if we got a virtual key, since that's interpreted as no input.
	}

	if (unicode != NULL)
	{
		*unicode = inputBuffer.front().unicode;
	}

	inputBuffer.pop_front();

	return retVal;
}
Beispiel #25
0
void loop() {
	Serial.println("loop");
	while (!data_queue.empty()) {
		Serial.println("shift queue");
		send_data_t send_data = data_queue.front();
		data_queue.pop_front();

		Serial.print("chipId: ");
		Serial.println(send_data.chipId, HEX);

		Serial.print("battery: ");
		Serial.print( static_cast<float>(send_data.battery) / (1<<10) * 3);
		Serial.print(" V (");
		Serial.print(send_data.battery);
		Serial.println(")");

		float avg = 0;
		for (int i = 0; i < 12; i++) {
//			Serial.print(" 0x");
//			Serial.print(send_data.data[i], HEX);
			float adc = send_data.data[i] / 1e6f;
			constexpr unsigned TURNS_N = 2000;
			constexpr unsigned LOAD_RESISTER = 10;

			float I = adc * (TURNS_N / (0.9 * LOAD_RESISTER));
			Serial.print(I * 100);
			Serial.println("W");
			avg += I;
		}
		Serial.println("");
		avg = avg / 12.0;

		Serial.print("avg = ");
		Serial.println(avg * 100);

		gf.post("/home/test/watt", (int32_t)(avg * 100));
	}
	delay(1000);
}
Beispiel #26
0
void NaviPlayer::playTracks(std::deque<std::string> tracks)
{
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    std::string mediaPath;
    mediaPath = mPath+tracks.front()+std::string(".mp3");
    tracks.pop_front();
    MutexLocker lock(playingQueueMutex);
    if(mState!=Phonon::PlayingState){
        LOG4CPLUS_INFO(msLogger, "media state: not playing, setting current source");
        mMedia->setCurrentSource(QString(mediaPath.c_str()));
        mMedia->play();
    }else{
        LOG4CPLUS_INFO(msLogger, "media state: playing, enqueuing");
        playingQueue.push_back(mediaPath);
    }
    while(!tracks.empty())
    {
        mediaPath = mPath+tracks.front()+".mp3";
        tracks.pop_front();
        playingQueue.push_back(mediaPath);
    }
}
Beispiel #27
0
void sched_end_task_callback()
{
	int core = actual_core();

	semaphore_P(sched_stream_lock, 1);
	std::cout << "task " << task_type_names[running_tasks[core]->type];
	std::cout << " id " << running_tasks[core]->task_id << " exited" << std::endl;
	semaphore_V(sched_stream_lock, 1);

	semaphore_P(sched_lock, 1);
	exit_task_queue.push_back(std::move(running_tasks[core]));

	if (task_queue.empty())
	{
		// interrupt scheduler
		semaphore_V(sched_lock, 1);
		SetEvent(cpu_int_table_handlers[0][INT_SCHEDULER]);
		SuspendThread(GetCurrentThread());
	}
	else
	{
		std::unique_ptr<task_control_block> next_task(std::move(task_queue.front()));
		task_queue.pop_front();

		DWORD target_esp = (DWORD)next_task->context.Esp;

		next_task->state = RUNNING;
		running_tasks[core] = std::move(next_task);

		semaphore_V(sched_lock, 1);

		__asm
		{
			mov esp, target_esp
			jmp do_reschedule
		}
	}
}
Beispiel #28
0
static void DrawTimeSlice(std::deque<TimeSlice>& frames, const spring_time curTime, const spring_time maxHist, const float drawArea[4])
{
	// remove old entries
	while (!frames.empty() && (curTime - frames.front().second) > maxHist) {
		frames.pop_front();
	}

	const float y1 = drawArea[1];
	const float y2 = drawArea[3];

	// render
	CVertexArray* va = GetVertexArray();
	va->Initialize();
	for (TimeSlice& ts: frames) {
		float x1 = (ts.first % maxHist).toSecsf() / maxHist.toSecsf();
		float x2 = (ts.second % maxHist).toSecsf() / maxHist.toSecsf();
		x2 = std::max(x1 + globalRendering->pixelX, x2);

		x1 = drawArea[0] + x1 * (drawArea[2] - drawArea[0]);
		x2 = drawArea[0] + x2 * (drawArea[2] - drawArea[0]);

		va->AddVertex0(x1, y1, 0.0f);
		va->AddVertex0(x1, y2, 0.0f);
		va->AddVertex0(x2, y2, 0.0f);
		va->AddVertex0(x2, y1, 0.0f);

		const float mx1 = x1 + 3 * globalRendering->pixelX;
		const float mx2 = x2 - 3 * globalRendering->pixelX;
		if (mx1 < mx2) {
			va->AddVertex0(mx1, y1 + 3 * globalRendering->pixelX, 0.0f);
			va->AddVertex0(mx1, y2 - 3 * globalRendering->pixelX, 0.0f);
			va->AddVertex0(mx2, y2 - 3 * globalRendering->pixelX, 0.0f);
			va->AddVertex0(mx2, y1 + 3 * globalRendering->pixelX, 0.0f);
		}
	}

	va->DrawArray0(GL_QUADS);
}
Beispiel #29
0
void NewObjInGlobal()
{
    int percent = RandomRange(1, 100);
    if (percent <= 20)
    {
        g_globalTable.push_back(g_gc.NewTable(luna::GCGen2));
    }
    else if (percent <= 50)
    {
        g_globalString.push_back(g_gc.NewString(luna::GCGen2));
    }
    else if (percent <= 60)
    {
        if (!g_globalFunction.empty())
        {
            auto index = RandomNum(g_globalFunction.size());
            auto proto = g_globalFunction[index];
            auto c = g_gc.NewClosure(luna::GCGen1);
            c->SetPrototype(proto);
            g_globalClosure.push_back(c);
        }
    }
}
Beispiel #30
0
CVideoBuffer* CVideoBufferPoolDRMPRIME::Get()
{
  CSingleLock lock(m_critSection);

  CVideoBufferDRMPRIME* buf = nullptr;
  if (!m_free.empty())
  {
    int idx = m_free.front();
    m_free.pop_front();
    m_used.push_back(idx);
    buf = m_all[idx];
  }
  else
  {
    int id = m_all.size();
    buf = new CVideoBufferDRMPRIME(*this, id);
    m_all.push_back(buf);
    m_used.push_back(id);
  }

  buf->Acquire(GetPtr());
  return buf;
}