#if !defined (USE_PRIVATE_CACHE) && defined(USE_PTHREAD_PSHARED)
#include <pthread.h>
#endif
-#include <haproxy/list.h>
+#include <haproxy/api-t.h>
+#include <haproxy/thread-t.h>
#ifndef SHSESS_BLOCK_MIN_SIZE
#define SHSESS_BLOCK_MIN_SIZE 128
#else
unsigned int waiters;
#endif
+#else
+ __decl_thread(HA_SPINLOCK_T lock); // used when USE_PRIVATE_CACHE=1
#endif
struct list avail; /* list for active and free blocks */
struct list hot; /* list for locked blocks */
#ifndef __HAPROXY_SHCTX_H
#define __HAPROXY_SHCTX_H
-#include <haproxy/api-t.h>
+#include <haproxy/api.h>
#include <haproxy/list.h>
#include <haproxy/shctx-t.h>
#include <sys/syscall.h>
#endif
#endif
+#else
+#include <haproxy/thread.h>
#endif
int shctx_init(struct shared_context **orig_shctx,
/* Lock functions */
#if defined (USE_PRIVATE_CACHE)
+extern int use_shared_mem;
-#define shctx_lock(shctx)
-#define shctx_unlock(shctx)
+#define shctx_lock(shctx) if (use_shared_mem) HA_SPIN_LOCK(SHCTX_LOCK, &shctx->lock)
+#define shctx_unlock(shctx) if (use_shared_mem) HA_SPIN_UNLOCK(SHCTX_LOCK, &shctx->lock)
#elif defined (USE_PTHREAD_PSHARED)
extern int use_shared_mem;
STK_SESS_LOCK,
APPLETS_LOCK,
PEER_LOCK,
+ SHCTX_LOCK,
SSL_LOCK,
SSL_GEN_CERTS_LOCK,
PATREF_LOCK,
case STK_SESS_LOCK: return "STK_SESS";
case APPLETS_LOCK: return "APPLETS";
case PEER_LOCK: return "PEER";
+ case SHCTX_LOCK: return "SHCTX";
case SSL_LOCK: return "SSL";
case SSL_GEN_CERTS_LOCK: return "SSL_GEN_CERTS";
case PATREF_LOCK: return "PATREF";
#include <haproxy/list.h>
#include <haproxy/shctx.h>
-#if !defined (USE_PRIVATE_CACHE)
-
int use_shared_mem = 0;
-#endif
-
/*
* Reserve a new row if <first> is null, put it in the hotlist, set the refcount to 1
* or append new blocks to the row with <first> as first block if non null.
int i;
struct shared_context *shctx;
int ret;
-#ifndef USE_PRIVATE_CACHE
#ifdef USE_PTHREAD_PSHARED
pthread_mutexattr_t attr;
-#endif
#endif
void *cur;
int maptype = MAP_PRIVATE;
blocksize = (blocksize + sizeof(void *) - 1) & -sizeof(void *);
extra = (extra + sizeof(void *) - 1) & -sizeof(void *);
-#ifndef USE_PRIVATE_CACHE
if (shared)
maptype = MAP_SHARED;
-#endif
shctx = (struct shared_context *)mmap(NULL, sizeof(struct shared_context) + extra + (maxblocks * (sizeof(struct shared_block) + blocksize)),
PROT_READ | PROT_WRITE, maptype | MAP_ANON, -1, 0);
shctx->nbav = 0;
-#ifndef USE_PRIVATE_CACHE
if (maptype == MAP_SHARED) {
+#ifndef USE_PRIVATE_CACHE
#ifdef USE_PTHREAD_PSHARED
if (pthread_mutexattr_init(&attr)) {
munmap(shctx, sizeof(struct shared_context) + extra + (maxblocks * (sizeof(struct shared_block) + blocksize)));
}
#else
shctx->waiters = 0;
+#endif
+#else
+ HA_SPIN_INIT(&shctx->lock);
#endif
use_shared_mem = 1;
}
-#endif
LIST_INIT(&shctx->avail);
LIST_INIT(&shctx->hot);