#include <string.h>
#include <inttypes.h>
-#ifndef NDEBUG
-# include <signal.h>
-#endif
-
#include "libmemcachedprotocol/common.h"
-#ifndef NDEBUG
+#ifndef HAVE_UMEM_H
+
+# ifdef _MSC_VER
+typedef SECURITY_ATTRIBUTES pthread_mutexattr_t;
+
+static inline int pthread_mutex_init(pthread_mutex_t *m, pthread_mutexattr_t *a) {
+ *m = CreateMutexA(a, FALSE, NULL);
+ return !*m;
+}
+static inline int pthread_mutex_destroy(pthread_mutex_t *m) {
+ return !CloseHandle(*m);
+}
+static inline int pthread_mutex_lock(pthread_mutex_t *m) {
+ if (WaitForSingleObject(*m, INFINITE)) {
+ return 0;
+ }
+ return GetLastError();
+}
+static inline int pthread_mutex_unlock(pthread_mutex_t *m) {
+ return !ReleaseMutex(*m);
+}
+# endif
+
+# ifndef NDEBUG
+# include <signal.h>
+
const uint64_t redzone_pattern = 0xdeadbeefcafebabe;
int cache_error = 0;
-#endif
+
+# endif
const size_t initial_pool_size = 64;
ret->constructor = constructor;
ret->destructor = destructor;
-#ifndef NDEBUG
+# ifndef NDEBUG
ret->bufsize = bufsize + 2 * sizeof(redzone_pattern);
-#else
+# else
ret->bufsize = bufsize;
-#endif
+# endif
(void) align;
}
static inline void *get_object(void *ptr) {
-#ifndef NDEBUG
+# ifndef NDEBUG
uint64_t *pre = ptr;
return pre + 1;
-#else
+# else
return ptr;
-#endif
+# endif
}
void cache_destroy(cache_t *cache) {
}
pthread_mutex_unlock(&cache->mutex);
-#ifndef NDEBUG
+# ifndef NDEBUG
if (object) {
/* add a simple form of buffer-check */
uint64_t *pre = ret;
memcpy(((char *) ret) + cache->bufsize - (2 * sizeof(redzone_pattern)), &redzone_pattern,
sizeof(redzone_pattern));
}
-#endif
+# endif
return object;
}
void cache_free(cache_t *cache, void *ptr) {
pthread_mutex_lock(&cache->mutex);
-#ifndef NDEBUG
+# ifndef NDEBUG
/* validate redzone... */
if (memcmp(((char *) ptr) + cache->bufsize - (2 * sizeof(redzone_pattern)), &redzone_pattern,
sizeof(redzone_pattern))
return;
}
ptr = pre;
-#endif
+# endif
if (cache->freecurr < cache->freetotal) {
cache->ptr[cache->freecurr++] = ptr;
} else {
}
pthread_mutex_unlock(&cache->mutex);
}
+
+#endif // HAVE_UMEM_H