|
@@ -40,13 +40,12 @@ static int int_comparator (void *user, int *prio1, int *prio2)
|
|
|
|
|
|
|
|
static void schedule (PacketPassPriorityQueue *m)
|
|
static void schedule (PacketPassPriorityQueue *m)
|
|
|
{
|
|
{
|
|
|
- ASSERT(!m->freeing)
|
|
|
|
|
ASSERT(!m->sending_flow)
|
|
ASSERT(!m->sending_flow)
|
|
|
|
|
+ ASSERT(!m->freeing)
|
|
|
ASSERT(BHeap_GetFirst(&m->queued_heap))
|
|
ASSERT(BHeap_GetFirst(&m->queued_heap))
|
|
|
|
|
|
|
|
// get first queued flow
|
|
// get first queued flow
|
|
|
- BHeapNode *heap_node = BHeap_GetFirst(&m->queued_heap);
|
|
|
|
|
- PacketPassPriorityQueueFlow *qflow = UPPER_OBJECT(heap_node, PacketPassPriorityQueueFlow, queued.heap_node);
|
|
|
|
|
|
|
+ PacketPassPriorityQueueFlow *qflow = UPPER_OBJECT(BHeap_GetFirst(&m->queued_heap), PacketPassPriorityQueueFlow, queued.heap_node);
|
|
|
ASSERT(qflow->is_queued)
|
|
ASSERT(qflow->is_queued)
|
|
|
|
|
|
|
|
// remove flow from queue
|
|
// remove flow from queue
|
|
@@ -56,13 +55,12 @@ static void schedule (PacketPassPriorityQueue *m)
|
|
|
// schedule send
|
|
// schedule send
|
|
|
PacketPassInterface_Sender_Send(m->output, qflow->queued.data, qflow->queued.data_len);
|
|
PacketPassInterface_Sender_Send(m->output, qflow->queued.data, qflow->queued.data_len);
|
|
|
m->sending_flow = qflow;
|
|
m->sending_flow = qflow;
|
|
|
- m->sending_len = qflow->queued.data_len;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void schedule_job_handler (PacketPassPriorityQueue *m)
|
|
static void schedule_job_handler (PacketPassPriorityQueue *m)
|
|
|
{
|
|
{
|
|
|
- ASSERT(!m->freeing)
|
|
|
|
|
ASSERT(!m->sending_flow)
|
|
ASSERT(!m->sending_flow)
|
|
|
|
|
+ ASSERT(!m->freeing)
|
|
|
DebugObject_Access(&m->d_obj);
|
|
DebugObject_Access(&m->d_obj);
|
|
|
|
|
|
|
|
if (BHeap_GetFirst(&m->queued_heap)) {
|
|
if (BHeap_GetFirst(&m->queued_heap)) {
|
|
@@ -72,13 +70,13 @@ static void schedule_job_handler (PacketPassPriorityQueue *m)
|
|
|
|
|
|
|
|
static void input_handler_send (PacketPassPriorityQueueFlow *flow, uint8_t *data, int data_len)
|
|
static void input_handler_send (PacketPassPriorityQueueFlow *flow, uint8_t *data, int data_len)
|
|
|
{
|
|
{
|
|
|
- ASSERT(!flow->m->freeing)
|
|
|
|
|
- ASSERT(flow != flow->m->sending_flow)
|
|
|
|
|
|
|
+ PacketPassPriorityQueue *m = flow->m;
|
|
|
|
|
+
|
|
|
|
|
+ ASSERT(flow != m->sending_flow)
|
|
|
ASSERT(!flow->is_queued)
|
|
ASSERT(!flow->is_queued)
|
|
|
|
|
+ ASSERT(!m->freeing)
|
|
|
DebugObject_Access(&flow->d_obj);
|
|
DebugObject_Access(&flow->d_obj);
|
|
|
|
|
|
|
|
- PacketPassPriorityQueue *m = flow->m;
|
|
|
|
|
-
|
|
|
|
|
// queue flow
|
|
// queue flow
|
|
|
flow->queued.data = data;
|
|
flow->queued.data = data;
|
|
|
flow->queued.data_len = data_len;
|
|
flow->queued.data_len = data_len;
|
|
@@ -92,10 +90,10 @@ static void input_handler_send (PacketPassPriorityQueueFlow *flow, uint8_t *data
|
|
|
|
|
|
|
|
static void output_handler_done (PacketPassPriorityQueue *m)
|
|
static void output_handler_done (PacketPassPriorityQueue *m)
|
|
|
{
|
|
{
|
|
|
- ASSERT(!m->freeing)
|
|
|
|
|
ASSERT(m->sending_flow)
|
|
ASSERT(m->sending_flow)
|
|
|
- ASSERT(!m->sending_flow->is_queued)
|
|
|
|
|
ASSERT(!BPending_IsSet(&m->schedule_job))
|
|
ASSERT(!BPending_IsSet(&m->schedule_job))
|
|
|
|
|
+ ASSERT(!m->freeing)
|
|
|
|
|
+ ASSERT(!m->sending_flow->is_queued)
|
|
|
|
|
|
|
|
PacketPassPriorityQueueFlow *flow = m->sending_flow;
|
|
PacketPassPriorityQueueFlow *flow = m->sending_flow;
|
|
|
|
|
|
|
@@ -123,13 +121,12 @@ static void output_handler_done (PacketPassPriorityQueue *m)
|
|
|
void PacketPassPriorityQueue_Init (PacketPassPriorityQueue *m, PacketPassInterface *output, BPendingGroup *pg, int use_cancel)
|
|
void PacketPassPriorityQueue_Init (PacketPassPriorityQueue *m, PacketPassInterface *output, BPendingGroup *pg, int use_cancel)
|
|
|
{
|
|
{
|
|
|
ASSERT(use_cancel == 0 || use_cancel == 1)
|
|
ASSERT(use_cancel == 0 || use_cancel == 1)
|
|
|
- if (use_cancel) {
|
|
|
|
|
- ASSERT(PacketPassInterface_HasCancel(output))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ASSERT(!use_cancel || PacketPassInterface_HasCancel(output))
|
|
|
|
|
|
|
|
// init arguments
|
|
// init arguments
|
|
|
m->output = output;
|
|
m->output = output;
|
|
|
m->pg = pg;
|
|
m->pg = pg;
|
|
|
|
|
+ m->use_cancel = use_cancel;
|
|
|
|
|
|
|
|
// init output
|
|
// init output
|
|
|
PacketPassInterface_Sender_Init(m->output, (PacketPassInterface_handler_done)output_handler_done, m);
|
|
PacketPassInterface_Sender_Init(m->output, (PacketPassInterface_handler_done)output_handler_done, m);
|
|
@@ -143,14 +140,11 @@ void PacketPassPriorityQueue_Init (PacketPassPriorityQueue *m, PacketPassInterfa
|
|
|
// not freeing
|
|
// not freeing
|
|
|
m->freeing = 0;
|
|
m->freeing = 0;
|
|
|
|
|
|
|
|
- // set if using cancel
|
|
|
|
|
- m->use_cancel = use_cancel;
|
|
|
|
|
-
|
|
|
|
|
// init schedule job
|
|
// init schedule job
|
|
|
BPending_Init(&m->schedule_job, m->pg, (BPending_handler)schedule_job_handler, m);
|
|
BPending_Init(&m->schedule_job, m->pg, (BPending_handler)schedule_job_handler, m);
|
|
|
|
|
|
|
|
- DebugCounter_Init(&m->d_ctr);
|
|
|
|
|
DebugObject_Init(&m->d_obj);
|
|
DebugObject_Init(&m->d_obj);
|
|
|
|
|
+ DebugCounter_Init(&m->d_ctr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void PacketPassPriorityQueue_Free (PacketPassPriorityQueue *m)
|
|
void PacketPassPriorityQueue_Free (PacketPassPriorityQueue *m)
|
|
@@ -168,6 +162,7 @@ void PacketPassPriorityQueue_PrepareFree (PacketPassPriorityQueue *m)
|
|
|
{
|
|
{
|
|
|
DebugObject_Access(&m->d_obj);
|
|
DebugObject_Access(&m->d_obj);
|
|
|
|
|
|
|
|
|
|
+ // set freeing
|
|
|
m->freeing = 1;
|
|
m->freeing = 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -189,20 +184,18 @@ void PacketPassPriorityQueueFlow_Init (PacketPassPriorityQueueFlow *flow, Packet
|
|
|
// is not queued
|
|
// is not queued
|
|
|
flow->is_queued = 0;
|
|
flow->is_queued = 0;
|
|
|
|
|
|
|
|
- DebugCounter_Increment(&m->d_ctr);
|
|
|
|
|
DebugObject_Init(&flow->d_obj);
|
|
DebugObject_Init(&flow->d_obj);
|
|
|
|
|
+ DebugCounter_Increment(&m->d_ctr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void PacketPassPriorityQueueFlow_Free (PacketPassPriorityQueueFlow *flow)
|
|
void PacketPassPriorityQueueFlow_Free (PacketPassPriorityQueueFlow *flow)
|
|
|
{
|
|
{
|
|
|
- if (!flow->m->freeing) {
|
|
|
|
|
- ASSERT(flow != flow->m->sending_flow)
|
|
|
|
|
- }
|
|
|
|
|
- DebugCounter_Decrement(&flow->m->d_ctr);
|
|
|
|
|
- DebugObject_Free(&flow->d_obj);
|
|
|
|
|
-
|
|
|
|
|
PacketPassPriorityQueue *m = flow->m;
|
|
PacketPassPriorityQueue *m = flow->m;
|
|
|
|
|
|
|
|
|
|
+ ASSERT(m->freeing || flow != m->sending_flow)
|
|
|
|
|
+ DebugCounter_Decrement(&m->d_ctr);
|
|
|
|
|
+ DebugObject_Free(&flow->d_obj);
|
|
|
|
|
+
|
|
|
// remove from current flow
|
|
// remove from current flow
|
|
|
if (flow == m->sending_flow) {
|
|
if (flow == m->sending_flow) {
|
|
|
m->sending_flow = NULL;
|
|
m->sending_flow = NULL;
|
|
@@ -219,46 +212,51 @@ void PacketPassPriorityQueueFlow_Free (PacketPassPriorityQueueFlow *flow)
|
|
|
|
|
|
|
|
void PacketPassPriorityQueueFlow_AssertFree (PacketPassPriorityQueueFlow *flow)
|
|
void PacketPassPriorityQueueFlow_AssertFree (PacketPassPriorityQueueFlow *flow)
|
|
|
{
|
|
{
|
|
|
- if (!flow->m->freeing) {
|
|
|
|
|
- ASSERT(flow != flow->m->sending_flow)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ PacketPassPriorityQueue *m = flow->m;
|
|
|
|
|
+
|
|
|
|
|
+ ASSERT(m->freeing || flow != m->sending_flow)
|
|
|
DebugObject_Access(&flow->d_obj);
|
|
DebugObject_Access(&flow->d_obj);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int PacketPassPriorityQueueFlow_IsBusy (PacketPassPriorityQueueFlow *flow)
|
|
int PacketPassPriorityQueueFlow_IsBusy (PacketPassPriorityQueueFlow *flow)
|
|
|
{
|
|
{
|
|
|
- ASSERT(!flow->m->freeing)
|
|
|
|
|
|
|
+ PacketPassPriorityQueue *m = flow->m;
|
|
|
|
|
+
|
|
|
|
|
+ ASSERT(!m->freeing)
|
|
|
DebugObject_Access(&flow->d_obj);
|
|
DebugObject_Access(&flow->d_obj);
|
|
|
|
|
|
|
|
- return (flow == flow->m->sending_flow);
|
|
|
|
|
|
|
+ return (flow == m->sending_flow);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void PacketPassPriorityQueueFlow_Release (PacketPassPriorityQueueFlow *flow)
|
|
void PacketPassPriorityQueueFlow_Release (PacketPassPriorityQueueFlow *flow)
|
|
|
{
|
|
{
|
|
|
- ASSERT(flow->m->use_cancel)
|
|
|
|
|
- ASSERT(flow == flow->m->sending_flow)
|
|
|
|
|
- ASSERT(!flow->m->freeing)
|
|
|
|
|
- ASSERT(!BPending_IsSet(&flow->m->schedule_job))
|
|
|
|
|
- DebugObject_Access(&flow->d_obj);
|
|
|
|
|
-
|
|
|
|
|
PacketPassPriorityQueue *m = flow->m;
|
|
PacketPassPriorityQueue *m = flow->m;
|
|
|
|
|
|
|
|
- // cancel current packet
|
|
|
|
|
- PacketPassInterface_Sender_Cancel(m->output);
|
|
|
|
|
|
|
+ ASSERT(flow == m->sending_flow)
|
|
|
|
|
+ ASSERT(m->use_cancel)
|
|
|
|
|
+ ASSERT(!m->freeing)
|
|
|
|
|
+ ASSERT(!BPending_IsSet(&m->schedule_job))
|
|
|
|
|
+ DebugObject_Access(&flow->d_obj);
|
|
|
|
|
|
|
|
// set no sending flow
|
|
// set no sending flow
|
|
|
m->sending_flow = NULL;
|
|
m->sending_flow = NULL;
|
|
|
|
|
|
|
|
// schedule schedule
|
|
// schedule schedule
|
|
|
BPending_Set(&m->schedule_job);
|
|
BPending_Set(&m->schedule_job);
|
|
|
|
|
+
|
|
|
|
|
+ // cancel current packet
|
|
|
|
|
+ PacketPassInterface_Sender_Cancel(m->output);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void PacketPassPriorityQueueFlow_SetBusyHandler (PacketPassPriorityQueueFlow *flow, PacketPassPriorityQueue_handler_busy handler, void *user)
|
|
void PacketPassPriorityQueueFlow_SetBusyHandler (PacketPassPriorityQueueFlow *flow, PacketPassPriorityQueue_handler_busy handler, void *user)
|
|
|
{
|
|
{
|
|
|
- ASSERT(flow == flow->m->sending_flow)
|
|
|
|
|
- ASSERT(!flow->m->freeing)
|
|
|
|
|
|
|
+ PacketPassPriorityQueue *m = flow->m;
|
|
|
|
|
+
|
|
|
|
|
+ ASSERT(flow == m->sending_flow)
|
|
|
|
|
+ ASSERT(!m->freeing)
|
|
|
DebugObject_Access(&flow->d_obj);
|
|
DebugObject_Access(&flow->d_obj);
|
|
|
|
|
|
|
|
|
|
+ // set handler
|
|
|
flow->handler_busy = handler;
|
|
flow->handler_busy = handler;
|
|
|
flow->user = user;
|
|
flow->user = user;
|
|
|
}
|
|
}
|