OSDN Git Service

TCPソケットのリソース排他mutexの集約
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Tue, 21 May 2013 13:21:18 +0000 (13:21 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Tue, 21 May 2013 13:21:18 +0000 (13:21 +0000)
git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@243 47198e57-cb75-475f-84c4-a814cd6f29e0

lib/src/uip/NyLPC_cIPv4.c
lib/src/uip/NyLPC_cIPv4.h
lib/src/uip/NyLPC_cTcpSocket.c
lib/src/uip/NyLPC_cTcpSocket.h
lib/src/uip/NyLPC_cTcpSocket_protected.h
lib/src/uip/NyLPC_cUipService_protected.h

index d1aa95a..2cb9d3d 100644 (file)
@@ -67,7 +67,7 @@
  ***************************************************/\r
 \r
 #define cSocketTbl_initialize(i_inst,buf) NyLPC_cPtrTbl_initialize(i_inst,buf,NyLPC_cIPv4_MAX_SOCKET)\r
-\r
+#define cSocketTbl_finalize(i_inst)\r
 \r
 /**\r
  * 条件に一致する、アクティブなTCPソケットオブジェクトを取得します。\r
@@ -170,6 +170,7 @@ void NyLPC_cIPv4_initialize(
        //内部テーブルの初期化\r
        cSocketTbl_initialize(&(i_inst->_socket_tbl),(void**)(i_inst->_socket_array_buf));\r
        //instanceの初期化\r
+       NyLPC_cMutex_initialize(&(i_inst->_sock_mutex));\r
        i_inst->_ref_config=NULL;\r
        return;\r
 }\r
@@ -180,6 +181,8 @@ void NyLPC_cIPv4_initialize(
 void NyLPC_cIPv4_finalize(\r
        NyLPC_TcIPv4_t* i_inst)\r
 {\r
+       cSocketTbl_finalize(&(i_inst->_socket_tbl));\r
+       NyLPC_cMutex_finalize(&(i_inst->_sock_mutex));\r
        return;\r
 }\r
 \r
@@ -345,8 +348,6 @@ static NyLPC_TBool tcp_rx(
                        //Listen失敗。ドロップ\r
                        goto DROP;\r
                }\r
-//             //Socketの割当に成功。管理リストへ追加\r
-//             NyLPC_AbortIfNot(NyLPC_cPtrTbl_add(&(i_inst->_socket_tbl),sock)>=0);\r
                return NyLPC_TBool_FALSE;//LISTEN成功。送信データなし\r
        }\r
        return NyLPC_TBool_TRUE;\r
index 7a10dc6..38482cd 100644 (file)
@@ -111,15 +111,12 @@ struct NyLPC_TcIPv4
 {\r
        /** 参照しているIPスタックの環境値です。この値は、start関数が設定します。*/\r
        const NyLPC_TcIPv4Config_t* _ref_config;\r
-//     /** NyLPC_cTcpListernerを管理するポインタリストです。*/\r
-//     NyLPC_TcPtrTbl_t _listener_tbl;\r
+       /** ソケットリソースの保護用。コールバック関数から呼び出されるソケット内部のリソース保護に使用する共通MUTEX*/\r
+       NyLPC_TcMutex_t _sock_mutex;\r
        /** NyLPC_cTcpSocketを管理するポインタリストです。*/\r
        NyLPC_TcPtrTbl_t _socket_tbl;\r
-//     /** _listener_tblが使用するメモリ領域です。*/\r
-//     NyLPC_TcTcpListener_t* _listener_array_buf[NyLPC_cIPv4_MAX_TCP_LISTENER];\r
        /** _socket_tblが使用するメモリ領域です。*/\r
        NyLPC_TcBaseSocket_t* _socket_array_buf[NyLPC_cIPv4_MAX_SOCKET];\r
-\r
 };\r
 \r
 /**\r
@@ -215,8 +212,11 @@ NyLPC_TBool NyLPC_cIPv4_rx(NyLPC_TcIPv4_t* i_inst,void* i_rx,NyLPC_TUInt16 i_rx_
  */\r
 void NyLPC_cIPv4_periodec(NyLPC_TcIPv4_t* i_inst);\r
 \r
