mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
@@ -27,6 +27,7 @@
|
|||||||
#include "coverage.h"
|
#include "coverage.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "hmap.h"
|
#include "hmap.h"
|
||||||
|
#include "ovs-thread.h"
|
||||||
#include "timeval.h"
|
#include "timeval.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "vlog.h"
|
#include "vlog.h"
|
||||||
@@ -54,6 +55,9 @@ struct lockfile {
|
|||||||
* once. */
|
* once. */
|
||||||
static struct hmap lock_table = HMAP_INITIALIZER(&lock_table);
|
static struct hmap lock_table = HMAP_INITIALIZER(&lock_table);
|
||||||
|
|
||||||
|
/* Protects 'lock_table'. */
|
||||||
|
static pthread_mutex_t lock_table_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static void lockfile_unhash(struct lockfile *);
|
static void lockfile_unhash(struct lockfile *);
|
||||||
static int lockfile_try_lock(const char *name, pid_t *pidp,
|
static int lockfile_try_lock(const char *name, pid_t *pidp,
|
||||||
struct lockfile **lockfilep);
|
struct lockfile **lockfilep);
|
||||||
@@ -106,7 +110,9 @@ lockfile_lock(const char *file, struct lockfile **lockfilep)
|
|||||||
|
|
||||||
lock_name = lockfile_name(file);
|
lock_name = lockfile_name(file);
|
||||||
|
|
||||||
|
xpthread_mutex_lock(&lock_table_mutex);
|
||||||
error = lockfile_try_lock(lock_name, &pid, lockfilep);
|
error = lockfile_try_lock(lock_name, &pid, lockfilep);
|
||||||
|
xpthread_mutex_unlock(&lock_table_mutex);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
COVERAGE_INC(lockfile_error);
|
COVERAGE_INC(lockfile_error);
|
||||||
@@ -132,8 +138,11 @@ void
|
|||||||
lockfile_unlock(struct lockfile *lockfile)
|
lockfile_unlock(struct lockfile *lockfile)
|
||||||
{
|
{
|
||||||
if (lockfile) {
|
if (lockfile) {
|
||||||
COVERAGE_INC(lockfile_unlock);
|
xpthread_mutex_lock(&lock_table_mutex);
|
||||||
lockfile_unhash(lockfile);
|
lockfile_unhash(lockfile);
|
||||||
|
xpthread_mutex_unlock(&lock_table_mutex);
|
||||||
|
|
||||||
|
COVERAGE_INC(lockfile_unlock);
|
||||||
free(lockfile->name);
|
free(lockfile->name);
|
||||||
free(lockfile);
|
free(lockfile);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user