Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > BestEffortMessaging
comparison LossyCom.h @ 0:29d8b41926f0
Initial commit - compiles but has still the wrong name
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Wed, 07 Mar 2012 19:46:37 +0100 |
| parents | |
| children | 826448e34e80 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:b07c8ec4360a |
|---|---|
| 1 /* | |
| 2 * This describes a best effort communication channel. Mainly designed for | |
| 3 * communication between Core-Controllers, so they can inform each other about | |
| 4 * their status and pass work around. This is to avoid idling cores that occupy | |
| 5 * the Masterlock. | |
| 6 * | |
| 7 * The communication entities poll a central trigger counter that increases when | |
| 8 * there are new messages. However it's not guaranteed that the increase of the | |
| 9 * counter reflects the number of new messages. | |
| 10 * | |
| 11 * The messages consist of a single 64bit word so it can be written in one | |
| 12 * operation and therefore avoiding inconsistent messages. | |
| 13 * | |
| 14 * The messages are handled with a handler function provided by the receiver | |
| 15 * when acquiring the communication endpoint. | |
| 16 * | |
| 17 * The message passing is handled by a central struct that is used w/o any lock. | |
| 18 * It consists of a array messages for the number of communicating entities. The | |
| 19 * number of entities is fixed at initialization. | |
| 20 */ | |
| 21 | |
| 22 #include <stdint.h> | |
| 23 | |
| 24 | |
| 25 | |
| 26 /*********************************** | |
| 27 * Type Definitions | |
| 28 ***********************************/ | |
| 29 | |
| 30 #define BROADCAST_ID 65535 | |
| 31 #define ENDPOINT_ID_SHIFT 32 | |
| 32 #define TRIGGER_SHIFT 48 | |
| 33 | |
| 34 /* | |
| 35 * A message consists of the | |
| 36 * 16bit saved trigger value when the message was sent | |
| 37 * 16bit receiver identifier, this is the index of the slot in the array | |
| 38 * 65536 is the broadcast identifier | |
| 39 * 32bit message body, the message format is defined by the endpoints | |
| 40 */ | |
| 41 typedef uint64_t lossyCom__msg_t; | |
| 42 typedef uint32_t lossyCom__msgBody_t; | |
| 43 typedef uint16_t lossyCom__endpointID_t; | |
| 44 | |
| 45 /* | |
| 46 * Message Handler that has two arguments the sender endpoint ID and the Msg | |
| 47 * Example: | |
| 48 * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg); | |
| 49 */ | |
| 50 typedef void (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t); | |
| 51 | |
| 52 /* | |
| 53 * Central communication structure. | |
| 54 */ | |
| 55 typedef struct{ | |
| 56 uint16_t triggerCounter; | |
| 57 uint16_t numEndpoints; | |
| 58 lossyCom__msg_t* outboxArray; | |
| 59 }lossyCom__exchange_t; | |
| 60 | |
| 61 /* | |
| 62 * Endpoint data structure. | |
| 63 */ | |
| 64 typedef struct { | |
| 65 uint16_t localTriggerCopy; | |
| 66 lossyCom__endpointID_t endpointID; | |
| 67 lossyCom__exchange_t* centralExchangePtr; | |
| 68 lossyCom__msgHandler* msgHandler; | |
| 69 } lossyCom__endpoint_t; | |
| 70 | |
| 71 /*********************************** | |
| 72 * Function Declarations | |
| 73 ***********************************/ | |
| 74 | |
| 75 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints); | |
| 76 | |
| 77 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint, | |
| 78 lossyCom__exchange_t* exchange, | |
| 79 lossyCom__endpointID_t endpointID, | |
| 80 lossyCom__msgHandler* msgHandler); | |
| 81 | |
| 82 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint, | |
| 83 lossyCom__msgBody_t msg); | |
| 84 | |
| 85 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint, | |
| 86 lossyCom__endpointID_t receiverEndpointID, | |
| 87 lossyCom__msgBody_t msg); | |
| 88 | |
| 89 void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint); |
