Beispiel #1
0
static void _dead_thread_two (void)
{
	s4_transaction_t *trans = s4_begin (s4, 0);

	CU_ASSERT_PTR_NOT_NULL (trans);
	g_usleep (G_USEC_PER_SEC / 2);
	CU_ASSERT_TRUE (s4_add (trans, "b", val, "a", val, "src"));
	g_usleep (G_USEC_PER_SEC);
	CU_ASSERT_FALSE (s4_add (trans, "a", val, "b", val, "src"));

	CU_ASSERT_FALSE (s4_commit (trans));
	CU_ASSERT_EQUAL (s4_errno (), S4E_DEADLOCK);
}
Beispiel #2
0
static void _dead_thread_one (void)
{
	s4_transaction_t *trans = s4_begin (s4, 0);

	CU_ASSERT_PTR_NOT_NULL (trans);
	CU_ASSERT_TRUE (s4_add (trans, "a", val, "b", val, "src"));

	g_usleep (G_USEC_PER_SEC);

	CU_ASSERT_TRUE (s4_add (trans, "b", val, "a", val, "src"));

	CU_ASSERT_TRUE (s4_commit (trans));
}
Beispiel #3
0
static xmms_medialib_session_t *
xmms_medialib_session_begin_internal (xmms_medialib_t *medialib,
                                      s4_transaction_flag_t flags)
{
	xmms_medialib_session_t *ret = g_new0 (xmms_medialib_session_t, 1);

	xmms_object_ref (medialib);
	ret->medialib = medialib;

	s4_t *s4 = xmms_medialib_get_database_backend (medialib);
	ret->trans = s4_begin (s4, flags);

	return ret;
}
Beispiel #4
0
Datei: t_s4.c Projekt: xmms2/s4
static void check_db (struct db_struct *db)
{
	int i, j;
	s4_fetchspec_t *fs = s4_fetchspec_create ();
	s4_fetchspec_add (fs, NULL, NULL, S4_FETCH_DATA);

	for (i = 0; db[i].name != NULL; i++) {
		s4_val_t *name_val = s4_val_new_string (db[i].name);
		s4_condition_t *cond = s4_cond_new_filter (S4_FILTER_EQUAL,
				"entry", name_val, NULL, S4_CMP_CASELESS, S4_COND_PARENT);
		s4_transaction_t *trans = s4_begin (s4, 0);
		s4_resultset_t *set = s4_query (trans, fs, cond);
		s4_commit (trans);
		const s4_result_t *res = s4_resultset_get_result (set, 0, 0);
		int found[ARG_SIZE] = {0};

		for (; res != NULL; res = s4_result_next (res)) {
			for (j = 0; db[i].args[j] != NULL; j++) {
				const char *str;

				if (s4_val_get_str (s4_result_get_val (res), &str) && !strcmp (str, db[i].args[j]) &&
						!strcmp (s4_result_get_key (res), "property") &&
						!strcmp (s4_result_get_src (res), db[i].src)) {
					found[j] = 1;
					break;
				}
			}
		}
		for (j = 0; db[i].args[j] != NULL; j++) {
			CU_ASSERT_EQUAL (found[j], 1);
		}

		s4_resultset_free (set);
		s4_cond_free (cond);
		s4_val_free (name_val);
	}

	s4_fetchspec_free (fs);
}
Beispiel #5
0
Datei: t_s4.c Projekt: xmms2/s4
static void create_db (struct db_struct *db)
{
	s4_val_t *name_val, *arg_val;
	int i, j;

	for (i = 0; db[i].name != NULL; i++) {
		name_val = s4_val_new_string (db[i].name);

		for (j = 0; db[i].args[j] != NULL; j++) {
			s4_transaction_t *trans;

			arg_val = s4_val_new_string (db[i].args[j]);

			trans = s4_begin (s4, 0);
			CU_ASSERT (s4_add (trans, "entry", name_val, "property", arg_val, db[i].src));
			s4_commit (trans);

			s4_val_free (arg_val);
		}

		s4_val_free (name_val);
	}
}
Beispiel #6
0
int main (int argc, char *argv[])
{
	s4_t *s4;
	s4_transaction_t *t;
	int i;
	char *filename = tmpnam (NULL);
	GTimeVal cur, prev;

	g_thread_init (NULL);
	log_init(G_LOG_LEVEL_MASK & ~G_LOG_LEVEL_DEBUG);
	g_get_current_time (&prev);

	s4 = s4_open (filename, NULL, S4_NEW);

	if (s4 == NULL) {
		fprintf (stderr, "Could not open %s\n", argv[1]);
		exit (1);
	}

	take_time ("s4_open took", &prev, &cur);

	for (i = 0; i < ENTRIES; i++) {
		s4_val_t *val;
		val = s4_val_new_int (i);
		t = s4_begin (s4, 0);
		s4_add (t, "a", val, "b", val, "src");
		s4_commit (t);
		s4_val_free (val);
	}

	take_time ("s4be_ip_add took", &prev, &cur);

	for (i = 0; i < ENTRIES; i++) {
		s4_val_t *val;
		val = s4_val_new_int (i);
		t = s4_begin (s4, 0);
		s4_del (t, "a", val, "b", val, "src");
		s4_commit (t);
		s4_val_free (val);
	}

	take_time ("s4be_ip_del took", &prev, &cur);

	t = s4_begin (s4, 0);
	for (i = 0; i < ENTRIES; i++) {
		s4_val_t *val;
		val = s4_val_new_int (i);
		s4_add (t, "a", val, "b", val, "src");
		s4_val_free (val);
	}
	s4_commit (t);

	take_time ("s4be_ip_add took", &prev, &cur);

	t = s4_begin (s4, 0);
	for (i = 0; i < ENTRIES; i++) {
		s4_val_t *val;
		val = s4_val_new_int (i);
		s4_del (t, "a", val, "b", val, "src");
		s4_val_free (val);
	}
	s4_commit (t);

	take_time ("s4be_ip_del took", &prev, &cur);

	for (i = ENTRIES; i > 0; i--) {
		s4_val_t *val;
		val = s4_val_new_int (i);
		t = s4_begin (s4, 0);
		s4_add (t, "a", val, "b", val, "src");
		s4_commit (t);
		s4_val_free (val);
	}

	take_time ("s4be_ip_add (backwards) took", &prev, &cur);

	for (i = ENTRIES; i > 0; i--) {
		s4_val_t *val;
		val = s4_val_new_int (i);
		t = s4_begin (s4, 0);
		s4_del (t, "a", val, "b", val, "src");
		s4_commit (t);
		s4_val_free (val);
	}

	take_time ("s4be_ip_del (backwards) took", &prev, &cur);

	s4_close (s4);

	take_time ("s4_close took", &prev, &cur);

	g_unlink (filename);
	g_unlink (g_strconcat (filename, ".log", NULL));

	take_time ("g_unlink took", &prev, &cur);

	return 0;
}