// ------------------------------------------------------------------------
    void createWhite(bool private_init = true)
    {
#ifndef SERVER_ONLY
        glBindTexture(GL_TEXTURE_2D, m_texture_name);
        static int32_t data[4] = { -1, -1, -1, -1 };
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0,
#ifdef USE_GLES2
            GL_RGBA,
#else
            GL_BGRA,
#endif
            GL_UNSIGNED_BYTE, data);
        glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0,
#ifdef USE_GLES2
            GL_RGBA,
#else
            GL_BGRA,
#endif
            GL_UNSIGNED_BYTE, data);
        glBindTexture(GL_TEXTURE_2D, 0);
        if (private_init)
        {
            m_width.store(2);
            m_height.store(2);
        }
        else
        {
            m_width.store(0);
            m_height.store(0);
        }
#endif
    }
Пример #2
0
void
step(DhtRunner& dht, std::atomic_uint& done, std::shared_ptr<NodeSet> all_nodes, dht::InfoHash cur_h, unsigned cur_depth)
{
    std::cout << "step at " << cur_h << ", depth " << cur_depth << std::endl;
    done++;
    dht.get(cur_h, [all_nodes](const std::vector<std::shared_ptr<Value>>& /*values*/) {
        return true;
    }, [&,all_nodes,cur_h,cur_depth](bool, const std::vector<std::shared_ptr<Node>>& nodes) {
        all_nodes->insert(nodes.begin(), nodes.end());
        NodeSet sbuck {nodes.begin(), nodes.end()};
        if (not sbuck.empty()) {
            unsigned bdepth = sbuck.size()==1 ? 0u : InfoHash::commonBits((*sbuck.begin())->id, (*std::prev(sbuck.end()))->id);
            unsigned target_depth = std::min(159u, bdepth+3u);
            std::cout << cur_h << " : " << nodes.size() << " nodes; target is " << target_depth << " bits deep (cur " << cur_depth << ")" << std::endl;
            for (unsigned b = cur_depth ; b < target_depth; b++) {
                auto new_h = cur_h;
                new_h.setBit(b, 1);
                step(dht, done, all_nodes, new_h, b+1);
            }
        }
        done--;
        std::cout << done.load() << " operations left, " << all_nodes->size() << " nodes found." << std::endl;
        cv.notify_one();
    });
}
Пример #3
0
 // ------------------------------------------------------------------------
 void stopThreads()
 {
     m_max_threaded_load_obj.store(0);
     std::unique_lock<std::mutex> ul(m_thread_obj_mutex);
     m_threaded_functions.push_back([](){ return true; });
     m_thread_obj_cv.notify_all();
     ul.unlock();
     for (std::thread& t : m_threaded_load_obj)
     {
         t.join();
     }
     m_threaded_load_obj.clear();
 }
Пример #4
0
 void swap_queues()
 {
     for(unsigned int i=0; i<m_full_slots; ++i)
     {
         m_queues[m_consumer_q].vec[i].valid.store(false,std::memory_order_release);
     }
     unsigned int newpoint=m_consumer_q<<30;
     m_consumer_q=exchange_queue(m_consumer_q);
     unsigned int old_pointer=m_pointer.exchange(newpoint,std::memory_order_release);
     m_full.store(false,std::memory_order_release);
     old_pointer&=~MASK;
     m_full_slots=std::min(old_pointer,Qlen);
     m_read=0;
 }
    // ------------------------------------------------------------------------
    void createTransparent()
    {
#ifndef SERVER_ONLY
        glBindTexture(GL_TEXTURE_2D, m_texture_name);
        static uint32_t data[4] = { 0, 0, 0, 0 };
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0,
#ifdef USE_GLES2
            GL_RGBA,
#else
            GL_BGRA,
#endif
            GL_UNSIGNED_BYTE, data);
        glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0,
#ifdef USE_GLES2
            GL_RGBA,
#else
            GL_BGRA,
#endif
            GL_UNSIGNED_BYTE, data);
        glBindTexture(GL_TEXTURE_2D, 0);
        m_width.store(2);
        m_height.store(2);
