summaryrefslogtreecommitdiff
path: root/openpcd/firmware/src/req_ctx.c
diff options
context:
space:
mode:
Diffstat (limited to 'openpcd/firmware/src/req_ctx.c')
-rw-r--r--openpcd/firmware/src/req_ctx.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/openpcd/firmware/src/req_ctx.c b/openpcd/firmware/src/req_ctx.c
index c0731fe..984f6b9 100644
--- a/openpcd/firmware/src/req_ctx.c
+++ b/openpcd/firmware/src/req_ctx.c
@@ -8,26 +8,21 @@
/* FIXME: locking, FIFO order processing */
-static struct req_ctx req_ctx[8];
-static unsigned long req_ctx_busy; /* bitmask of used request contexts */
+static struct req_ctx req_ctx[NUM_REQ_CTX];
-struct req_ctx *req_ctx_find_get(void)
+struct req_ctx *req_ctx_find_get(unsigned long old_state, unsigned long new_state)
{
+ unsigned long flags;
u_int8_t i;
- for (i = 0; i < NUM_REQ_CTX; i++) {
- if (test_and_set_bit(i, &req_ctx_busy) == 1)
- return &req_ctx[i];
- }
- return NULL;
-}
-
-struct req_ctx *req_ctx_find_busy(void)
-{
- u_int8_t i;
for (i = 0; i < NUM_REQ_CTX; i++) {
- if (test_bit(i, &req_ctx_busy))
+ local_irq_save(flags);
+ if (req_ctx[i].state == old_state) {
+ req_ctx[i].state = new_state;
+ local_irq_restore(flags);
return &req_ctx[i];
+ }
+ local_irq_restore(flags);
}
return NULL;
@@ -38,12 +33,17 @@ u_int8_t req_ctx_num(struct req_ctx *ctx)
return ((void *)ctx - (void *)&req_ctx[0])/sizeof(*ctx);
}
-void req_ctx_put(struct req_ctx *ctx)
+void req_ctx_set_state(struct req_ctx *ctx, unsigned long new_state)
{
- int offset = req_ctx_num(ctx);
- if (offset > NUM_REQ_CTX)
- DEBUGPCR("Error in offset calculation req_ctx_put");
+ unsigned long flags;
+
+ /* FIXME: do we need this kind of locking, we're UP! */
+ local_irq_save(flags);
+ ctx->state = new_state;
+ local_irq_restore(flags);
+}
- clear_bit(offset, &req_ctx_busy);
- //req_ctx_busy &= ~(1 << offset);
+void req_ctx_put(struct req_ctx *ctx)
+{
+ req_ctx_set_state(ctx, RCTX_STATE_FREE);
}
personal git repositories of Harald Welte. Your mileage may vary