| 1 | /*----------------------------------------------------------------------------- | 
|---|
| 2 | mbx.h -- Synchronization of mailbox access | 
|---|
| 3 |  | 
|---|
| 4 | Copyright (c) 1995 JANZ Computer AG | 
|---|
| 5 | All Rights Reserved | 
|---|
| 6 |  | 
|---|
| 7 | Created 96/01/23 by Stefan Althoefer | 
|---|
| 8 | Version 1.4 of 96/07/26 | 
|---|
| 9 |  | 
|---|
| 10 | Two processes -- local and peer -- communicate via mailboxes. | 
|---|
| 11 | There are two mailboxes for each direction. Thus there are four | 
|---|
| 12 | mailboxes altogether referred to by indexes 0,1,2,3. | 
|---|
| 13 |  | 
|---|
| 14 | To synchronize read-write access to the mailboxes two synchronization | 
|---|
| 15 | bytes are used. These bytes are located in shared memory readable by | 
|---|
| 16 | both processes. One byte is owned by the local process the other by | 
|---|
| 17 | the (remote) peer process. Only the owner of a synchronization byte | 
|---|
| 18 | may write it. | 
|---|
| 19 |  | 
|---|
| 20 | There are two functions for the local process to manipulate the | 
|---|
| 21 | synchronization bytes: msync_get() and msync_unget(). | 
|---|
| 22 | With msync_get(1) (resp. msync_get(0)) the local process requests a | 
|---|
| 23 | mailbox for writing (resp. reading). The index "index" of the next box | 
|---|
| 24 | ready for writing (resp. for reading) is returned. The value -1 is | 
|---|
| 25 | returned if there is no such box. After using the box the local process | 
|---|
| 26 | calls msync_unget(writing, index) making the box available to the peer. | 
|---|
| 27 |  | 
|---|
| 28 | The functions are declared static. This file is meant to included in | 
|---|
| 29 | the file where reading and writing mailboxes is done. | 
|---|
| 30 | It is necessary to designate the send (write) direction as either | 
|---|
| 31 | up or down by #defining MSYNC_UP in the local process and MSYNC_DOWN | 
|---|
| 32 | in the peer process (or vice versa). | 
|---|
| 33 | The addresses of the synchronization bytes must be specified | 
|---|
| 34 | with MSYNC_LOCL_ADDR or MSYNC_PEER_ADDR. | 
|---|
| 35 |  | 
|---|
| 36 | -----------------------------------------------------------------------------*/ | 
|---|
| 37 |  | 
|---|
| 38 | #ifndef mbx_DEFINED | 
|---|
| 39 | #define mbx_DEFINED | 
|---|
| 40 |  | 
|---|
| 41 | #define far | 
|---|
| 42 |  | 
|---|
| 43 | /* Function prototypes by default */ | 
|---|
| 44 | #ifdef __STDC__ | 
|---|
| 45 | #define _PARAMS(args) args | 
|---|
| 46 | #else | 
|---|
| 47 | #define _PARAMS(args) () | 
|---|
| 48 | #endif | 
|---|
| 49 |  | 
|---|
| 50 | /* Mailbox access macros */ | 
|---|
| 51 | #define mbx_get(i)              ((unsigned char *)(MBX_BASE+(i+1) * MBX_LENGTH)) | 
|---|
| 52 |  | 
|---|
| 53 | /* Values for parameter "writing" in msync_*() */ | 
|---|
| 54 | #define MBX_WRITING             1 | 
|---|
| 55 | #define MBX_READING             0 | 
|---|
| 56 |  | 
|---|
| 57 | #define MSYNC_SHIFT(w) ((w) ? 4 : 0) | 
|---|
| 58 |  | 
|---|
| 59 | /* Address of local synchronization byte */ | 
|---|
| 60 | #ifdef MSYNC_LOCL_ADDR | 
|---|
| 61 | #define MSYNC_LOCL (MSYNC_LOCL_ADDR) | 
|---|
| 62 | #endif | 
|---|
| 63 |  | 
|---|
| 64 | /* Address of peer synchronization byte */ | 
|---|
| 65 | #ifdef MSYNC_PEER_ADDR | 
|---|
| 66 | #define MSYNC_PEER (MSYNC_PEER_ADDR) | 
|---|
| 67 | #endif | 
|---|
| 68 |  | 
|---|
| 69 | #endif /* mbx_DEFINED */ | 
|---|