-\r
-\r
+/**\r
+ * ソケットリソースとコールバックの排他処理に使う共通MUTEXを返します。\r
+ * このMutexはソケット同士の干渉が起こらない処理にだけ使ってください。\r
+ */\r
+#define NyLPC_cIPv4_getSockMutex(i_inst) (&((i_inst)->_sock_mutex))\r
 \r
 \r
 #ifdef __cplusplus\r
index f9a0d94..0f008e2 100644 (file)
@@ -44,6 +44,12 @@ static NyLPC_TUInt32 iss32=3939;
        #define DEBUG_RTO_LOG(i_inst)\r
 #endif\r
 \r
+\r
+//#define lockResource(i_inst) NyLPC_cMutex_lock(&((i_inst)->_smutex))\r
+//#define unlockResource(i_inst) NyLPC_cMutex_unlock(&((i_inst)->_smutex))\r
+#define lockResource(i_inst) NyLPC_cMutex_lock(((i_inst)->_smutex))\r
+#define unlockResource(i_inst) NyLPC_cMutex_unlock(((i_inst)->_smutex))\r
+\r
 static void sendRst(NyLPC_TcTcpSocket_t* i_inst);\r
 \r
 \r
@@ -139,7 +145,7 @@ static void resetTxQWithUnlock(NyLPC_TcTcpSocket_t* i_inst)
        }\r
        i_inst->txbuf.rp=i_inst->txbuf.wp=0;\r
        //ロック解除\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        //セーブしたバッファを開放\r
        for(i=0;i<l;i++){\r
                NyLPC_cUipService_releaseTxBuf(dlist[i]);\r
@@ -272,11 +278,11 @@ static struct NyLPC_TcTcpSocket_TxQItem* getTxQ(NyLPC_TcTcpSocket_t* i_inst,NyLP
                //キューの空きをチェック。wp+1==rpなら、キューがいっぱい。rp==wpなら、キューが空。\r
                if(((i_inst->txbuf.wp+1)%NyLPC_TcTcpSocket_NUMBER_OF_TXQ)==i_inst->txbuf.rp){\r
                        //一時的なアンロック\r
-                       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+                       unlockResource(i_inst);\r
                        //タスクスイッチ\r
                        NyLPC_cThread_yield();\r
                        //ロック\r
-                       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+                       lockResource(i_inst);\r
                        continue;\r
                }\r
                i=i_inst->txbuf.wp;\r
@@ -296,7 +302,6 @@ static struct NyLPC_TcTcpSocket_TxQItem* getTxQ(NyLPC_TcTcpSocket_t* i_inst,NyLP
  * public 関数
  **********************************************************************/\r
 \r
-\r
 NyLPC_TBool NyLPC_cTcpSocket_initialize(NyLPC_TcTcpSocket_t* i_inst,void* i_rbuf,NyLPC_TUInt16 i_rbuf_len)\r
 {\r
        int i;\r
@@ -306,7 +311,8 @@ NyLPC_TBool NyLPC_cTcpSocket_initialize(NyLPC_TcTcpSocket_t* i_inst,void* i_rbuf
        NyLPC_Assert(NyLPC_TcUipService_isInitService());\r
 \r
        NyLPC_cFifoBuffer_initialize(&(i_inst->rxbuf),i_rbuf,i_rbuf_len);\r
-       NyLPC_AbortIfNot(NyLPC_cMutex_initialize(&(i_inst->_smutex)));\r
+       //      NyLPC_AbortIfNot(NyLPC_cMutex_initialize(&(i_inst->_smutex)));\r
+       i_inst->_smutex=NyLPC_cIPv4_getSockMutex(&(srv->_tcpv4));\r
        i_inst->tcpstateflags=UIP_CLOSED;\r
        i_inst->txbuf.rp=i_inst->txbuf.wp=0;\r
        for(i=0;i<NyLPC_TcTcpSocket_NUMBER_OF_TXQ;i++){\r
@@ -327,14 +333,14 @@ void NyLPC_cTcpSocket_finalize(NyLPC_TcTcpSocket_t* i_inst)
        }\r
        //開放漏れの保険\r
        if(i_inst->txbuf.rp!=i_inst->txbuf.wp){\r
-               NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+               lockResource(i_inst);\r
                resetTxQWithUnlock(i_inst);\r
        }\r
        for(i=0;i<NyLPC_TcTcpSocket_NUMBER_OF_TXQ;i++){\r
                NyLPC_cIPv4Payload_finalize(&(i_inst->txbuf.txq[i].data));\r
        }\r
        NyLPC_cFifoBuffer_finalize(&(i_inst->rxbuf));\r
-       NyLPC_cMutex_finalize(&(i_inst->_smutex));\r
+//     NyLPC_cMutex_finalize(&(i_inst->_smutex));\r
        NyLPC_cBaseSocket_finalize(&(i_inst->_super));\r
        return;\r
 }\r
@@ -350,7 +356,7 @@ NyLPC_TBool NyLPC_cTcpSocket_setSynPayload(NyLPC_TcTcpSocket_t* i_inst,const NyL
 {\r
        NyLPC_TUInt16 tmp16;\r
        //ソケットが無効であること。\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
        if(i_inst->tcpstateflags==UIP_CLOSED)\r
        {\r
                /* Fill in the necessary fields for the new connection. */\r
@@ -373,13 +379,13 @@ NyLPC_TBool NyLPC_cTcpSocket_setSynPayload(NyLPC_TcTcpSocket_t* i_inst,const NyL
                if(i_inst->txbuf.rp!=i_inst->txbuf.wp){\r
                        resetTxQWithUnlock(i_inst);\r
                }else{\r
-                       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+                       unlockResource(i_inst);\r
                }\r
                //ここでステータスがかわる。\r
                i_inst->tcpstateflags = UIP_SYN_RCVD;\r
                return NyLPC_TBool_TRUE;\r
        }\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        return NyLPC_TBool_FALSE;\r
 }\r
 /**\r
@@ -401,22 +407,22 @@ NyLPC_TBool NyLPC_cTcpSocket_setSynPayload(NyLPC_TcTcpSocket_t* i_inst,const NyL
 static NyLPC_TBool waitForTxRemove(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt32 i_sq,NyLPC_TcStopwatch_t* i_timer)\r
 {\r
        NyLPC_TUInt8 f;\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
        while(!NyLPC_cStopwatch_isExpired(i_timer)){\r
                //パケットが送信中か調べる。\r
                if(!isPacketAcked(i_inst,i_sq)){\r
                        //まだある場合は、タスクスイッチを繰り返して消失を待つ。\r
-                       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+                       unlockResource(i_inst);\r
                        NyLPC_cThread_yield();\r
-                       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+                       lockResource(i_inst);\r
                        continue;\r
                }\r
                //なくなった場合は、原因を調べる。\r
                f=i_inst->tcpstateflags;\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
                return (f==UIP_CLOSED)?NyLPC_TBool_FALSE:NyLPC_TBool_TRUE;\r
        }\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        return NyLPC_TBool_FALSE;\r
 }\r
 \r
@@ -453,17 +459,17 @@ static NyLPC_TInt32 sendWithRetransmit(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt8
                        return -1;\r
                }\r
        };\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
        //ペイロードがある場合のみ、相手のwindowサイズが0以上になるのを待つ。\r
        if(i_len>0){\r
                while(i_inst->uip_connr.peer_win==0){\r
-                       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+                       unlockResource(i_inst);\r
                        //時間切れならエラー。\r
                        if(NyLPC_cStopwatch_isExpired(i_timer)){\r
                                return -1;\r
                        }\r
                        NyLPC_cThread_yield();\r
-                       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+                       lockResource(i_inst);\r
                }\r
        }\r
        //送信キューの取得\r
@@ -471,7 +477,7 @@ static NyLPC_TInt32 sendWithRetransmit(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt8
        //送信キューが取れなかった。\r
        if(txq==NULL){\r
                //シーケンス番号をロールバックできないので、エラーとする。\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
                NyLPC_cUipService_releaseTxBuf(buf);\r
                return -1;\r
        }\r
@@ -505,7 +511,7 @@ static NyLPC_TInt32 sendWithRetransmit(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt8
        i_inst->uip_connr.peer_win-=s;\r
        //ACK番号の返却\r
        *o_ack=txq->ackno=NyLPC_HTONL(next_ack);\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        NyLPC_cUipService_sendIPv4Tx(buf);\r
        return s;\r
 }\r
@@ -529,11 +535,11 @@ static void sendRst(NyLPC_TcTcpSocket_t* i_inst)
        do{\r
                buf=NyLPC_cUipService_allocTxBuf((SIZE_OF_IPv4_TCPIP_HEADER)+5,&s);\r
        }while(buf==NULL);\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
        NyLPC_cIPv4Payload_setTxBuf(&ipv4,buf);\r
        i_inst->uip_connr.snd_nxt32++;\r
        setPacket(i_inst,&ipv4,TCP_RST|TCP_ACK,buf,0);\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
 \r
        NyLPC_cUipService_sendIPv4Tx(buf);\r
        NyLPC_cUipService_releaseTxBuf(buf);\r
@@ -606,12 +612,12 @@ NyLPC_TBool NyLPC_cTcpSocket_accept(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt32 i_
                }\r
        }\r
        //ロックして、強制的なステータス遷移\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
        f=i_inst->tcpstateflags;\r
        if(f!=UIP_CLOSED){\r
                i_inst->tcpstateflags=UIP_CLOSED;\r
        }\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        //もし、強制CLOSE遷移であれば、RSTも送信。\r
        if(f!=UIP_CLOSED){\r
                sendRst(i_inst);\r
@@ -640,12 +646,12 @@ NyLPC_TInt32 NyLPC_cTcpSocket_precv(NyLPC_TcTcpSocket_t* i_inst,const void** o_b
                //読み出しバッファ情報のコピー\r
 \r
                //MUTEX LOCK\r
-               NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+               lockResource(i_inst);\r
                st=i_inst->tcpstateflags;\r
                rlen=NyLPC_cFifoBuffer_getLength(&(i_inst->rxbuf));\r
                *o_buf_ptr=NyLPC_cFifoBuffer_getPtr(&(i_inst->rxbuf));\r
                //MUTEX UNLOCK\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
 \r
                //バッファが空の場合は、ステータスチェック。ESTABLISHEDでなければ、エラー(PASVCLOSE等の場合)\r
                switch(st){\r
@@ -698,14 +704,14 @@ void NyLPC_cTcpSocket_pseek(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt16 i_seek)
        }while(buf==NULL);\r
 \r
        //MUTEX LOCK\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
 \r
        //受信バッファを読み出しシーク\r
        NyLPC_cFifoBuffer_pop(&(i_inst->rxbuf),i_seek);\r
        //ACKパケットの生成\r
        NyLPC_cIPv4Payload_setTxBuf(&ipv4payload,buf);\r
        setPacket(i_inst,&ipv4payload,TCP_ACK,buf,0);\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        //ACK送信\r
        NyLPC_cUipService_sendIPv4Tx(buf);\r
        NyLPC_cUipService_releaseTxBuf(buf);\r
@@ -739,11 +745,12 @@ void* NyLPC_cTcpSocket_allocSendBuf(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt16 i_
                }\r
        }\r
 \r
-//ここ、要求サイズとpeerのwinのうち、小さいほうを割り当てたほうが良くない?\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+//@todo 前段処理と順番を入れ替えて、要求サイズとpeerのwinのうち、小さいほうを割り当てたほうが良くない?\r
+//ここで相手のwin待ちをする理由は、相手に確実に受け取れるサイズを決定する為。\r
+       lockResource(i_inst);\r
        //ペイロードがある場合のみ、相手のwindowサイズが0以上になるのを待つ。\r
        while(i_inst->uip_connr.peer_win==0){\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
                //ESTABLISHED以外に非同期遷移 orタイムアウト確認\r
                if(NyLPC_cStopwatch_isExpired(&sw)||(i_inst->tcpstateflags!=UIP_ESTABLISHED)){\r
                        NyLPC_cUipService_releaseTxBuf(buf);\r
@@ -751,7 +758,7 @@ void* NyLPC_cTcpSocket_allocSendBuf(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt16 i_
                        return NULL;\r
                }\r
                NyLPC_cThread_yield();\r
-               NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+               lockResource(i_inst);\r
        }\r
        //送信バッファを基準とした送信サイズを計算\r
        s-=SIZE_OF_IPv4_TCPIP_HEADER;\r
@@ -763,7 +770,7 @@ void* NyLPC_cTcpSocket_allocSendBuf(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt16 i_
        if(i_inst->uip_connr.peer_win<s){\r
                s=i_inst->uip_connr.peer_win;\r
        }\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        //バッファサイズ確定。\r
        *o_buf_size=s;\r
        NyLPC_cStopwatch_finalize(&sw);\r
@@ -806,13 +813,13 @@ NyLPC_TBool NyLPC_cTcpSocket_psend(NyLPC_TcTcpSocket_t* i_inst,void* i_buf_ptr,i
 \r
        //先頭ポインタは、i_buf-sizeof(SIZE_OF_IPv4_TCPIP_HEADER)固定\r
        buf=(NyLPC_TUInt8*)i_buf_ptr-SIZE_OF_IPv4_TCPIP_HEADER;\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
        //送信キューの取得\r
        txq=getTxQ(i_inst,&sw);\r
        //送信キューが取れなかった。\r
        if(txq==NULL){\r
                //シーケンス番号をロールバックできないので、エラーとする。\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
                NyLPC_cStopwatch_finalize(&sw);\r
                return NyLPC_TBool_FALSE;\r
        }\r
@@ -835,7 +842,7 @@ NyLPC_TBool NyLPC_cTcpSocket_psend(NyLPC_TcTcpSocket_t* i_inst,void* i_buf_ptr,i
        i_inst->uip_connr.peer_win-=i_len;\r
        //ACK番号の返却\r
        txq->ackno=NyLPC_HTONL(i_inst->uip_connr.snd_nxt32);\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        NyLPC_cUipService_sendIPv4Tx(buf);\r
        NyLPC_cStopwatch_finalize(&sw);\r
        return NyLPC_TBool_TRUE;\r
@@ -875,7 +882,7 @@ void NyLPC_cTcpSocket_close(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt32 i_wait_in_
        NyLPC_TUInt32 sq;\r
        NyLPC_cStopwatch_initialize(&sw);\r
        NyLPC_cStopwatch_startExpire(&sw,i_wait_in_msec);\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
 \r
        f=i_inst->tcpstateflags;\r
        //ステータスチェック\r
@@ -888,7 +895,7 @@ void NyLPC_cTcpSocket_close(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt32 i_wait_in_
                //アクティブクローズ。\r
                i_inst->tcpstateflags=UIP_FIN_WAIT_1;\r
                //送信のために一旦解除\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
                //FINの送信\r
                if(sendWithRetransmit(i_inst,TCP_FIN|TCP_ACK,NULL,0,&sw,&sq)==0){\r
                        //ちょっと待つ。\r
@@ -896,7 +903,7 @@ void NyLPC_cTcpSocket_close(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt32 i_wait_in_
                        //TXの消去待ち\r
                        if(waitForTxRemove(i_inst,sq,&sw)){\r
                                //再ロック\r
-                               NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+                               lockResource(i_inst);\r
                                //タイムアウトするか、UIP_CLOSED、もしくはTIME_WAITに遷移するのを待つ。(遷移はRxprocで自動的に実行。)\r
                                while(!NyLPC_cStopwatch_isExpired(&sw)){\r
                                        switch(i_inst->tcpstateflags)\r
@@ -911,14 +918,14 @@ void NyLPC_cTcpSocket_close(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt32 i_wait_in_
                                        case UIP_FIN_WAIT_2:\r
                                        case UIP_CLOSING:\r
                                                //一時的なアンロック\r
-                                               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+                                               unlockResource(i_inst);\r
                                                NyLPC_cThread_yield();\r
-                                               NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+                                               lockResource(i_inst);\r
                                        default:\r
                                                break;\r
                                        }\r
                                }\r
-                               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+                               unlockResource(i_inst);\r
                        }\r
                }\r
                break;\r
@@ -926,41 +933,41 @@ void NyLPC_cTcpSocket_close(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt32 i_wait_in_
                //LAST_ACKへ遷移\r
                i_inst->tcpstateflags=UIP_LAST_ACK;\r
                //送信のために一旦解除\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
                if(sendWithRetransmit(i_inst,TCP_FIN|TCP_ACK,NULL,0,&sw,&sq)==0){\r
                        //ちょっと待つ。\r
                        NyLPC_cThread_yield();\r
                        //TXの消去待ち\r
                        if(waitForTxRemove(i_inst,sq,&sw)){\r
                                //再ロック\r
-                               NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+                               lockResource(i_inst);\r
                                //TX消去後にCLOSEDに遷移していればOK\r
                                if(i_inst->tcpstateflags==UIP_CLOSED)\r
                                {\r
                                        NyLPC_Assert(i_inst->txbuf.rp==i_inst->txbuf.wp);\r
                                        goto ReturnWithUnlock;\r
                                }\r
-                               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+                               unlockResource(i_inst);\r
                        }\r
                }\r
                //エラー。RSTで切断。\r
                break;\r
        default:\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
                NyLPC_Warning();\r
                break;\r
        }\r
-       if(i_inst->_smutex._lock_count>0){\r
-               NyLPC_Warning();\r
-       }\r
+//     if(i_inst->_smutex._lock_count>0){\r
+//             NyLPC_Warning();\r
+//     }\r
        //このパスに到達するのは、FIN送信/ACKに成功したにも拘らず、規定時間内にCLOSEDに遷移しなかった場合。\r
        //コネクションを強制遷移して、RST\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
        f=i_inst->tcpstateflags;\r
        if(f!=UIP_CLOSED){\r
                i_inst->tcpstateflags=UIP_CLOSED;\r
        }\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        //もし、強制CLOSE遷移であれば、RSTも送信。\r
        if(f!=UIP_CLOSED){\r
                sendRst(i_inst);\r
@@ -968,14 +975,14 @@ void NyLPC_cTcpSocket_close(NyLPC_TcTcpSocket_t* i_inst,NyLPC_TUInt32 i_wait_in_
        NyLPC_cStopwatch_finalize(&sw);\r
        return;\r
 ReturnWithUnlock:\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        NyLPC_cStopwatch_finalize(&sw);\r
        return;\r
 }\r
 \r
 /**\r
  * 定期的に実行する関数。最低でも1s単位で実行してください。\r
- * 動作\r
+ * uipサービスタスクが実行する関数です。\r
  */\r
 void NyLPC_cTcpSocket_periodic(\r
        NyLPC_TcTcpSocket_t* i_inst)\r
@@ -988,17 +995,17 @@ void NyLPC_cTcpSocket_periodic(
        NyLPC_cStopwatch_initialize(&sw);\r
        now=NyLPC_cStopwatch_now();\r
        //MUTEX LOCK\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
        if(i_inst->tcpstateflags==UIP_CLOSED)\r
        {\r
                //CLOSEDなら、バッファ開放。\r
                resetTxQWithUnlock(i_inst);\r
        }else if(i_inst->txbuf.rp==i_inst->txbuf.wp){\r
                //再送信パケットがなければ何もしないよ。\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
        }else if(i_inst->uip_connr.peer_win==0){\r
                //peer_winが0の場合は何もしない。\r
-               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+               unlockResource(i_inst);\r
        }else{\r
                //再送信処理\r
                rp=i_inst->txbuf.rp;\r
@@ -1020,10 +1027,10 @@ void NyLPC_cTcpSocket_periodic(
                                for(i=rp;i!=i_inst->txbuf.wp;i=(i+1)%NyLPC_TcTcpSocket_NUMBER_OF_TXQ){\r
                                        NyLPC_cUipService_sendIPv4Tx(NyLPC_cIPv4Payload_getBuf(&(q[i].data)));\r
                                }\r
-                               NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+                               unlockResource(i_inst);\r
                        }\r
                }else{\r
-                       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+                       unlockResource(i_inst);\r
                }\r
        }\r
        NyLPC_cStopwatch_finalize(&sw);\r
@@ -1060,7 +1067,7 @@ NyLPC_TBool NyLPC_cTcpSocket_parseRx(
        tcp_data_offset=o_ipp->payload.rawbuf+tmp16;\r
 \r
        //インスタンスをロックする。\r
-       NyLPC_cMutex_lock(&(i_inst->_smutex));\r
+       lockResource(i_inst);\r
 \r
        //RSTのチェック。RST受信時は、状態にかかわらず、CLOSEDステータスに移行する。\r
        if (in_tcpflag & TCP_RST)\r
@@ -1197,7 +1204,7 @@ NyLPC_TBool NyLPC_cTcpSocket_parseRx(
        }else{\r
                ret=NyLPC_TBool_FALSE;\r
        }\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
        //取り外したTXメモリの開放\r
        for(i=0;i<s;i++){\r
                //取り外したTXメモリを開放\r
@@ -1207,7 +1214,7 @@ NyLPC_Trace();
        return ret;\r
 DROP:\r
        //ACKしたパケットを送信キューから削除\r
-       NyLPC_cMutex_unlock(&(i_inst->_smutex));\r
+       unlockResource(i_inst);\r
 NyLPC_Trace();\r
        return NyLPC_TBool_FALSE;\r
 }\r
index 0322eaf..33a4426 100644 (file)
@@ -65,8 +65,8 @@ struct uip_conn
        NyLPC_TUInt16                rport;             /**< The local remote TCP port, in network byte order. */\r
        NyLPC_TUInt32 rcv_nxt32;        /**< The sequence number that we expect to receive next. */\r
        NyLPC_TUInt32 snd_nxt32;        /**< 送信用sqカウンター*/\r
-       NyLPC_TUInt16 peer_mss;          /**< PeerのMSS*/\r
-       NyLPC_TUInt16 default_mss;   /**< Peerの初期MMS*/\r
+       NyLPC_TUInt16 peer_mss;     /**< PeerのMSS*/\r
+       NyLPC_TUInt16 default_mss;  /**< Peerの初期MMS*/\r
        /**Peerのウインドウサイズ*/\r
        NyLPC_TUInt16 peer_win;\r
        NyLPC_TUInt16 _padding;\r
@@ -89,6 +89,11 @@ struct uip_conn
 \r
 /**\r
  * uipサービスを使用したTCPソケットクラスです。\r
+ * この関数は2つのタスクから呼び出されます。\r
+ * [uipTask]  ->  [cTcpSocket] <- [Application]\r
+ * ApplicationとuipTaskとの間での排他処理はインスタンスで制御されています。\r
+ * Application側からのコールは内部でuipTaskとの間で排他処理を実行します。\r
+ * Application側からのコールはリエントラントではありません。\r
  */\r
 \r
 struct NyLPC_TcTcpSocket\r
@@ -105,8 +110,8 @@ struct NyLPC_TcTcpSocket
                struct NyLPC_TcTcpSocket_TxQItem txq[NyLPC_TcTcpSocket_NUMBER_OF_TXQ];\r
        }txbuf;\r
        volatile NyLPC_TUInt8 tcpstateflags; /**< TCP state and flags. */\r
-\r
-       NyLPC_TcMutex_t _smutex;\r
+       /** 共通MUTEXへのポインタ(うまくいtったらこのままで)*/\r
+       NyLPC_TcMutex_t* _smutex;\r
 };\r
 \r
 /**\r
index 3f3b112..68c1a18 100644 (file)
@@ -63,6 +63,7 @@ void NyLPC_cTcpSocket_initConnection(NyLPC_TcTcpSocket_t* i_inst,const NyLPC_TcI
 \r
 /**\r
  * TCPペイロードを処理して、応答パケットをペイロードに返します。\r
+ * uipサービスタスクが実行する関数です。\r
  * @return\r
  * 応答ペイロードの有無を返します。\r
  */\r
@@ -71,6 +72,13 @@ NyLPC_TBool NyLPC_cTcpSocket_parseRx(
        NyLPC_TcIPv4Payload_t* o_ipp);\r
 \r
 /**\r
+ * 定期的に実行する関数。最低でも1s単位で実行してください。\r
+ * uipサービスタスクが実行する関数です。\r
+ */\r
+void NyLPC_cTcpSocket_periodic(\r
+       NyLPC_TcTcpSocket_t* i_inst);\r
+\r
+/**\r
  * ソケットをlisten済みにマークします。cTcpListenerからコールします。\r
  */\r
 NyLPC_TBool NyLPC_cTcpSocket_setSynPayload(NyLPC_TcTcpSocket_t* i_inst,const NyLPC_TcIPv4Config_t* i_config,const NyLPC_TcIPv4Payload_t* i_ipp);\r
index 3ec5aa2..ba8b92c 100644 (file)
@@ -56,7 +56,7 @@ struct NyLPC_TcUipService
        NyLPC_TcIPv4_t _tcpv4;\r
        /** ICOMP処理インスタンス*/\r
        NyLPC_TcIPv4IComp_t _icomp;\r
-       /** 排他制御用*/\r
+       /** (Ethernetメモリ排他制御用)*/\r
        NyLPC_TcMutex_t _mutex;\r
        const struct TiEthernetDevice* _ethif;\r
        /** ipタスクが使う小サイズ送信バッファ*/\r