Пример #1
0
int pl_destroy_htable(void)
{
	int i;
	pl_pipe_t *it;
	pl_pipe_t *it0;

	if(_pl_pipes_ht==NULL)
		return -1;

	for(i=0; i<_pl_pipes_ht->htsize; i++)
	{
		/* free entries */
		it = _pl_pipes_ht->slots[i].first;
		while(it)
		{
			it0 = it;
			it = it->next;
			pl_pipe_free(it0);
		}
		/* free locks */
		lock_destroy(&_pl_pipes_ht->slots[i].lock);
	}
	shm_free(_pl_pipes_ht->slots);
	shm_free(_pl_pipes_ht);
	_pl_pipes_ht = NULL;
	return 0;
}
Пример #2
0
void pl_pipe_timer_update(int interval, int netload)
{
	int i;
	pl_pipe_t *it, *it0;

	if(_pl_pipes_ht==NULL)
		return;

	for(i=0; i<_pl_pipes_ht->htsize; i++)
	{
		lock_get(&_pl_pipes_ht->slots[i].lock);
		it = _pl_pipes_ht->slots[i].first;
		while(it)
		{
			if (pl_clean_unused) {
				if (it->counter > 0) {
					// used, reset unused intervals counter
					it->unused_intervals = 0;
				} else {
					if (it->unused_intervals >= pl_clean_unused) {
						// unused for n intervals, delete
						it0 = it;
						it = it->next;
						if(it0->prev==NULL) {
							_pl_pipes_ht->slots[i].first = it;
						} else {
							it0->prev->next = it;
						}
						if(it) {
							it->prev = it0->prev;
						}
						_pl_pipes_ht->slots[i].ssize--;
						pl_pipe_free(it0);
						continue;
					} else {
						it->unused_intervals++;
					}
				}
			}
			if (it->algo != PIPE_ALGO_NOP) {
				if( it->algo == PIPE_ALGO_NETWORK ) {
					it->load = ( netload > it->limit ) ? 1 : -1;
				} else if (it->limit && interval) {
					it->load = it->counter / it->limit;
				}
				it->last_counter = it->counter;
				it->counter = 0;
			}

			it = it->next;
		}
		lock_release(&_pl_pipes_ht->slots[i].lock);
	}
}