hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (C) 2014 Philippe Gerum <rpm@xenomai.org>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
#ifndef _COPPERPLATE_REGISTRY_OBSTACK_H
#define _COPPERPLATE_REGISTRY_OBSTACK_H
 
#include <copperplate/registry.h>
 
#ifdef CONFIG_XENO_REGISTRY
 
#include <stdlib.h>
#include <boilerplate/obstack.h>
#include <copperplate/heapobj.h>
 
struct threadobj;
struct syncobj;
 
/*
 * Obstacks are grown from handlers called by the fusefs server
 * thread, which has no real-time requirement: malloc/free is fine for
 * memory management.
 */
#define obstack_chunk_alloc    malloc
#define obstack_chunk_free    free
 
struct threadobj;
 
struct fsobstack {
   struct obstack obstack;
   void *data;
   size_t len;
};
 
struct fsobstack_syncops {
   int (*prepare_cache)(struct fsobstack *o,
                struct obstack *cache, int item_count);
   size_t (*collect_data)(void *p, struct threadobj *thobj);
   size_t (*format_data)(struct fsobstack *o, void *p);
};
 
struct syncobj;
 
#ifdef __cplusplus
extern "C" {
#endif
 
void fsobstack_grow_string(struct fsobstack *o,
              const char *s);
 
void fsobstack_grow_char(struct fsobstack *o,
            char c);
 
int fsobstack_grow_format(struct fsobstack *o,
             const char *fmt, ...);
 
int fsobstack_grow_file(struct fsobstack *o,
           const char *path);
 
int fsobstack_grow_syncobj_grant(struct fsobstack *o,
                struct syncobj *sobj,
                struct fsobstack_syncops *ops);
 
int fsobstack_grow_syncobj_drain(struct fsobstack *o,
                struct syncobj *sobj,
                struct fsobstack_syncops *ops);
 
ssize_t fsobstack_pull(struct fsobstack *o,
              char *buf, size_t size);
 
ssize_t fsobj_obstack_read(struct fsobj *fsobj,
              char *buf, size_t size, off_t offset,
              void *priv);
 
int fsobj_obstack_release(struct fsobj *fsobj, void *priv);
 
#ifdef __cplusplus
}
#endif
 
static inline void fsobstack_init(struct fsobstack *o)
{
   obstack_init(&o->obstack);
   o->data = NULL;
   o->len = 0;
}
 
static inline void fsobstack_destroy(struct fsobstack *o)
{
   obstack_free(&o->obstack, NULL);
}
 
static inline void fsobstack_finish(struct fsobstack *o)
{
   o->len = obstack_object_size(&o->obstack);
   o->data = obstack_finish(&o->obstack);
}
 
static inline
void registry_init_file_obstack(struct fsobj *fsobj, 
               const struct registry_operations *ops)
{
   registry_init_file(fsobj, ops, sizeof(struct fsobstack));
}
 
#else /* !CONFIG_XENO_REGISTRY */
 
static inline
void registry_init_file_obstack(struct fsobj *fsobj, 
               const struct registry_operations *ops)
{ }
 
#endif /* !CONFIG_XENO_REGISTRY */
 
#endif /* !_COPPERPLATE_REGISTRY_OBSTACK_H */