changeset 5:95a03e431480 multiple_p2p_trigger tip

corrected comments and variable renaming
author Merten Sach <msach@mailbox.tu-berlin.de>
date Tue, 13 Mar 2012 19:07:49 +0100
parents 7ba5a3a6102d
children
files LossyCom.c LossyCom.h
diffstat 2 files changed, 48 insertions(+), 38 deletions(-) [+]
line diff
     1.1 --- a/LossyCom.c	Tue Mar 13 18:22:12 2012 +0100
     1.2 +++ b/LossyCom.c	Tue Mar 13 19:07:49 2012 +0100
     1.3 @@ -1,4 +1,3 @@
     1.4 -
     1.5  /*
     1.6   * For a detailed description see header file.
     1.7   */
     1.8 @@ -9,44 +8,44 @@
     1.9  #include "VMS_Implementations/VMS_impl/vmalloc.h"
    1.10  
    1.11  /*
    1.12 - * Initializes the central exchange structure.
    1.13 + * Initializes the central exchange structure and sets all trigger counter to 0
    1.14   * Allocates memory to fit the number of endpoints.
    1.15   * Returns NULL if an error occurs.
    1.16   */
    1.17  lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints)
    1.18  {
    1.19 -    lossyCom__exchange_t* exchange;
    1.20 +    lossyCom__exchange_t* centralExchange;
    1.21      
    1.22 -    exchange = VMS_WL__malloc(sizeof(lossyCom__exchange_t));
    1.23 -    if(exchange == NULL)
    1.24 +    centralExchange = VMS_WL__malloc(sizeof(lossyCom__exchange_t));
    1.25 +    if(centralExchange == NULL)
    1.26          return NULL;
    1.27      
    1.28 -    exchange->BroadcastTriggerCounter = 0;
    1.29 -    exchange->numEndpoints = numEndpoints;
    1.30 -    exchange->outboxArray = VMS_WL__malloc(sizeof(lossyCom__msg_t)*numEndpoints);
    1.31 -    if(exchange->outboxArray == NULL){
    1.32 -        VMS_WL__free(exchange);
    1.33 +    centralExchange->broadcastTriggerCounter = 0;
    1.34 +    centralExchange->numEndpoints = numEndpoints;
    1.35 +    centralExchange->outboxArray = VMS_WL__malloc(sizeof(lossyCom__msg_t)*numEndpoints);
    1.36 +    if(centralExchange->outboxArray == NULL){
    1.37 +        VMS_WL__free(centralExchange);
    1.38          return NULL;
    1.39      }
    1.40      
    1.41 -    exchange->p2pTriggerCounter = VMS_WL__malloc(sizeof(uint16_t)*numEndpoints);
    1.42 -    if(exchange->p2pTriggerCounter == NULL){
    1.43 -        VMS_WL__free(exchange->outboxArray);
    1.44 -        VMS_WL__free(exchange);
    1.45 +    centralExchange->p2pTriggerCounters = VMS_WL__malloc(sizeof(uint16_t)*numEndpoints);
    1.46 +    if(centralExchange->p2pTriggerCounters == NULL){
    1.47 +        VMS_WL__free(centralExchange->outboxArray);
    1.48 +        VMS_WL__free(centralExchange);
    1.49          return NULL;
    1.50      }
    1.51      
    1.52      //reset all point 2 point trigger counter
    1.53 -    memset((void*)exchange->p2pTriggerCounter, 0, sizeof(uint16_t)*numEndpoints);
    1.54 +    memset((void*)centralExchange->p2pTriggerCounters, 0, sizeof(uint16_t)*numEndpoints);
    1.55      
    1.56 -    return exchange;    
    1.57 +    return centralExchange;    
    1.58  }
    1.59  
    1.60  /*
    1.61   * Connects the local endpoint to the central exchange structure.
    1.62 - * This registers a message handler that handles all the incomming messages.
    1.63 + * This registers a message handler that handles all incoming messages.
    1.64   * Also an endpointID is set this ID has to be between 0 and total number of
    1.65 - * endpoints-1 and the number has to be unique.
    1.66 + * endpoints-1 and unique.
    1.67   */
    1.68  void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
    1.69                                     lossyCom__exchange_t* centralExchange,
    1.70 @@ -61,13 +60,17 @@
    1.71      localEndpoint->msgHandlerData = msgHandlerData;
    1.72  }
    1.73  
    1.74 +/*
    1.75 + * Prepare a lossyCom__msg_t in the correct format that contains the trigger 
    1.76 + * value, the receiver endpoint ID and the message body
    1.77 + */
    1.78  inline lossyCom__msg_t prepareMsg(uint16_t triggerValue,
    1.79                                    lossyCom__endpointID_t receiverEndpointID,
    1.80 -                                  lossyCom__msgBody_t msg)
    1.81 +                                  lossyCom__msgBody_t msgBody)
    1.82  {
    1.83      lossyCom__msg_t msgDraft;
    1.84      
    1.85 -    msgDraft = (0 | msg);
    1.86 +    msgDraft = (0 | msgBody);
    1.87      msgDraft |= ((lossyCom__msg_t)receiverEndpointID << ENDPOINT_ID_SHIFT);
    1.88      msgDraft |= ((lossyCom__msg_t)triggerValue << TRIGGER_SHIFT);
    1.89      
    1.90 @@ -84,7 +87,7 @@
    1.91      uint16_t increasedTrigger;
    1.92      lossyCom__msg_t msg;
    1.93      
    1.94 -    increasedTrigger = centralExchange->BroadcastTriggerCounter +1;
    1.95 +    increasedTrigger = centralExchange->broadcastTriggerCounter +1;
    1.96      
    1.97      //build message
    1.98      msg = prepareMsg(increasedTrigger, BROADCAST_ID, msgBody);
    1.99 @@ -93,7 +96,7 @@
   1.100      centralExchange->outboxArray[localEndpoint->endpointID] = msg;
   1.101      
   1.102      //update broadcast trigger counter
   1.103 -    centralExchange->BroadcastTriggerCounter = increasedTrigger;
   1.104 +    centralExchange->broadcastTriggerCounter = increasedTrigger;
   1.105  }
   1.106  
   1.107  /*
   1.108 @@ -109,7 +112,7 @@
   1.109      uint16_t increasedTrigger;
   1.110      
   1.111      increasedTrigger =
   1.112 -            centralExchange->p2pTriggerCounter[receiverEndpointID] +1;
   1.113 +            centralExchange->p2pTriggerCounters[receiverEndpointID] +1;
   1.114      
   1.115          //build message
   1.116      msg = prepareMsg(increasedTrigger, receiverEndpointID, msgBody);
   1.117 @@ -118,7 +121,7 @@
   1.118      centralExchange->outboxArray[localEndpoint->endpointID] = msg;
   1.119      
   1.120      //write back increased trigger counter
   1.121 -    centralExchange->p2pTriggerCounter[receiverEndpointID] = increasedTrigger;
   1.122 +    centralExchange->p2pTriggerCounters[receiverEndpointID] = increasedTrigger;
   1.123  }
   1.124  
   1.125  int inline isUnreceivedMsg(uint16_t msgTrigger, 
   1.126 @@ -153,9 +156,9 @@
   1.127      
   1.128      centralExchange = localEndpoint->centralExchange;
   1.129      //save trigger counter to know find valid messages
   1.130 -    broadcastTriggerSnapshot = centralExchange->BroadcastTriggerCounter;
   1.131 +    broadcastTriggerSnapshot = centralExchange->broadcastTriggerCounter;
   1.132      p2pTriggerSnapshot = 
   1.133 -            centralExchange->p2pTriggerCounter[localEndpoint->endpointID];    
   1.134 +            centralExchange->p2pTriggerCounters[localEndpoint->endpointID];    
   1.135      
   1.136      //new message arrived if trigger counter is higher than the last time read
   1.137      if( broadcastTriggerSnapshot > localEndpoint->lastReceivedBroadcastTrigger ||
     2.1 --- a/LossyCom.h	Tue Mar 13 18:22:12 2012 +0100
     2.2 +++ b/LossyCom.h	Tue Mar 13 19:07:49 2012 +0100
     2.3 @@ -4,9 +4,11 @@
     2.4   * their status and pass work around. This is to avoid idling cores that occupy
     2.5   * the Masterlock.
     2.6   * 
     2.7 - * The communication entities poll a central trigger counter that increases when
     2.8 - * there are new messages. However it's not guaranteed that the increase of the
     2.9 - * counter reflects the number of new messages.
    2.10 + * The communication entities poll a central trigger counter and per receiver
    2.11 + * trigger counter that increase when there are new messages.
    2.12 + * However it's not guaranteed that the increase of the counter reflects the
    2.13 + * number of new messages. The new trigger counter can even be lower than the
    2.14 + * last see counter for some receiver.
    2.15   * 
    2.16   * The messages consist of a single 64bit word so it can be written in one 
    2.17   * operation and therefore avoiding inconsistent messages.
    2.18 @@ -15,10 +17,13 @@
    2.19   * when acquiring the communication endpoint.
    2.20   * 
    2.21   * The message passing is handled by a central struct that is used w/o any lock.
    2.22 - * It consists of a array messages for the number of communicating entities. The
    2.23 - * number of entities is fixed at initialization.
    2.24 + * It consists of a array messages for the number of communicating endpoints.
    2.25 + * The number of endpoints is fixed at initialization time.
    2.26   */
    2.27  
    2.28 +#ifndef LOSSYCOM_H
    2.29 +#define LOSSYCOM_H
    2.30 +
    2.31  #include <stdint.h>
    2.32  
    2.33  /***********************************
    2.34 @@ -58,8 +63,8 @@
    2.35   * Central communication structure.
    2.36   */
    2.37  typedef struct{
    2.38 -    volatile uint16_t  BroadcastTriggerCounter;
    2.39 -    volatile uint16_t* p2pTriggerCounter;
    2.40 +    volatile uint16_t  broadcastTriggerCounter;
    2.41 +    volatile uint16_t* p2pTriggerCounters;
    2.42      uint16_t           numEndpoints;
    2.43      lossyCom__msg_t*   outboxArray;
    2.44  }lossyCom__exchange_t;
    2.45 @@ -68,12 +73,12 @@
    2.46   * Endpoint data structure.
    2.47   */
    2.48  typedef struct {
    2.49 +    lossyCom__exchange_t*  centralExchange;
    2.50 +    lossyCom__endpointID_t endpointID;
    2.51 +    lossyCom__msgHandler   msgHandler;
    2.52 +    void*    msgHandlerData;
    2.53      uint16_t lastReceivedBroadcastTrigger;
    2.54      uint16_t lastReceivedp2pTrigger;
    2.55 -    lossyCom__endpointID_t endpointID;
    2.56 -    lossyCom__exchange_t*  centralExchange;
    2.57 -    lossyCom__msgHandler   msgHandler;
    2.58 -    void*    msgHandlerData;
    2.59  } lossyCom__endpoint_t;
    2.60  
    2.61  /***********************************
    2.62 @@ -95,4 +100,6 @@
    2.63                         lossyCom__endpointID_t receiverEndpointID,
    2.64                         lossyCom__msgBody_t msg);
    2.65  
    2.66 -void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint);
    2.67 \ No newline at end of file
    2.68 +void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint);
    2.69 +
    2.70 +#endif //LOSSYCOM_H
    2.71 \ No newline at end of file