Commit ef146407 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add ObjIterate() wrapper function

parent f5b92e27
......@@ -855,6 +855,9 @@ void *MPL_Get(struct mempool *mpl, unsigned *size);
void MPL_Free(struct mempool *mpl, void *item);
/* cache_obj.c */
typedef int objiterate_f(void *priv, int flush, const void *ptr, ssize_t len);
int ObjIterate(struct worker *, struct objcore *,
void *priv, objiterate_f *func);
enum objiter_status {
OIS_DONE,
OIS_DATA,
......
......@@ -231,6 +231,40 @@ ObjIterEnd(struct objcore *oc, void **oix)
FREE_OBJ(oi);
}
int
ObjIterate(struct worker *wrk, struct objcore *oc,
void *priv, objiterate_f *func)
{
void *oi;
enum objiter_status ois;
void *ptr;
ssize_t len;
oi = ObjIterBegin(wrk, oc);
do {
ois = ObjIter(oc, oi, &ptr, &len);
switch(ois) {
case OIS_DONE:
AZ(len);
break;
case OIS_ERROR:
break;
case OIS_DATA:
if (func(priv, 0, ptr, len))
ois = OIS_ERROR;
break;
case OIS_STREAM:
if (func(priv, 1, ptr, len))
ois = OIS_ERROR;
break;
default:
WRONG("Wrong OIS value");
}
} while (ois == OIS_DATA || ois == OIS_STREAM);
ObjIterEnd(oc, &oi);
return (ois == OIS_DONE ? 0 : -1);
}
/*--------------------------------------------------------------------
*/
......
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