int main (int argc,char* argv[]) { //main ss int semid,shmid; char *shmaddr; char write_str[SHM_SIZE]; memset(write_str,SHM_SIZE,'\0'); if ((shmid = createshm(".",'m',SHM_SIZE)) == -1) { exit(-1); } if((shmaddr = shmat(shmid,(char*)0,0)) == (char*)-1) { cout << "shmat error" << endl; } if((semid =(createsem(".",'s',1,1)))==-1) { exit(-1); } while(1) { wait_sem(semid,0); sem_P(semid,0); cout << "writer:"<< "do something here" << endl; fgets(write_str,1024,stdin); int length = strlen(write_str); write_str[len]='\0'; strncpy(shmaddr,write_str,len+1); sleep(10); } return 0; }
int main() { int semid, shmid; char *shmaddr; if ((shmid = createshm(".", 'm', SHM_SIZE)) == -1){ exit (1); } if((shmaddr = shmat (shmid, (char *)0, 0)) == (char *)-1){ perror ("attach shared memory error!\n"); exit (1); } if((semid = opensem("." ,'s')) == -1){ exit (1); } while(1){ printf("reader: "); sem_p(semid,0); /* P操作 */ printf("%s", shmaddr); sem_v(semid,0); /* V操作 */ } }
int main() { int semid,shmid; char *shmaddr=NULL; if((shmid=createshm(".",'m',SHM_SIZE))==-1) { exit(1); } if((shmaddr=shmat(shmid,(char*)0,0))==(char *)-1) { perror("attach shared memory error\n"); exit(1); } if((semid=opensem(".",'s'))==-1) { exit(1); } while(1) { waitsem(semid,0); p(semid,0); printf("reader:"); printf("%s\n",shmaddr); my_sleep(5); v(semid,0); // my_sleep(5); } }
main(int argc, char *argv[]) { if (argc != 3 || (strcmp(argv[1], "set") != 0 && strcmp(argv[1], "del") != 0 && strcmp(argv[1], "get") != 0 && strcmp(argv[1], "check") != 0 && strcmp(argv[1], "create") != 0 && strcmp(argv[1], "inc") != 0 && strcmp(argv[1], "dec") != 0)) { printf("Usage: %s create shm\n", argv[0]); printf("Usage: %s set variable=value\n", argv[0]); printf("Usage: %s del all\n", argv[0]); printf("Usage: %s del variable\n", argv[0]); printf("Usage: %s get all\n", argv[0]); printf("Usage: %s get variable\n", argv[0]); printf("Usage: %s inc variable\n", argv[0]); printf("Usage: %s dec variable\n", argv[0]); printf("Usage: %s check variable\n", argv[0]); exit(0); } char *shm = NULL; if (strcmp(argv[1], "create") == 0 && strcmp(argv[2], "shm") == 0) { shm = createshm(); if (shm == NULL) { perror("createshm"); exit(1); } printf("shared mem created\n"); exit(0); } shm = findshm(); if (shm == NULL) { perror("findshm"); exit(1); } if (strcmp(argv[1], "inc") == 0 && strcmp(argv[2], "all") != 0) { strcat(argv[2], "="); if (incshmentry(shm, argv[2]) != 1) { printf("error: value not set\n"); exit(1); } exit(0); } if (strcmp(argv[1], "dec") == 0 && strcmp(argv[2], "all") != 0) { strcat(argv[2], "="); if (decshmentry(shm, argv[2]) != 1) { printf("error: value not set\n"); exit(1); } exit(0); } if (strcmp(argv[1], "get") == 0 && strcmp(argv[2], "all") != 0) { char *shmbuf = NULL; shmbuf = malloc(256); strcat(argv[2], "="); getshmentry(shm, argv[2], shmbuf, 256); printf("%s\n", shmbuf); free(shmbuf); exit(0); } if (strcmp(argv[1], "get") == 0 && strcmp(argv[2], "all") == 0) { char *shmbuf = NULL; shmbuf = malloc(4096); getshmentryall(shm, shmbuf, 4096); printf("%s\n", shmbuf); free(shmbuf); exit(0); } if (strcmp(argv[1], "set") == 0) { if (setshmentry(shm, argv[2]) != 1) { printf("error: value not set\n"); exit(1); } exit(0); } if (strcmp(argv[1], "del") == 0 && strcmp(argv[2], "all") != 0) { strcat(argv[2], "="); delshmentry(shm, argv[2]); exit(0); } if (strcmp(argv[1], "del") == 0 && strcmp(argv[2], "all") == 0) { *shm = '\0'; exit(0); } if (strcmp(argv[1], "check") == 0) { strcat(argv[2], "="); if (checkshmentry(shm, argv[2]) == 0) printf("not exist\n"); else printf("exist\n"); exit(0); } exit(0); }
int main(int argc, char **argv) { #if defined(__sh__) // nits shm hack to behavior of e2 on the fly shm = findshm(); if(shm == NULL) shm = createshm(); #endif #ifdef MEMLEAK_CHECK atexit(DumpUnfreed); #endif #ifdef OBJECT_DEBUG atexit(object_dump); #endif #ifndef ENABLE_LIBEPLAYER3 gst_init(&argc, &argv); #endif // set pythonpath if unset setenv("PYTHONPATH", eEnv::resolve("${libdir}/enigma2/python").c_str(), 0); printf("PYTHONPATH: %s\n", getenv("PYTHONPATH")); bsodLogInit(); ePython python; eMain main; #if 1 ePtr<gMainDC> my_dc; gMainDC::getInstance(my_dc); //int double_buffer = my_dc->haveDoubleBuffering(); ePtr<gLCDDC> my_lcd_dc; gLCDDC::getInstance(my_lcd_dc); /* ok, this is currently hardcoded for arabic. */ /* some characters are wrong in the regular font, force them to use the replacement font */ for (int i = 0x60c; i <= 0x66d; ++i) eTextPara::forceReplacementGlyph(i); eTextPara::forceReplacementGlyph(0xfdf2); for (int i = 0xfe80; i < 0xff00; ++i) eTextPara::forceReplacementGlyph(i); eWidgetDesktop dsk(eSize(720, 576)); eWidgetDesktop dsk_lcd(my_lcd_dc->size()); dsk.setStyleID(0); #ifdef HAVE_GRAPHLCD dsk_lcd.setStyleID(my_lcd_dc->size().width() == 320 ? 1 : 2); #else dsk_lcd.setStyleID(my_lcd_dc->size().width() == 96 ? 2 : 1); #endif /* if (double_buffer) { eDebug(" - double buffering found, enable buffered graphics mode."); dsk.setCompositionMode(eWidgetDesktop::cmBuffered); } */ wdsk = &dsk; lcddsk = &dsk_lcd; dsk.setDC(my_dc); dsk_lcd.setDC(my_lcd_dc); ePtr<gPixmap> m_pm; loadPNG(m_pm, eEnv::resolve("${datadir}/enigma2/skin_default/pal.png").c_str()); if (!m_pm) { eFatal("pal.png not found!"); } else dsk.setPalette(*m_pm); dsk.setBackgroundColor(gRGB(0,0,0,0xFF)); #endif /* redrawing is done in an idle-timer, so we have to set the context */ dsk.setRedrawTask(main); dsk_lcd.setRedrawTask(main); eDebug("Loading spinners..."); { int i; #define MAX_SPINNER 64 ePtr<gPixmap> wait[MAX_SPINNER]; for (i=0; i<MAX_SPINNER; ++i) { char filename[64]; std::string rfilename; snprintf(filename, sizeof(filename), "${datadir}/enigma2/skin_default/spinner/wait%d.png", i + 1); rfilename = eEnv::resolve(filename); loadPNG(wait[i], rfilename.c_str()); if (!wait[i]) { if (!i) eDebug("failed to load %s! (%m)", rfilename.c_str()); else eDebug("found %d spinner!\n", i); break; } } if (i) my_dc->setSpinner(eRect(ePoint(100, 100), wait[0]->size()), wait, i); else my_dc->setSpinner(eRect(100, 100, 0, 0), wait, 1); } gRC::getInstance()->setSpinnerDC(my_dc); eRCInput::getInstance()->keyEvent.connect(slot(keyEvent)); #if defined(__sh__) // initialise the vfd class evfd * vfd = new evfd; vfd->init(); delete vfd; #endif printf("executing main\n"); bsodCatchSignals(); setIoPrio(IOPRIO_CLASS_BE, 3); // python.execute("mytest", "__main__"); python.execFile(eEnv::resolve("${libdir}/enigma2/python/mytest.py").c_str()); extern void setFullsize(); // definend in lib/gui/evideo.cpp setFullsize(); if (exit_code == 5) /* python crash */ { eDebug("(exit code 5)"); bsodFatal(0); } dsk.paint(); dsk_lcd.paint(); { gPainter p(my_lcd_dc); p.resetClip(eRect(ePoint(0, 0), my_lcd_dc->size())); p.clear(); p.flush(); } return exit_code; }