* This file contains the heritage passed when mgt forks cache
*/
+#include <pthread.h>
#include "queue.h"
struct listen_sock {
/* Storage method */
struct stevedore_head stevedore_h;
+ pthread_mutex_t stevedore_lock;
/* Hash method */
struct hash_slinger *hash;
struct stevedore *stv, *stv_first;
struct stevedore_head *stevedore_h = &heritage.stevedore_h;
- /* Simple round robin selecting of a stevedore.
- */
+ /* Simple round robin selecting of a stevedore. */
+ pthread_mutex_lock(&heritage.stevedore_lock);
stv_first = TAILQ_FIRST(stevedore_h);
stv = stv_first;
do {
st = stv->alloc(stv, size);
TAILQ_REMOVE(stevedore_h, stv, stevedore_list);
TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list);
- if (st != NULL)
+ if (st != NULL) {
+ pthread_mutex_unlock(&heritage.stevedore_lock);
return (st);
+ }
} while ((stv = TAILQ_FIRST(stevedore_h)) != stv_first);
/* No stevedore with enough space is found. Make room in the first
stv = TAILQ_FIRST(stevedore_h);
TAILQ_REMOVE(stevedore_h, stv, stevedore_list);
TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list);
+ pthread_mutex_unlock(&heritage.stevedore_lock);
do {
if ((st = stv->alloc(stv, size)) == NULL)
if (st->open != NULL)
st->open(st);
}
+ pthread_mutex_init(&heritage.stevedore_lock, NULL);
}