#endif
#ifdef CONFIG_USE_SHM
-void *shared_memory = (void*)0;
+void *shared_memory = (void*) 0;
+int shmid;
#endif
+
MULTI_DEBUG_CHANNEL(qemu, maru_vga);
extern pthread_mutex_t mutex_screenshot;
/* for screenshot */
pthread_mutex_lock(&mutex_screenshot);
MaruScreenshot* maru_screenshot = get_maru_screenshot();
- if ( !maru_screenshot ) {
- ERR( "maru screenshot is NULL.\n" );
+
+ if (!maru_screenshot) {
+ ERR("maru screenshot is NULL.\n");
} else {
if (maru_screenshot->request_screenshot == 1) {
memcpy(maru_screenshot->pixel_data, s->ds->surface->data,
s->ds->surface->linesize * s->ds->surface->height);
maru_screenshot->request_screenshot = 0;
+
pthread_cond_signal(&cond_screenshot);
}
}
#ifdef CONFIG_USE_SHM
int mykey;
void *temp;
- int shmid;
shmid = shmget((key_t)SHMKEY, (size_t)MAXLEN, 0666 | IPC_CREAT);
if (shmid == -1) {
- ERR( "shmget failed\n");
+ ERR("shmget failed\n");
perror("maru_vga: ");
exit(1);
}
temp = shmat(shmid, (char*)0x0, 0);
if (temp == (void *)-1) {
- ERR( "shmat failed\n");
+ ERR("shmat failed\n");
perror("maru_vga: ");
exit(1);
}
mykey = atoi(temp);
shmdt(temp);
INFO("shared memory key: %d, vga ram_size : %d\n", mykey, s->vram_size);
+
shmid = shmget((key_t)mykey, (size_t)s->vram_size, 0666 | IPC_CREAT);
if (shmid == -1) {
- ERR( "shmget failed\n");
+ ERR("shmget failed\n");
perror("maru_vga: ");
maru_register_exit_msg(MARU_EXIT_UNKNOWN, (char*)"Cannot launch this VM.\n"
"Shared memory is not enough.");
shared_memory = shmat(shmid, (void*)0, 0);
if (shared_memory == (void *)-1) {
- ERR( "shmat failed\n");
+ ERR("shmat failed\n");
perror("maru_vga: ");
exit(1);
}
}
+#ifdef CONFIG_USE_SHM
+void maru_vga_common_fini(void)
+{
+ if (shmdt(shared_memory) == -1) {
+ ERR("shmdt failed\n");
+ perror("maru_vga: ");
+ }
+
+ if (shmctl(shmid, IPC_RMID, 0) == -1) {
+ ERR("shmctl failed\n");
+ perror("maru_vga: ");
+ }
+}
+#endif
static const MemoryRegionPortio vga_portio_list[] = {
{ 0x04, 2, 1, .read = vga_ioport_read, .write = vga_ioport_write }, /* 3b4 */
private int[] array;
private ImageData imageData;
private Image framebuffer;
- private EmulatorFingers finger;
private volatile boolean stopRequest;
private Runnable runnable;
public PollFBThread(EmulatorFingers finger, int lcdWidth, int lcdHeight) {
- this.finger = finger;
this.display = Display.getDefault();
this.lcdWidth = lcdWidth;
this.lcdHeight = lcdHeight;
while (!stopRequest) {
synchronized (this) {
try {
- this.wait(30); //30ms
- } catch (InterruptedException ex) {
+ this.wait(30); /* 30ms */
+ } catch (InterruptedException e) {
+ e.printStackTrace();
break;
}
}
- int result = getPixels(array); //from shared memory
- //logger.info("getPixels navtive function returned " + result);
+ int result = getPixels(array); /* from shared memory */
+ //logger.info("getPixels native function returned " + result);
for (int i = 0; i < lcdHeight; i++) {
imageData.setPixels(0, i, lcdWidth, array, i * lcdWidth);
Image temp = framebuffer;
framebuffer = new Image(display, imageData);
temp.dispose();
+
if(display.isDisposed() == false) {
- display.asyncExec(runnable); //redraw canvas
+ /* redraw canvas */
+ display.asyncExec(runnable);
}
}
- //logger.info("PollFBThread is stopped");
+ logger.info("PollFBThread is stopped");
+
+ int result = shmdt();
+ logger.info("shmdt native function returned " + result);
}
public void stopRequest() {
int result = shmget(
currentState.getCurrentResolutionWidth() *
currentState.getCurrentResolutionHeight());
- //logger.info("shmget navtive function returned " + result);
+ logger.info("shmget native function returned " + result);
/* update lcd thread */
pollThread = new PollFBThread(finger,
finger.drawImage(e, currentState.getCurrentAngle());
}
});
-
- pollThread.start();
+
+ pollThread.start();
return 0;
}