コード例 #1
0
ファイル: stats-tool.c プロジェクト: HoraceWeebler/connman
static int stats_file_update_cache(struct stats_file *file)
{
	struct stats_record *it, *end;

	update_max_nr_entries(file);
	update_nr_entries(file);
	update_first(file);
	update_last(file);
	file->home_first = NULL;
	file->roaming_first = NULL;

	end = get_iterator_end(file);
	for (it = get_iterator_begin(file);
			it != end;
			it = get_next(file, it)) {

		if (!file->home_first && it->roaming == 0)
			file->home_first = it;

		if (!file->roaming_first && it->roaming == 1)
			file->roaming_first = it;

		if (file->home_first && file->roaming_first)
			break;
	}

	return 0;
}
コード例 #2
0
ファイル: stats.c プロジェクト: saukko/connman
static void stats_file_update_cache(struct stats_file *file)
{
	update_first(file);
	update_last(file);
	update_home(file);
	update_roaming(file);
}
コード例 #3
0
ファイル: parsum.hpp プロジェクト: robryk/parsum
		virtual update_result update(intptr_t tid, const T* val) {
			update_result child_result = children_[child_idx(tid)]->update(child_tid(tid), val);
			intptr_t other_version = children_[1-child_idx(tid)]->get_version();

			bool tt = false;
			do {
				intptr_t my_version = get_version();
				value my_value;
				if (!history_.get(my_version, &my_value))
					break;
				if (my_value.child_versions[child_idx(tid)] >= child_result.version && my_value.child_versions[1-child_idx(tid)] >= other_version)
					break;
				value new_value;
				new_value.child_versions[0] = children_[0]->get(&new_value.child_values[0]);
				new_value.child_versions[1] = children_[1]->get(&new_value.child_values[1]);
				if (new_value.child_versions[0] == INVALID_VERSION || new_value.child_versions[1] == INVALID_VERSION)
					break;
				update_last(my_version % thread_count_);
				if (history_.publish(tid, my_version+1, &new_value)) {
					counter::inc_counter(counter::Parsum_OwnPublish, 1);
					break;
				}
			} while (true);

			counter::inc_counter(counter::Parsum_Update, 1);

			update_result result;
			bool ok = get_last(tid, &result);
			assert(ok);
			assert(result.update_count == child_result.update_count);
			return result;
		}
コード例 #4
0
ファイル: parsum.hpp プロジェクト: robryk/parsum
		virtual bool get_last(intptr_t tid, update_result* output) {
			update_last(tid);
			latest_value last_value;
			intptr_t last_version = latest_[tid].get(&last_value);
			if (last_version == holder<latest_value>::INVALID_VERSION)
				return false;
			output->update_count = last_version;
			output->value_before = last_value.value_before;
			output->version = last_value.version;
			return true;
		}
コード例 #5
0
ファイル: ceph.c プロジェクト: Zanop/collectd
/**
 * Calculate average b/t current data and last poll data
 * if last poll data exists
 */
static double get_last_avg(struct ceph_daemon *d, const char *ds_n, int index,
        double cur_sum, uint64_t cur_count)
{
    double result = -1.1, sum_delt = 0.0;
    uint64_t count_delt = 0;
    int tmp_index = 0;
    if(d->last_idx > index)
    {
        if(strcmp(d->last_poll_data[index]->ds_name, ds_n) == 0)
        {
            tmp_index = index;
        }
        //test previous index
        else if((index > 0) && (strcmp(d->last_poll_data[index-1]->ds_name, ds_n) == 0))
        {
            tmp_index = (index - 1);
        }
        else
        {
            tmp_index = backup_search_for_last_avg(d, ds_n);
        }

        if((tmp_index > -1) && (cur_count > d->last_poll_data[tmp_index]->last_count))
        {
            sum_delt = (cur_sum - d->last_poll_data[tmp_index]->last_sum);
            count_delt = (cur_count - d->last_poll_data[tmp_index]->last_count);
            result = (sum_delt / count_delt);
        }
    }

    if(result == -1.1)
    {
        result = NAN;
    }
    if(update_last(d, ds_n, tmp_index, cur_sum, cur_count) == -ENOMEM)
    {
        return -ENOMEM;
    }
    return result;
}
コード例 #6
0
ファイル: server.c プロジェクト: j3gb3rt/CS4210Proj2
int main(int argc, char *argv[])
{
	process_queue *curr_process;
	process_queue *next_process;

	remote_service_server_init();
	pthread_create(&msg_watcher, NULL, (void *)&msgq_watch, NULL);
	printf("message queue watching thread created\n");

	if(pthread_mutex_init(&lock, NULL) != 0)
	{
		printf("mutex init failed\n");
	}
	
	while(1) {
		/*iterate through the process queue
			   and add and store result unlock and
			   detach */
		curr_process = queue;
		pthread_mutex_lock(&lock);
		if (curr_process != NULL && curr_process->requests != NULL) {
			do {
//				int shared_mem_identifier;
				shared_block *shared_mem;
				request_queue *request;
				
				request = curr_process->requests;
					
				shared_mem = request->shm;
				shared_mem->ret_val = shared_mem->arg0 + shared_mem->arg1;
				shared_mem->locked = 0;
				printf("request completed: %i + %i = %i\n", shared_mem->arg0, shared_mem->arg1, shared_mem->ret_val);
				shmdt(shared_mem);

				
				if (request->next != NULL) {
					curr_process->requests->next->last = request->last;
					curr_process->requests = request->next;
					free(request);
				} else  {
//					queue empty
					if(curr_process == queue && curr_process == queue->last)
					{
						queue = NULL;
					}else if(curr_process == queue)
//					assign new node as queue head
					{
						queue = curr_process->next;
						queue->last = curr_process->last;
					}else if(curr_process == queue->last)
					{
						update_last();
					}
					next_process = curr_process->next;
					free(curr_process->requests);
					free(curr_process);
					curr_process = next_process;
					printf("process node freed\n");
				}
				
			} while (curr_process != NULL);
		}
		pthread_mutex_unlock(&lock);
	}
}