shared_mem.c

00001 #include <native/heap.h>
00002 
00003 RT_HEAP heap_desc;
00004 
00005 void *shared_mem; /* Start address of the shared memory segment */
00006 
00007 /* A shared memory segment with Xenomai is implemented as a mappable
00008    real-time heap object managed as a single memory block. In this
00009    mode, the allocation routine always returns the start address of
00010    the heap memory to all callers, and the free routine always leads
00011    to a no-op. */
00012 
00013 int main (int argc, char *argv[])
00014 
00015 {
00016     int err;
00017 
00018     /* Bind to a shared heap which has been created elsewhere, either
00019        in kernel or user-space. Here we cannot wait and the heap must
00020        be available at once, since the caller is not a Xenomai-enabled
00021        thread. The heap should have been created with the H_SHARED
00022        mode set. */
00023 
00024     err = rt_heap_bind(&heap_desc,"SomeShmName",TM_NONBLOCK);
00025 
00026     if (err)
00027         fail();
00028 
00029     /* Get the address of the shared memory segment. The "size" and
00030        "timeout" arguments are unused here. */
00031     rt_heap_alloc(&heap_desc,0,TM_NONBLOCK,&shared_mem);
00032 
00033     /* ... */
00034 }
00035 
00036 void cleanup (void)
00037 
00038 {
00039     /* We need to unbind explicitly from the heap in order to
00040        properly release the underlying memory mapping. Exiting the
00041        process unbinds all mappings automatically. */
00042     rt_heap_unbind(&heap_desc);
00043 }

Generated on Mon Mar 24 18:02:40 2008 for Xenomai API by  doxygen 1.5.3