Exemplo n.º 1
0
    /** Given an sarray, returns a small number uniquely associated with
     * that sarray.  This number is unique over the course of the
     * program run.
     */
    static size_t unique_sarray_tag(const std::shared_ptr<sarray<flexible_type> >& sa) {
        static mutex access_lock;
        std::lock_guard<mutex> _lg(access_lock);

        static size_t current_number = 0;
        static std::map<ptrdiff_t, std::pair<std::weak_ptr<sarray<flexible_type> >, size_t> > tracked_numbers;

        ptrdiff_t key = ptrdiff_t(sa.get());

        auto it = tracked_numbers.find(key);

        if(it != tracked_numbers.end()) {
            if(!it->second.first.expired())
                return it->second.second;
            else
                tracked_numbers.erase(it);
        }

        ++current_number;

        // Purge out expired weak pointers if they are present
        if(current_number % 256 == 0) {
            for(auto it = tracked_numbers.begin(); it != tracked_numbers.end();) {
                if(it->second.first.expired())
                    it = tracked_numbers.erase(it);
                else
                    ++it;
            }
        }

        tracked_numbers[key] = {sa, current_number};
        return current_number;
    }
void SurfaceComposerClient::dispose()
{
    // this can be called more than once.

    sp<IMemoryHeap>             controlMemory;
    sp<ISurfaceFlingerClient>   client;

    {
        Mutex::Autolock _lg(gLock);
        Mutex::Autolock _lm(mLock);

        mSignalServer = 0;

        if (mClient != 0) {
            client = mClient;
            mClient.clear();

            ssize_t i = gActiveConnections.indexOfKey(client->asBinder());
            if (i >= 0 && gActiveConnections.valueAt(i) == this) {
                VERBOSE("Removing client %p from map at %d", this, int(i));
                gActiveConnections.removeItemsAt(i);
            }
        }

        delete mPrebuiltLayerState;
        mPrebuiltLayerState = 0;
        controlMemory = mControlMemory;
        mControlMemory.clear();
        mControl = 0;
        mStatus = NO_INIT;
    }
}
Exemplo n.º 3
0
	void TaskRunnerPool::Deinit() {

		wawo::thread::LockGuard<Mutex> _lg(m_mutex) ;
		if( m_is_running == false ) { return ; }

		m_is_running = false;
		while( !m_runners.empty() ) {
			TaskRunner* r = m_runners.back();
			WAWO_DELETE( r ) ;
			m_runners.pop_back() ;
		}
	}
Exemplo n.º 4
0
	void TaskRunnerPool::SetMaxTaskRunner( u32_t const& count ) {
		UniqueLock<Mutex> _lg(m_mutex) ;
		WAWO_ASSERT( count>0 && count<WAWO_MAX_TASK_RUNNER_CONCURRENCY_COUNT );

		m_max_concurrency = count;

		//dynamic clear ,,if ...
		while( m_runners.size() > m_max_concurrency ) {
			TaskRunner* runner = m_runners.back();
			WAWO_DELETE( runner ) ;
			m_runners.pop_back() ;
		}
	}
Exemplo n.º 5
0
	int TaskRunnerPool::_NewTaskRunner() {

		wawo::thread::UniqueLock<Mutex> _lg(m_mutex) ;
		if( !m_is_running ) {
			return wawo::E_TASK_RUNNER_POOL_INVALID_STATE ;
		}

		int size = m_runners.size() ;
		TaskRunner* tr = new TaskRunner(size) ;
		WAWO_RETURN_V_IF_MATCH( wawo::E_MEMORY_ALLOC_FAILED , tr == NULL );

		int rt = tr->Start();
		if( rt != wawo::OK ) {
			tr->Stop();
			WAWO_DELETE( tr );
			return rt;
		}
		m_runners.push_back( tr );
		return rt;
	}
