Exemplo n.º 1
0
/* lock must be held */
static void __cookie_cache_check_swap(struct cookie_cache *c) {
	if (poller_now - c->swap_time >= 30) {
		g_hash_table_remove_all(c->old.cookies);
#if GLIB_CHECK_VERSION(2,14,0)
		g_string_chunk_clear(c->old.chunks);
		swap_ptrs(&c->old.chunks, &c->current.chunks);
#else
		g_string_chunk_free(c->old.chunks);
		c->old.chunks = c->current.chunks;
		c->current.chunks = g_string_chunk_new(4 * 1024);
#endif
		swap_ptrs(&c->old.cookies, &c->current.cookies);
		c->swap_time = poller_now;
	}
}
/** Update database entry with new information (if needed)
  @param entry Entry to be updated
  @param new_config New config
  @return 0 if success, !0 in other case (reason printed)
  */
static int update_organization(organization_db_entry_t *entry,
				json_t *new_config) {
	int rc = 0;
	json_error_t jerr;
	json_int_t bytes_limit = 0;
	json_t *aux_enrichment = NULL;

	const int unpack_rc = json_unpack_ex(new_config, &jerr,
		JSON_STRICT,
		"{s?O,s?{s?I}}",
		"enrichment",&aux_enrichment,
		"limits","bytes",&bytes_limit);

	if (0 != unpack_rc) {
		const char *organization_uuid =
			organization_db_entry_get_uuid(entry);
		rdlog(LOG_ERR,"Couldn't unpack organization %s limits: %s",
						organization_uuid, jerr.text);
		rc = -1;
		goto unpack_err;
	}

	pthread_mutex_lock(&entry->mutex);
	swap_ptrs(entry->enrichment, aux_enrichment);
	entry->bytes_limit.max = (uint64_t)bytes_limit;
	pthread_mutex_unlock(&entry->mutex);

unpack_err:
	if (aux_enrichment) {
		json_decref(aux_enrichment);
	}

	return rc;
}
Exemplo n.º 3
0
/*
 * Juho Gävert & Santeri Hiltunen
 Starting point of calculation. Searches for temperature balance in Array for
 maximum iterations of max_iters.
 */
double calculate_heatconduct(Array* arr, unsigned int max_iters)
{

  if (max_iters == 0 || arr->width < 3 || arr->height < 3)
    return -1;

  Array* temp_arr = new_array(arr->width, arr->height);
  copy_array(arr, temp_arr);

  double prev_mean = -1;
  for (unsigned int i = 0; i < max_iters; ++i) {
    double new_mean = calculate_iteration(arr, temp_arr);

    swap_ptrs((void**) &arr, (void**) &temp_arr);

    if (conf.verbose) {
      printf("Iter: %d Mean: %.15f\n", i + 1, new_mean);
      if (conf.verbose > 1) {
        print_arr(arr);
      }
    }

    if (fabs(new_mean - prev_mean) < 0.0000000000001) {
      printf("Found balance after %d iterations.\n", i);
      del_array(temp_arr);
      return new_mean;
    }

    prev_mean = new_mean;
  }
  del_array(temp_arr);
  printf("Didn't find balance after %d iterations.\n", max_iters);
  return prev_mean;
}
Exemplo n.º 4
0
int main(void)
{
	int c = 42;
	int d = 69105;
	int *blah = &c;
	int *foo = &d;
	swap_ptrs(&blah, &foo);

	return 0;
}
int main(void)
{
	/* Here we do stuff that's genuinely invalid. Example: 1
	 * use our swap function to swap two unsigned longs. */
	int c = 42;
	int d = 69105;
	unsigned long long blah = (unsigned long long) &c;
	unsigned long long foo = (unsigned long long) &d;
	swap_ptrs(&blah, &foo);

	/* Any more? */

	return 0;
}
Exemplo n.º 6
0
void	sort_strings(char **args, int size)
{
	int i;
	int sorted;

	sorted = 0;
	while (!sorted)
	{
		sorted = 1;
		i = -1;
		while (++i < size - 1)
			if (ft_strcmp(args[i], args[i + 1]) == 1)
			{
				swap_ptrs(&(args[i]), &(args[i + 1]));
				sorted = 0;
			}
	}
}