#define LOGMSG(...) xseg_snprintf(__xseg_errbuf, 4096, FMTARG("%s: ", __func__, ## __VA_ARGS__, "")), \
__xseg_errbuf[4095] = 0, __xseg_log(__xseg_errbuf)
+typedef uint64_t xpointer;
+
+#define None ((xqindex)-1)
+#define Null ((xpointer)-1)
+
+
+#define XPTR_TYPE(ptrtype) \
+ union { \
+ ptrtype *t; \
+ xpointer x; \
+ }
+
+#define XPTRI(xptraddr) \
+ ( (xpointer)(unsigned long)(xptraddr) + \
+ (xptraddr)->x )
+
+#define XPTRISET(xptraddr, ptrval) \
+ ((xptraddr)->x = (xpointer)(ptrval) - \
+ (xpointer)(unsigned long)(xptraddr) )
+
+#define XPTR(xptraddr) \
+ ( (typeof((xptraddr)->t)) \
+ (unsigned long) \
+ ( (xpointer)(unsigned long)(xptraddr) + \
+ (xptraddr)->x ) )
+
+#define XPTRSET(xptraddr, ptrval) \
+ ((xptraddr)->x = (xpointer)(unsigned long)(ptrval) - \
+ (xpointer)(unsigned long)(xptraddr) )
+
#endif
#include <xq/xq.h>
-#ifdef RELATIVE_POINTERS
-#define PTR(p, f) ((typeof((p)->f))((unsigned long)(p) + (unsigned long)(p)->f))
-#define PTRSET(p, f, v) ((p)->f = (void *)((unsigned long)(v) - (unsigned long)(p)))
-#else
-#define PTR(p, f) (p)->f
-#define PTRSET(p, f, v) ((p)->f = (v))
-#endif
-
static inline int __snap(xqindex size)
{
if (!size)
}
void xq_free(struct xq *xq) {
- xq_mfree((void *)PTR(xq, queue));
+ xq_mfree((void *)XPTR(&xq->queue));
memset(xq, 0, sizeof(struct xq));
}
{
xq->head = 1;
xq->tail = 0;
- PTRSET(xq, queue, mem);
+ XPTRSET(&xq->queue, mem);
xq->size = __snap(size);
xq_release(&xq->lock);
}
xqindex t, *qmem = mem;
xq->head = count + 1;
xq->tail = 0;
- PTRSET(xq, queue, qmem);
+ XPTRSET(&xq->queue, qmem);
xq->size = __snap(size);
for (t = 0; t < count; t++)
qmem[t] = mapfn(t);
xqindex t, *qmem = mem;
xq->head = count + 1;
xq->tail = 0;
- PTRSET(xq, queue, qmem);
+ XPTRSET(&xq->queue, qmem);
xq->size = __snap(size);
for (t = 0; t < count; t++)
qmem[t] = t;
xqindex xq_element(struct xq *xq, xqindex index)
{
- return PTR(xq, queue)[index & (xq->size - 1)];
+ return XPTR(&xq->queue)[index & (xq->size - 1)];
}
void xq_print(struct xq *xq)
mask = xq->size -1;
head = __xq_append_head(xq, nr);
for (i = 0; i < nr; i++)
- PTR(xq, queue)[(head + i) & mask] = heads[i];
+ XPTR(&xq->queue)[(head + i) & mask] = heads[i];
out:
xq_release(&xq->lock);
return serial;
serial = None;
goto out;
}
- PTR(xq, queue)[__xq_append_head(xq, 1) & (xq->size -1)] = xqi;
+ XPTR(&xq->queue)[__xq_append_head(xq, 1) & (xq->size -1)] = xqi;
out:
xq_release(&xq->lock);
return serial;
mask = xq->size -1;
head = __xq_pop_head(xq, nr);
for (i = 0; i < nr; i++)
- heads[i] = PTR(xq, queue)[(head - i) & mask];
+ heads[i] = XPTR(&xq->queue)[(head - i) & mask];
out:
xq_release(&xq->lock);
return serial;
(void)xq_acquire(&xq->lock, 1);
if (!xq_count(xq))
goto out;
- value = PTR(xq, queue)[__xq_pop_head(xq, 1) & (xq->size -1)];
+ value = XPTR(&xq->queue)[__xq_pop_head(xq, 1) & (xq->size -1)];
out:
xq_release(&xq->lock);
return value;
mask = xq->size -1;
tail = __xq_append_tail(xq, nr) + nr -1;
for (i = 0; i < nr; i++)
- PTR(xq, queue)[(tail - i) & mask] = tails[i];
+ XPTR(&xq->queue)[(tail - i) & mask] = tails[i];
out:
xq_release(&xq->lock);
return serial;
serial = None;
goto out;
}
- PTR(xq, queue)[__xq_append_tail(xq, 1) & (xq->size -1)] = xqi;
+ XPTR(&xq->queue)[__xq_append_tail(xq, 1) & (xq->size -1)] = xqi;
out:
xq_release(&xq->lock);
return serial;
mask = xq->size -1;
tail = __xq_pop_tail(xq, nr);
for (i = 0; i < nr; i++)
- tails[i] = PTR(xq, queue)[(tail + i) & mask];
+ tails[i] = XPTR(&xq->queue)[(tail + i) & mask];
out:
xq_release(&xq->lock);
return serial;
(void)xq_acquire(&xq->lock, 1);
if (!xq_count(xq))
goto out;
- value = PTR(xq, queue)[__xq_pop_tail(xq, 1) & (xq->size -1)];
+ value = XPTR(&xq->queue)[__xq_pop_tail(xq, 1) & (xq->size -1)];
out:
xq_release(&xq->lock);
return value;
tmask = tailq->size -1;
head = __xq_pop_head(headq, nr);
tail = __xq_append_tail(tailq, nr);
- hq = PTR(headq, queue);
- tq = PTR(tailq, queue);
+ hq = XPTR(&headq->queue);
+ tq = XPTR(&tailq->queue);
for (i = 0; i < nr; i++)
tq[(tail + i) & tmask] = hq[(head + i) & hmask];
return ret;
}
-#undef PTR
-#undef PTRDEF
-
#ifdef __KERNEL__
#include <linux/module.h>
#include <xq/xq_exports.h>