pkg

Check-in [9c196b93c3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Ad a pkgdb_downgrade_lock() to go from EXCLUSIVE to ADVISORY
Timelines: family | ancestors | descendants | both | trunk | gsoc2013
Files: files | file ages | folders
SHA1: 9c196b93c3de2eccb3577b45c83ec684677c51fb
User & Date: bryan@shatow.net 2014-06-11 18:25:14
Context
2014-06-11
18:26
pkg check -d: Fix double locking errors Rather than lock/release in fix_deps, let the caller handle the upgrade on the lock it already holds. Rather than releasing the lock completely after each action just downgrade it to ADVISORY again so that the next action can upgrade it again. This is mostly noticeable when passing multiple patterns to pkg-check. check-in: c6280bd2b6 user: bryan@shatow.net tags: trunk, gsoc2013
18:25
Ad a pkgdb_downgrade_lock() to go from EXCLUSIVE to ADVISORY check-in: 9c196b93c3 user: bryan@shatow.net tags: trunk, gsoc2013
17:57
pkg check -d: Fix crash, should not close the db when reopened, it will be closed later Fixes #814 check-in: e34b86c5aa user: bryan@shatow.net tags: trunk, gsoc2013
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to libpkg/libpkg.ver.

274
275
276
277
278
279
280

281
282
283
284
285
286
287
	pkgdb_add_annotation;
	pkgdb_begin_solver;
	pkgdb_case_sensitive;
	pkgdb_close;
	pkgdb_cmd;
	pkgdb_compact;
	pkgdb_delete_annotation;

	pkgdb_dump;
	pkgdb_end_solver;
	pkgdb_file_set_cksum;
	pkgdb_find_shlib_provide;
	pkgdb_find_shlib_require;
	pkgdb_get_pattern_query;
	pkgdb_get_reponame;







>







274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
	pkgdb_add_annotation;
	pkgdb_begin_solver;
	pkgdb_case_sensitive;
	pkgdb_close;
	pkgdb_cmd;
	pkgdb_compact;
	pkgdb_delete_annotation;
	pkgdb_downgrade_lock;
	pkgdb_dump;
	pkgdb_end_solver;
	pkgdb_file_set_cksum;
	pkgdb_find_shlib_provide;
	pkgdb_find_shlib_require;
	pkgdb_get_pattern_query;
	pkgdb_get_reponame;

Changes to libpkg/pkg.h.in.

1000
1001
1002
1003
1004
1005
1006


1007
1008
1009
1010
1011
1012
1013
int pkgdb_open_all(struct pkgdb **db, pkgdb_t type, const char *reponame);

/**
 * Locking functions
 */
int pkgdb_obtain_lock(struct pkgdb *db, pkgdb_lock_t type);
int pkgdb_upgrade_lock(struct pkgdb *db, pkgdb_lock_t old_type, pkgdb_lock_t new_type);


int pkgdb_release_lock(struct pkgdb *db, pkgdb_lock_t type);

/**
 * Close and free the struct pkgdb.
 */
void pkgdb_close(struct pkgdb *db);








>
>







1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
int pkgdb_open_all(struct pkgdb **db, pkgdb_t type, const char *reponame);

/**
 * Locking functions
 */
int pkgdb_obtain_lock(struct pkgdb *db, pkgdb_lock_t type);
int pkgdb_upgrade_lock(struct pkgdb *db, pkgdb_lock_t old_type, pkgdb_lock_t new_type);
int pkgdb_downgrade_lock(struct pkgdb *db, pkgdb_lock_t old_type,
    pkgdb_lock_t new_type);
int pkgdb_release_lock(struct pkgdb *db, pkgdb_lock_t type);

/**
 * Close and free the struct pkgdb.
 */
void pkgdb_close(struct pkgdb *db);

Changes to libpkg/pkgdb.c.

4471
4472
4473
4474
4475
4476
4477





















4478
4479
4480
4481
4482
4483
4484
	assert(db != NULL);

	if (old_type == PKGDB_LOCK_ADVISORY && new_type == PKGDB_LOCK_EXCLUSIVE) {
		pkg_debug(1, "want to upgrade advisory to exclusive lock");
		ret = pkgdb_try_lock(db, advisory_exclusive_lock_sql,
				new_type, true);
	}






















	return (ret);
}

int
pkgdb_release_lock(struct pkgdb *db, pkgdb_lock_t type)
{







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
	assert(db != NULL);

	if (old_type == PKGDB_LOCK_ADVISORY && new_type == PKGDB_LOCK_EXCLUSIVE) {
		pkg_debug(1, "want to upgrade advisory to exclusive lock");
		ret = pkgdb_try_lock(db, advisory_exclusive_lock_sql,
				new_type, true);
	}

	return (ret);
}

int
pkgdb_downgrade_lock(struct pkgdb *db, pkgdb_lock_t old_type,
    pkgdb_lock_t new_type)
{
	const char downgrade_exclusive_lock_sql[] = ""
		"UPDATE pkg_lock SET exclusive=0,advisory=1 WHERE exclusive=1 "
		"AND advisory=1 AND read=0;";
	int ret = EPKG_FATAL;

	assert(db != NULL);

	if (old_type == PKGDB_LOCK_EXCLUSIVE &&
	    new_type == PKGDB_LOCK_ADVISORY) {
		pkg_debug(1, "want to downgrade exclusive to advisory lock");
		ret = pkgdb_try_lock(db, downgrade_exclusive_lock_sql,
		    new_type, true);
	}

	return (ret);
}

int
pkgdb_release_lock(struct pkgdb *db, pkgdb_lock_t type)
{