sharedmem.h

Go to the documentation of this file.
00001 /* $Id: sharedmem.h,v 1.3 2005/02/03 11:02:19 jlaako Exp $ */
00002 
00065 #ifndef SHAREDMEM_H
00066 #define SHAREDMEM_H
00067 
00068 
00069 #include "shm_config.h"
00070 
00071 #include <limits.h>
00072 #include <sys/types.h>
00073 #ifdef HAVE_PSHARED
00074 #include <pthread.h>
00075 #endif
00076 #include <semaphore.h>
00077 
00078 
00079 #define SHAREDMEM_ERROR_SIZE            256
00080 #define SHAREDMEM_NAME_LENGTH           _POSIX_PATH_MAX
00081 
00082 
00083 #if ((__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1) && !defined(likely))
00084 #define likely(x)           __builtin_expect(x, 1)
00085 #define unlikely(x)         __builtin_expect(x, 0)
00086 #define prefetch(x, w, l)   __builtin_prefetch(x, w, l)
00087 #else
00088 #define likely(x)           (x)
00089 #define unlikely(x)         (x)
00090 #define prefetch(x, w, l)
00091 #endif
00092 
00093 
00094 #ifdef __cplusplus
00095 extern "C" {
00096 #endif
00097 
00098 
00102 typedef struct _sharedmem_ctrl_t
00103 {
00104 #ifdef HAVE_PSHARED
00105     pthread_mutex_t mutex;              
00106     pthread_cond_t cond;                
00107 #endif
00108     volatile size_t size;               
00109     volatile int ref;                   
00110 } sharedmem_ctrl_t;
00111 
00112 
00116 typedef struct _sharedmem_error_t
00117 {
00118     int code;                           
00119     char string[SHAREDMEM_ERROR_SIZE];  
00120 } sharedmem_error_t;
00121 
00122 
00126 typedef struct _sharedmem_t
00127 {
00128     int fd;                             
00129     sem_t *sem;                         
00130     sharedmem_ctrl_t *ctrl;             
00131     size_t mapped_size;                 
00132     void *pdata;                        
00133     char name[SHAREDMEM_NAME_LENGTH];   
00134     sharedmem_error_t error;            
00135 } sharedmem_t;
00136 
00137 
00139 #define SHAREDMEM_MUTEX(i)              (&(i)->ctrl->mutex)
00140 
00141 #define SHAREDMEM_COND(i)               (&(i)->ctrl->cond)
00142 
00143 #define SHAREDMEM_SEM(i)                ((i)->sem)
00144 
00145 #define SHAREDMEM_PTR(i)                ((i)->pdata)
00146 
00147 #define SHAREDMEM_SIZE(i)               ((i)->mapped_size)
00148 
00149 
00158 int sharedmem_create (sharedmem_t *inst, const char *name, size_t size);
00166 int sharedmem_open (sharedmem_t *inst, const char *name);
00173 int sharedmem_close (sharedmem_t *inst);
00181 int sharedmem_resize (sharedmem_t *inst, size_t size);
00190 int sharedmem_resize2 (sharedmem_t *inst);
00199 int sharedmem_size_changed (sharedmem_t *inst);
00206 int sharedmem_lock (sharedmem_t *inst);
00213 int sharedmem_unlock (sharedmem_t *inst);
00220 int sharedmem_get_error_code (sharedmem_t *inst);
00227 const char * sharedmem_get_error_string (sharedmem_t *inst);
00228 
00229 
00230 #ifdef __cplusplus
00231 }
00232 #endif
00233 
00234 #endif

Generated on Thu Sep 13 18:14:21 2007 for libsharedmem by  doxygen 1.5.1