mfapi - an API set for using shared memory

API declaration:

int mfopen(MFILE* mfp, char* pathname, int size);
int mfclose(MFILE* mfp);
int mflock(MFILE* mfp);
int mfunlock(MFILE* mfp);
int mftrylock(MFILE* mfp);
void mfreset(MFILE* mfp);
void* mfpoint(MFILE* mfp); /* get mf pointed memory */

One Example:

#include "mfapi.h"

int main(int argc, char** argv)
{
MFILE mf;
int ret;

setbuf(stdout,NULL);

mfopen(&mf,"test",1024);
mfdump(&mf);

printf("this operation %s lock\n",mftrylock(&mf) ? "will" : "will not");
mflock(&mf);
int* val = (int*) mfpoint(&mf);
printf("val[%d]\n",*val);
if(argc == 2)
sleep(atoi(argv[1]));
*val = time(NULL);
printf("val[%d]\n",*val);
mfdump(&mf);
mfunlock(&mf);

#if (0000)
mfreset(&mf);
mfclose(&mf);
#endif
}

AttachmentSize
mfapi-20080502a-normal-backup.tgz1.48 KB