/* default screen */
memset(shared_memory, 0x00, (size_t)shm_size);
- printf("Memory attached at 0x%X\n", (int)shared_memory);
+ INFO("Memory attached at 0x%X\n", (int)shared_memory);
}
void maruskin_shm_quit(void)
{
+ struct shmid_ds shm_info;
+
INFO("maru shm quit\n");
+ if (shmctl(skin_shmid, IPC_STAT, &shm_info) == -1) {
+ ERR("shmctl failed\n");
+ shm_info.shm_nattch = -1;
+ }
+
if (shmdt(shared_memory) == -1) {
ERR("shmdt failed\n");
perror("maru_vga: ");
+ return;
}
shared_memory = NULL;
- if (shmctl(skin_shmid, IPC_RMID, 0) == -1) {
- INFO("segment was already removed\n");
- perror("maru_vga: ");
+ if (shm_info.shm_nattch == 1) {
+ /* remove */
+ if (shmctl(skin_shmid, IPC_RMID, 0) == -1) {
+ INFO("segment was already removed\n");
+ perror("maru_vga: ");
+ } else {
+ INFO("shared memory was removed\n");
+ }
+ } else if (shm_info.shm_nattch != -1) {
+ INFO("number of current attaches = %d\n",
+ (int)shm_info.shm_nattch);
}
}
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
- * of the License, or ( at your option ) any later version.
+ * of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
return 2;
}
- fprintf(stdout, "Memory attached at 0x%X\n", (int)shared_memory);
+ fprintf(stdout, "share.c: memory attached at 0x%X\n",
+ (int)shared_memory);
fflush(stdout);
return 0;
JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_shmdt
(JNIEnv *env, jobject obj)
{
+ struct shmid_ds shm_info;
+
+ if (shmctl(shmid, IPC_STAT, &shm_info) == -1) {
+ fprintf(stderr, "share.c: shmctl failed\n");
+ fflush(stderr);
+ perror("share.c: ");
+
+ shm_info.shm_nattch = -1;
+ }
+
fprintf(stdout, "share.c: clean up the shared memory\n");
fflush(stdout);
}
shared_memory = NULL;
- /*
- if (shmctl(shmid, IPC_RMID, 0) == -1) {
- fprintf(stdout, "share.c: segment was already removed\n");
+ if (shm_info.shm_nattch == 1) {
+ /* remove */
+ if (shmctl(shmid, IPC_RMID, 0) == -1) {
+ fprintf(stdout, "share.c: segment was already removed\n");
+ fflush(stdout);
+ perror("share.c: ");
+ return 2;
+ }
+ } else if (shm_info.shm_nattch != -1) {
+ fprintf(stdout, "share.c: number of current attaches = %d\n",
+ (int)shm_info.shm_nattch);
fflush(stdout);
- perror("share.c: ");
- return 2;
}
- */
return 0;
}
if (answer == SWT.OK) {
logger.info("force close!!!");
+
+ if (communicator != null) {
+ communicator.terminate();
+ }
+
System.exit(-1);
}
}
}
+ if (isTerminated) {
+ list.clear();
+ break;
+ }
+
for ( SkinSendData data : list ) {
sendToQEMUInternal( data );
}
list.clear();
-
- if ( isTerminated ) {
- break;
- }
-
}
}
break;
}
}
-
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
break;
}
+ logger.info("communicatorThread is stopped");
}
private void receiveData(
@Override
public void terminate() {
- isTerminated = true;
+ if (isTerminated == true) {
+ logger.info("has been terminated");
+ return;
+ }
+
logger.info("terminated");
+ isTerminated = true;
+
if (null != sendQueue) {
synchronized (sendQueue) {
sendQueue.notifyAll();
if (null != heartbeatTimer) {
heartbeatTimer.cancel();
+ heartbeatTimer = null;
}
IOUtil.closeSocket(socket);
/**
*
*
- * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
* GiWoong Kim <giwoong.kim@samsung.com>
*
*/
public class IOUtil {
+ private IOUtil() {
+ /* do nothing */
+ }
- private IOUtil(){}
-
- public static void closeSocket( Socket socket ) {
+ public static void closeSocket(Socket socket) {
try {
- if ( null != socket ) {
+ if (null != socket) {
socket.close();
+ socket = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
- public static void close( Closeable closeable ) {
+ public static void close(Closeable closeable) {
try {
- if ( null != closeable ) {
+ if (null != closeable) {
closeable.close();
}
} catch (IOException e) {
}
}
- public static byte[] getBytes( InputStream is ) throws IOException {
-
+ public static byte[] getBytes(InputStream is) throws IOException {
ByteArrayOutputStream bao = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int read = 0;
- while( 0 < ( read = is.read( buffer ) ) ) {
- bao.write( buffer, 0, read );
+ while(0 < (read = is.read(buffer))) {
+ bao.write(buffer, 0, read);
}
-
+
return bao.toByteArray();
-
}
-
}