Browse Source

Merge branch 'uniscan2' into bfgminer

Luke Dashjr 11 years ago
parent
commit
6393cf96dc
1 changed files with 7 additions and 0 deletions
  1. 7 0
      lowlevel.c

+ 7 - 0
lowlevel.c

@@ -211,11 +211,14 @@ struct _device_claim {
 struct device_drv *bfg_claim_any(struct device_drv * const api, const char *verbose, const char * const devpath)
 struct device_drv *bfg_claim_any(struct device_drv * const api, const char *verbose, const char * const devpath)
 {
 {
 	static struct _device_claim *claims = NULL;
 	static struct _device_claim *claims = NULL;
+	static pthread_mutex_t claims_lock = PTHREAD_MUTEX_INITIALIZER;
 	struct _device_claim *c;
 	struct _device_claim *c;
 	
 	
+	mutex_lock(&claims_lock);
 	HASH_FIND_STR(claims, devpath, c);
 	HASH_FIND_STR(claims, devpath, c);
 	if (c)
 	if (c)
 	{
 	{
+		mutex_unlock(&claims_lock);
 		if (verbose && opt_debug)
 		if (verbose && opt_debug)
 		{
 		{
 			char logbuf[LOGBUFSIZ];
 			char logbuf[LOGBUFSIZ];
@@ -236,12 +239,16 @@ struct device_drv *bfg_claim_any(struct device_drv * const api, const char *verb
 	}
 	}
 	
 	
 	if (!api)
 	if (!api)
+	{
+		mutex_unlock(&claims_lock);
 		return NULL;
 		return NULL;
+	}
 	
 	
 	c = malloc(sizeof(*c));
 	c = malloc(sizeof(*c));
 	c->devpath = strdup(devpath);
 	c->devpath = strdup(devpath);
 	c->drv = api;
 	c->drv = api;
 	HASH_ADD_KEYPTR(hh, claims, c->devpath, strlen(devpath), c);
 	HASH_ADD_KEYPTR(hh, claims, c->devpath, strlen(devpath), c);
+	mutex_unlock(&claims_lock);
 	return NULL;
 	return NULL;
 }
 }