Commit 7259fab6 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Lock the VSM alloc/free cals in the child process

parent 958114da
......@@ -803,6 +803,9 @@ void SES_Charge(struct sess *sp);
/* cache_shmlog.c */
void VSL_Init(void);
void *VSM_Alloc(unsigned size, const char *class, const char *type,
const char *ident);
void VSM_Free(const void *ptr);
#ifdef VSL_ENDMARKER
void VSL(enum vsl_tag tag, int id, const char *fmt, ...);
void WSLR(struct worker *w, enum vsl_tag tag, int id, txt t);
......
......@@ -104,7 +104,7 @@ child_main(void)
VSL_Init(); /* First, LCK needs it. */
LCK_Init(); /* Locking, must be first */
LCK_Init(); /* Second, locking */
PAN_Init();
CLI_Init();
......
......@@ -40,7 +40,9 @@ SVNID("$Id$")
#include "vmb.h"
#include "vsm.h"
/* These cannot be struct lock, which depends on vsm/vsl working */
static pthread_mutex_t vsl_mtx;
static pthread_mutex_t vsm_mtx;
static uint32_t *vsl_start;
static const uint32_t *vsl_end;
......@@ -275,8 +277,9 @@ VSL_Init(void)
struct vsm_chunk *vsc;
AZ(pthread_mutex_init(&vsl_mtx, NULL));
AZ(pthread_mutex_init(&vsm_mtx, NULL));
VSM_Clean();
VSM__Clean();
VSM_ITER(vsc)
if (!strcmp(vsc->class, VSL_CLASS))
......@@ -292,3 +295,26 @@ VSL_Init(void)
memset(VSC_main, 0, sizeof *VSC_main);
vsm_head->child_pid = getpid();
}
/*--------------------------------------------------------------------*/
void *
VSM_Alloc(unsigned size, const char *class, const char *type,
const char *ident)
{
void *p;
AZ(pthread_mutex_lock(&vsm_mtx));
p = VSM__Alloc(size, class, type, ident);
AZ(pthread_mutex_unlock(&vsm_mtx));
return (p);
}
void
VSM_Free(const void *ptr)
{
AZ(pthread_mutex_lock(&vsm_mtx));
VSM__Free(ptr);
AZ(pthread_mutex_unlock(&vsm_mtx));
}
......@@ -73,10 +73,14 @@ const void *pick(const struct choice *cp, const char *which, const char *kind);
extern struct vsm_head *vsm_head;
extern const struct vsm_chunk *vsm_end;
void *VSM_Alloc(unsigned size, const char *class, const char *type,
/*
* These three should not be called directly, but only through
* proper vectors in mgt.h/cache.h, hence the __
*/
void *VSM__Alloc(unsigned size, const char *class, const char *type,
const char *ident);
void VSM_Free(const void *ptr);
void VSM_Clean(void);
void VSM__Free(const void *ptr);
void VSM__Clean(void);
/* These classes are opaque to other programs, so we define the here */
#define VSM_CLASS_FREE "Free"
......
......@@ -99,3 +99,8 @@ extern unsigned mgt_vcc_err_unref;
fprintf(stderr, fmt "\n", __VA_ARGS__); \
syslog(pri, fmt, __VA_ARGS__); \
} while (0)
#define VSM_Alloc(a, b, c, d) VSM__Alloc(a,b,c,d)
#define VSM_Free(a) VSM__Free(a)
#define VSM_Clean() VSM__Clean()
......@@ -60,6 +60,7 @@ SVNID("$Id$")
#include "vsm.h"
#include "vmb.h"
/* These two come from beyond (mgt_shmem.c actually) */
struct vsm_head *vsm_head;
const struct vsm_chunk *vsm_end;
......@@ -146,7 +147,7 @@ vsm_cleanup(void)
/*--------------------------------------------------------------------*/
void *
VSM_Alloc(unsigned size, const char *class, const char *type, const char *ident)
VSM__Alloc(unsigned size, const char *class, const char *type, const char *ident)
{
struct vsm_chunk *sha, *sha2;
unsigned seq;
......@@ -195,7 +196,7 @@ VSM_Alloc(unsigned size, const char *class, const char *type, const char *ident)
/*--------------------------------------------------------------------*/
void
VSM_Free(const void *ptr)
VSM__Free(const void *ptr)
{
struct vsm_chunk *sha;
unsigned seq;
......@@ -216,7 +217,7 @@ VSM_Free(const void *ptr)
*/
void
VSM_Clean(void)
VSM__Clean(void)
{
struct vsm_chunk *sha;
unsigned f, seq;
......@@ -233,7 +234,7 @@ VSM_Clean(void)
continue;
if (strcmp(sha->class, VSM_CLASS_FREE) &&
strcmp(sha->class, VSM_CLASS_COOL))
VSM_Free(VSM_PTR(sha));
VSM__Free(VSM_PTR(sha));
}
vsm_release(seq);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment