Skip to content

Commit

Permalink
[nes]: LIB + SYSTEM + LAG + LACP changes ...
Browse files Browse the repository at this point in the history
  • Loading branch information
nes-repo committed Apr 13, 2015
1 parent ee6173e commit e4e2b05
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 99 deletions.
2 changes: 2 additions & 0 deletions lag/lagUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "lag/lacp/lacpUtils.h"
#include "if/ifUtils.h"

#include "lib/bitmap.h"

#include <stdbool.h>
#include <stdint.h>

Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ include ${MK_COMMON}
CFLAGS +=

SNMP_SRC :=
MODULE_SRC := ieee802.c number.c bitmap.c binaryTree.c list.c buffer.c sync.c thread.c freeRange.c ${SNMP_SRC}
MODULE_SRC := ieee802.c number.c bitmap.c binaryTree.c list.c buffer.c message.c thread.c freeRange.c ${SNMP_SRC}

$(call MODULE_DEP,${MODULE_SRC},${CFLAGS},${INCLUDES})

Expand Down
88 changes: 63 additions & 25 deletions lib/sync.c → lib/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@
*/
//set ts=4 sw=4

#ifndef __SYNC_C__
# define __SYNC_C__
#ifndef __MESSAGE_C__
# define __MESSAGE_C__



#include "sync.h"
#include "message.h"
#include "lib/lib.h"
#include "lib/list.h"
#include "lib/bitmap.h"
#include "lib/binaryTree.h"
#include "lib/buffer.h"
#include "lib/sync.h"
#include "lib/thread.h"

#include <stdbool.h>
#include <stdint.h>
#include <pthread.h>

#define MOD_NAME "SYNC"
#define PTHREAD_OK 0
#define MOD_NAME "MESSAGE"

#if 0
#include "lib/log.h"

#define Sync_log(_pri, _frmt, _args ...) xLog_str (MOD_NAME, _pri, _frmt, ## _args)
#define Message_log(_pri, _frmt, _args ...) xLog_str (MOD_NAME, _pri, _frmt, ## _args)
#else
#define Sync_log(_pri, _frmt, _args ...)
#define Message_log(_pri, _frmt, _args ...)
#endif

typedef struct xMessageData_t
Expand Down Expand Up @@ -73,7 +72,7 @@ static xMessageData_t oMessageData =
.oLock = xRwLock_initInline (),
};
static xMessageQueue_t *
xMessageQueue_getByIndex (uint32_t u32Index);
xMessageQueue_getByIndex (uint32_t u32Index);


int8_t
Expand All @@ -93,7 +92,7 @@ xMessageQueue_t *
xMessageQueue_create (
uint32_t u32Index)
{
xMessageQueue_t *poEntry = NULL;
register xMessageQueue_t *poEntry = NULL;

if ((poEntry = xBuffer_cAlloc (sizeof (xMessageQueue_t))) == NULL)
{
Expand All @@ -108,6 +107,7 @@ xMessageQueue_create (
xBuffer_free (poEntry);
return NULL;
}

xSList_headInit (&poEntry->oTxList);
xSList_headInit (&poEntry->oRxList);
xSList_headInit (&poEntry->oAckList);
Expand Down Expand Up @@ -163,7 +163,7 @@ xMessage_t *
xMessage_allocate (
uint16_t u32Type, void *pvData)
{
xMessageSrc_t *poEntry = NULL;
register xMessageSrc_t *poEntry = NULL;

if ((poEntry = xBuffer_cAlloc (sizeof (xMessageSrc_t))) == NULL)
{
Expand Down Expand Up @@ -211,9 +211,9 @@ xMessage_send (
xSList_push (&poMsgDst->oMsg.oQNode, &poQueueDst->oRxList);
xRwLock_unlock (&poQueueDst->oLock);

xBitmap_setBit (poThread->ubFlags, xThreadInfo_flagsMessage_c, true);
xMLock_unlock (&poThread->oLock);
xBitmap_setBit (poThread->au8Flags, xThreadInfo_flagsMessage_c, true);
xCond_broadcast (&poThread->oSignal);
xMLock_unlock (&poThread->oLock);

bMsgAdded = true;
}
Expand All @@ -228,11 +228,26 @@ xMessage_send (
return true;
}

xMessage_t *
xMessageAck_getMessage (
xMessageQueue_t *poQueueSrc)
{
register xSList_Node_t *poMsgNode = NULL;
register xMessage_t *poMsg = NULL;

if ((poMsgNode = xSList_nodeGetTail (&poQueueSrc->oAckList)) != NULL)
{
poMsg = xSList_entry (poMsgNode, xMessage_t, oQNode);
}

return poMsg;
}

bool
xMessage_free (
xMessageAck_remove (
xMessage_t *poMessage, xMessageQueue_t *poQueueSrc)
{
xMessageSrc_t *poMsgSrc = xGetParentByMemberPtr (poMessage, xMessageSrc_t, oMsg);
register xMessageSrc_t *poMsgSrc = xGetParentByMemberPtr (poMessage, xMessageSrc_t, oMsg);

xRwLock_wrLock (&poQueueSrc->oLock);
xSList_nodeRem (&poMsgSrc->oMsg.oQNode, &poQueueSrc->oAckList);
Expand All @@ -242,12 +257,20 @@ xMessage_free (
return true;
}

bool
xMessage_cleanupThread (
xMessageQueue_t *poSrcQueue, xThreadInfo_t *pThread)
{
xBitmap_setBit (pThread->au8Flags, xThreadInfo_flagsMessage_c, 0);
return true;
}


xMessage_t *
xMessageDst_create (
uint32_t u32Index, xMessage_t *poMessage)
{
xMessageDst_t *poEntry = NULL;
register xMessageDst_t *poEntry = NULL;

if ((poEntry = xBuffer_cAlloc (sizeof (xMessageDst_t))) == NULL)
{
Expand All @@ -267,12 +290,27 @@ xMessageDst_create (
return &poEntry->oMsg;
}

xMessage_t *
xMessageDst_getMessage (
xMessageQueue_t *poQueueDst)
{
register xSList_Node_t *poMsgNode = NULL;
register xMessage_t *poMsg = NULL;

if ((poMsgNode = xSList_nodeGetTail (&poQueueDst->oRxList)) != NULL)
{
poMsg = xSList_entry (poMsgNode, xMessage_t, oQNode);
}

return poMsg;
}

bool
xMessageDst_remove (
xMessage_t *poMsg, xMessageQueue_t *poQueueDst)
{
bool bRxComplete = false;
xMessageInfo_t *poMsgInfo = poMsg->poMsgInfo;
register bool bRxComplete = false;
register xMessageInfo_t *poMsgInfo = poMsg->poMsgInfo;

xRwLock_wrLock (&poMsgInfo->oLock);
xRwLock_wrLock (&poQueueDst->oLock);
Expand All @@ -299,7 +337,7 @@ xMessageDst_remove (
{
register xMessageDst_t *poMsgDst = xSList_entry (poDstNode, xMessageDst_t, oDstNode);

if (!xBitmap_getBit (poMsgDst->oMsg.ubFlags, xMessage_flagsAckInline_c))
if (!xBitmap_getBit (poMsgDst->oMsg.au8Flags, xMessage_flagsAckInline_c))
{
xSList_nodeRem (&poMsgDst->oDstNode, &poMsgInfo->oDstList);
xBuffer_free (poMsgDst);
Expand All @@ -310,9 +348,9 @@ xMessageDst_remove (

if (bRxComplete && xSList_count (&poMsgInfo->oDstList) != 0)
{
xThreadInfo_t *poThread = NULL;
xMessageQueue_t *poQueueSrc = NULL;
xMessageSrc_t *poMsgSrc = xGetParentByMemberPtr (poMsgInfo, xMessageSrc_t, oMsgInfo);
register xThreadInfo_t *poThread = NULL;
register xMessageQueue_t *poQueueSrc = NULL;
register xMessageSrc_t *poMsgSrc = xGetParentByMemberPtr (poMsgInfo, xMessageSrc_t, oMsgInfo);

xRwLock_rdLock (&oThreadData.oLock);
xRwLock_rdLock (&oMessageData.oLock);
Expand All @@ -331,9 +369,9 @@ xMessageDst_remove (
xSList_push (&poMsgSrc->oMsg.oQNode, &poQueueSrc->oAckList);
xRwLock_unlock (&poQueueSrc->oLock);

xBitmap_setBit (poThread->ubFlags, xThreadInfo_flagsMessage_c, true);
xMLock_unlock (&poThread->oLock);
xBitmap_setBit (poThread->au8Flags, xThreadInfo_flagsMessage_c, true);
xCond_broadcast (&poThread->oSignal);
xMLock_unlock (&poThread->oLock);

xRwLock_unlock (&oMessageData.oLock);
xRwLock_unlock (&oThreadData.oLock);
Expand All @@ -344,4 +382,4 @@ xMessageDst_remove (



#endif // __SYNC_C__
#endif // __MESSAGE_C__
119 changes: 119 additions & 0 deletions lib/message.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2008-2015
* NES <nes.open.switch@gmail.com>
*
* All rights reserved. This source file is the sole property of NES, and
* contain proprietary and confidential information related to NES.
*
* Licensed under the NES RED License, Version 1.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain a
* copy of the License bundled along with this file. Any kind of reproduction
* or duplication of any part of this file which conflicts with the License
* without prior written consent from NES is strictly prohibited.
*
* Unless required by applicable law and agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
//set ts=4 sw=4

#ifndef __MESSAGE_H__
# define __MESSAGE_H__

# ifdef __cplusplus
extern "C" {
# endif



#include "lib/list.h"
#include "lib/binaryTree.h"
#include "lib/sync.h"
#include "lib/thread.h"

#include <stdbool.h>
#include <stdint.h>


enum
{
xMessageQueue_flagsTx_c = 0,
xMessageQueue_flagsRx_c = 1,
xMessageQueue_flagsCount_c = 2,

xMessage_flagsAckInline_c = 0,
xMessage_flagsCount_c = 1,
};

typedef struct xMessageQueue_t
{
uint32_t u32Index;

uint8_t au8Flags[1];
xSList_Head_t oTxList;
xSList_Head_t oRxList;
xSList_Head_t oAckList;
xRwLock_t oLock;
xBTree_Node_t oBTreeNode;
} xMessageQueue_t;

struct xMessageInfo_t;

typedef struct xMessage_t
{
uint32_t u32Index;
void *pvData;
uint8_t au8Flags[1];
struct xMessageInfo_t *poMsgInfo;
xSList_Node_t oQNode;
} xMessage_t;

typedef struct xMessageInfo_t
{
uint16_t u32Type;
uint16_t u16RxCount;
xSList_Head_t oDstList;
xRwLock_t oLock;
} xMessageInfo_t;


extern xMessageQueue_t *
xMessageQueue_create (uint32_t u32Index);
extern void
xMessageQueue_remove (xMessageQueue_t *poEntry);


extern xMessage_t *
xMessage_allocate (
uint16_t u32Type, void *pvData);
extern bool
xMessage_send (
xMessage_t *poMessage, xMessageQueue_t *poSrcQueue);
extern xMessage_t *
xMessageAck_getMessage (xMessageQueue_t *poSrcQueue);
extern bool
xMessageAck_remove (
xMessage_t *poMessage, xMessageQueue_t *poSrcQueue);
extern bool
xMessage_cleanupThread (
xMessageQueue_t *poSrcQueue, xThreadInfo_t *pThread);


extern xMessage_t *
xMessageDst_create (
uint32_t u32Index, xMessage_t *poMessage);
extern xMessage_t *
xMessageDst_getMessage (xMessageQueue_t *poDstQueue);
extern bool
xMessageDst_remove (
xMessage_t *poMsg, xMessageQueue_t *poDstQueue);



# ifdef __cplusplus
}
# endif

#endif // __MESSAGE_H__

0 comments on commit e4e2b05

Please sign in to comment.