Exemplo n.º 6
0
/* Multikey introsort for medium size groups. */
static
void
_multikey_introsort(const sauchar_t *T, const saidx_t *PA,
                    saidx_t *first, saidx_t *last,
                    saidx_t depth) {
  struct { saidx_t *a, *b, c, d; } stack[STACK_SIZE];
  const sauchar_t *Td;
  saidx_t *a, *b, *c, *d, *e, *f;
  saidx_t s, t;
  saidx_t ssize;
  saidx_t limit;
  saint_t v, x = 0;

  for(ssize = 0, limit = _lg(last - first);;) {

    if((last - first) <= SS_INSERTIONSORT_THRESHOLD) {
      if(1 < (last - first)) { _insertionsort(T, PA, first, last, depth); }
      STACK_POP(first, last, depth, limit);
      continue;
    }

    Td = T + depth;
    if(limit-- == 0) { _heapsort(Td, PA, first, last - first); }
    if(limit < 0) {
      for(a = first + 1, v = Td[PA[*first]]; a < last; ++a) {
        if((x = Td[PA[*a]]) != v) {
          if(1 < (a - first)) { break; }
          v = x;
          first = a;
        }
      }
      if(Td[PA[*first] - 1] < v) {
        first = _substring_partition(PA, first, a, depth);
      }
      if((a - first) <= (last - a)) {
        if(1 < (a - first)) {
          STACK_PUSH(a, last, depth, -1);
          last = a, depth += 1, limit = _lg(a - first);
        } else {
          first = a, limit = -1;
        }
      } else {
        if(1 < (last - a)) {
          STACK_PUSH(first, a, depth + 1, _lg(a - first));
          first = a, limit = -1;
        } else {
          last = a, depth += 1, limit = _lg(a - first);
        }
      }
      continue;
    }

    /* choose pivot */
    a = _pivot(Td, PA, first, last);
    v = Td[PA[*a]];
    SWAP(*first, *a);

    /* partition */
    for(b = first; (++b < last) && ((x = Td[PA[*b]]) == v);) { }
    if(((a = b) < last) && (x < v)) {
      for(; (++b < last) && ((x = Td[PA[*b]]) <= v);) {
        if(x == v) { SWAP(*b, *a); ++a; }
      }
    }
    for(c = last; (b < --c) && ((x = Td[PA[*c]]) == v);) { }
    if((b < (d = c)) && (x > v)) {
      for(; (b < --c) && ((x = Td[PA[*c]]) >= v);) {
        if(x == v) { SWAP(*c, *d); --d; }
      }
    }
    for(; b < c;) {
      SWAP(*b, *c);
      for(; (++b < c) && ((x = Td[PA[*b]]) <= v);) {
        if(x == v) { SWAP(*b, *a); ++a; }
      }
      for(; (b < --c) && ((x = Td[PA[*c]]) >= v);) {
        if(x == v) { SWAP(*c, *d); --d; }
      }
    }

    if(a <= d) {
      c = b - 1;

      if((s = a - first) > (t = b - a)) { s = t; }
      for(e = first, f = b - s; 0 < s; --s, ++e, ++f) { SWAP(*e, *f); }
      if((s = d - c) > (t = last - d - 1)) { s = t; }
      for(e = b, f = last - s; 0 < s; --s, ++e, ++f) { SWAP(*e, *f); }

      a = first + (b - a), c = last - (d - c);
      b = (v <= Td[PA[*a] - 1]) ? a : _substring_partition(PA, a, c, depth);

      if((a - first) <= (last - c)) {
        if((last - c) <= (c - b)) {
          STACK_PUSH(b, c, depth + 1, _lg(c - b));
          STACK_PUSH(c, last, depth, limit);
          last = a;
        } else if((a - first) <= (c - b)) {
          STACK_PUSH(c, last, depth, limit);
          STACK_PUSH(b, c, depth + 1, _lg(c - b));
          last = a;
        } else {
          STACK_PUSH(c, last, depth, limit);
          STACK_PUSH(first, a, depth, limit);
          first = b, last = c, depth += 1, limit = _lg(c - b);
        }
      } else {
        if((a - first) <= (c - b)) {
          STACK_PUSH(b, c, depth + 1, _lg(c - b));
          STACK_PUSH(first, a, depth, limit);
          first = c;
        } else if((last - c) <= (c - b)) {
          STACK_PUSH(first, a, depth, limit);
          STACK_PUSH(b, c, depth + 1, _lg(c - b));
          first = c;
        } else {
          STACK_PUSH(first, a, depth, limit);
          STACK_PUSH(c, last, depth, limit);
          first = b, last = c, depth += 1, limit = _lg(c - b);
        }
      }
    } else {
      limit += 1;
      if(Td[PA[*first] - 1] < v) {
        first = _substring_partition(PA, first, last, depth);
        limit = _lg(last - first);
      }
      depth += 1;
    }
  }
}
Exemplo n.º 7
0
	void TaskRunnerPool::Init() {
		wawo::thread::LockGuard<Mutex> _lg(m_mutex) ;
		m_is_running = true ;
		m_last_runner_idx = 0;
	}