1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data
3 * See the file LICENSE for details.
7 * \file test_shared_ptr.c
8 * \brief test shared pointer
19 #include <yaz/mutex.h>
20 #include <yaz/wrbuf.h>
23 #define YAZ_SHPTR_TYPE(type) \
30 typedef struct type##_shptr *type##_shptr_t;
32 #define YAZ_SHPTR_INIT(p,n) { \
33 p = xmalloc(sizeof(*p)); \
37 yaz_mutex_create(&p->mutex); \
40 #define YAZ_SHPTR_INC(p) { \
41 yaz_mutex_enter(p->mutex); \
43 yaz_mutex_leave(p->mutex); \
46 #define YAZ_SHPTR_DEC(p, destroy) { \
47 yaz_mutex_enter(p->mutex); \
48 if (--p->ref == 0) { \
49 yaz_mutex_leave(p->mutex); \
51 yaz_mutex_destroy(&p->mutex); \
55 yaz_mutex_leave(p->mutex); \
61 static void test(void)
63 WRBUF w = wrbuf_alloc();
73 YAZ_SHPTR_DEC(t, wrbuf_destroy);
76 YAZ_SHPTR_DEC(t, wrbuf_destroy);
80 int main (int argc, char **argv)
82 YAZ_CHECK_INIT(argc, argv);
91 * c-file-style: "Stroustrup"
92 * indent-tabs-mode: nil
94 * vim: shiftwidth=4 tabstop=8 expandtab