#endif
    }
Пример #6
0
void
controller()
{
	while( agents_count != agents_destroyed.load( std::memory_order_acquire ) )
		std::this_thread::yield();

	std::cout << "All agents are destroyed. Take SO Environment some time..."
			<< std::endl;

	std::this_thread::sleep_for( std::chrono::seconds( 1 ) );

	auto env = environment.load( std::memory_order_acquire );
	if( !env )
	{
		std::cerr << "environment cannot be nullptr!" << std::endl;
		std::abort();
	}
	else
		std::cout << "Stopping SO Environment..." << std::endl;
	env->stop();
}
 // ------------------------------------------------------------------------
 unsigned getHeight() const                      { return m_height.load(); }
 // ------------------------------------------------------------------------
 unsigned getWidth() const                        { return m_width.load(); }
Пример #9
0
 explicit ThreadPool(const unsigned int& size, const unsigned int& queues_size) :queues(queues_size), thread_index(queues_size), thread_cond(size) {
     auto th_group_size = size / queues_size ;
     auto thread_offset = 0u;
     for (auto i = 0u; i < queues_size; ++i) {
         for (auto j = 0u; j < th_group_size; ++j, ++thread_offset) {
             thread_index[i].push_back(thread_offset);
             workers.emplace_back([this](const unsigned &queue_id, const unsigned &thread_id) {
                 std::mutex mut;
                 std::unique_lock<std::mutex> lk(mut);
                 while (true) {
                     if (!queues[queue_id].empty()) {
                         queues[queue_id].consume_one([](auto&& i) {
                             (*i)();
                             delete i;
                         });
                     }
                     else if (!stoped) {
                         //TODO: (High) add pause and check if queue paused or stoped
                         th_stoped_counter.fetch_add(1, std::memory_order_relaxed);
                         stoped_cond.notify_all();
                         thread_cond[thread_id].wait(lk);
                         th_stoped_counter.fetch_add(-1u, std::memory_order_relaxed);
                     }
                          else return;
                 }
             },i,thread_offset);
         }
     }
     auto threads = size - th_group_size * queues_size;
     auto group_size = gcd(threads,queues_size);
     threads /= group_size;
     auto queue_group_size = queues_size / group_size;
     for (auto i = 0u; i < group_size; ++i) {
         for (auto j = 0u; j < threads; ++j) {
             for (auto k = 0u; k < queue_group_size; ++k)
                 thread_index[k + i *queue_group_size].push_back(j + thread_offset + i * threads);
             workers.emplace_back([this](const unsigned& queue_group_size, const unsigned& group_id, const unsigned& thread_id) {
                 std::mutex mut;
                 std::unique_lock<std::mutex> lk(mut);
                 std::vector<bool> all_finished (queue_group_size,false);
                 auto count = 0u;
                 bool continue_thread{true};
                 while (true) {
                     continue_thread = stoped;
                     for (unsigned i = 0; i < queue_group_size; ++i) {
                         if (!queues[i+group_id*queue_group_size].empty()) {
                             continue_thread = true;
                             queues[i+group_id*queue_group_size].consume_one([](auto&& i) {
                                 (*i)();
                                 delete i;
                             });
                         } else {
                             if (stoped) {
                                 if (!all_finished[i]) { count++; all_finished[i]=!all_finished[i]; }
                                 else if (count ==queue_group_size ) return;
                             }
                         }
                     }
                     if (!continue_thread) {
                         //TODO: (High) add pause and check if queue paused or stoped
                         th_stoped_counter.fetch_add(1, std::memory_order_relaxed);
                         stoped_cond.notify_all();
                         thread_cond[thread_id].wait(lk);
                         th_stoped_counter.fetch_add(-1u, std::memory_order_relaxed);
                     }
                 }
             },queue_group_size,i,j + thread_offset);
         }
     }
 }
Пример #10
0
 bool is_empty() const noexcept {
     return th_stoped_counter.load() == workers.size(); //TODO: (Low) think about memory_order
 }