Changeset 58
- Timestamp:
- 07/31/08 12:48:30
(4 months ago)
- Author:
- jtang
- Message:
Made Java functions synchronized (otherwise Bad Things (TM) happen).
Clean up of Java test programs.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r57 |
r58 |
|
| 81 | 81 | * the system IPC resource. |
|---|
| 82 | 82 | */ |
|---|
| 83 | | public void DestroyHandle() { |
|---|
| | 83 | public synchronized void DestroyHandle() { |
|---|
| 84 | 84 | this.Close(); |
|---|
| 85 | 85 | sipcwrapper.sipc_unlink(key, ipc_type); |
|---|
| … | … | |
| 92 | 92 | * false otherwise |
|---|
| 93 | 93 | */ |
|---|
| 94 | | public boolean IsConnected() { |
|---|
| | 94 | public synchronized boolean IsConnected() { |
|---|
| 95 | 95 | return this.isConnected; |
|---|
| 96 | 96 | } |
|---|
| … | … | |
| 100 | 100 | * effect if the handle is already in a disconnected state. |
|---|
| 101 | 101 | */ |
|---|
| 102 | | public void Close() { |
|---|
| | 102 | public synchronized void Close() { |
|---|
| 103 | 103 | if (isConnected) { |
|---|
| 104 | 104 | handle.close(); |
|---|
| … | … | |
| 114 | 114 | * implemented by all backends. |
|---|
| 115 | 115 | */ |
|---|
| 116 | | public void RecvDone() throws Exception {} |
|---|
| | 116 | public synchronized void RecvDone() throws Exception {} |
|---|
| 117 | 117 | |
|---|
| 118 | 118 | /** |
|---|
| … | … | |
| 125 | 125 | * read. |
|---|
| 126 | 126 | */ |
|---|
| 127 | | public byte[] ReadData() throws Exception { |
|---|
| | 127 | public synchronized byte[] ReadData() throws Exception { |
|---|
| 128 | 128 | if (isConnected) { |
|---|
| 129 | 129 | return handle.recv_data(); |
|---|
| … | … | |
| 142 | 142 | * @return A reference to the IPC handle's internal data buffer. |
|---|
| 143 | 143 | */ |
|---|
| 144 | | public java.nio.ByteBuffer GetDataPtr() throws Exception { |
|---|
| | 144 | public synchronized java.nio.ByteBuffer GetDataPtr() throws Exception { |
|---|
| 145 | 145 | if (isConnected) { |
|---|
| 146 | 146 | /* cache the dataPtr, to avoid re-creating it for |
|---|
| … | … | |
| 166 | 166 | * @param len Length of the message to be sent. |
|---|
| 167 | 167 | */ |
|---|
| 168 | | public void SendData(int len) throws Exception { |
|---|
| | 168 | public synchronized void SendData(int len) throws Exception { |
|---|
| 169 | 169 | if (isConnected) { |
|---|
| 170 | 170 | java.nio.ByteBuffer b = GetDataPtr(); |
|---|
| … | … | |
| 185 | 185 | * connected state for this to succeed. |
|---|
| 186 | 186 | */ |
|---|
| 187 | | public void SendData() throws Exception { |
|---|
| | 187 | public synchronized void SendData() throws Exception { |
|---|
| 188 | 188 | if (isConnected) { |
|---|
| 189 | 189 | handle.send_data(dataPtr.limit()); |
|---|
| … | … | |
| 201 | 201 | * set the channel to not block when reading. |
|---|
| 202 | 202 | */ |
|---|
| 203 | | public void IOCtl(int request) throws Exception { |
|---|
| | 203 | public synchronized void IOCtl(int request) throws Exception { |
|---|
| 204 | 204 | if (isConnected) { |
|---|
| 205 | 205 | handle.ioctl(request); |
|---|
| r54 |
r58 |
|
| 47 | 47 | * successfully received and handled. |
|---|
| 48 | 48 | */ |
|---|
| 49 | | public void RecvDone() throws Exception { |
|---|
| | 49 | public synchronized void RecvDone() throws Exception { |
|---|
| 50 | 50 | if (isConnected) { |
|---|
| 51 | 51 | handle.shm_recv_done(); |
|---|
| r52 |
r58 |
|
| 6 | 6 | fi |
|---|
| 7 | 7 | JFLAGS='-cp ../libsipc-1.0.jar:. -Djava.library.path=..' |
|---|
| | 8 | |
|---|
| | 9 | MQ_TEST_FILE=Makefile |
|---|
| | 10 | SHM_TEST_FILE=../sipc_wrap.c |
|---|
| 8 | 11 | |
|---|
| 9 | 12 | set -e |
|---|
| … | … | |
| 15 | 18 | |
|---|
| 16 | 19 | echo -n " sending..." |
|---|
| 17 | | ${JAVA} ${JFLAGS} MQ_Sender Makefile |
|---|
| | 20 | ${JAVA} ${JFLAGS} MQ_Sender ${MQ_TEST_FILE} |
|---|
| 18 | 21 | echo " pass" |
|---|
| 19 | 22 | |
|---|
| 20 | 23 | echo -n " reading..." |
|---|
| 21 | 24 | ${JAVA} ${JFLAGS} MQ_Reader |
|---|
| 22 | | diff Makefile out.dat || (echo " diff failed" ; exit 1) |
|---|
| | 25 | diff ${MQ_TEST_FILE} out.dat || (echo " diff failed" ; exit 1) |
|---|
| 23 | 26 | echo " pass" |
|---|
| 24 | 27 | |
|---|
| 25 | 28 | echo -n " destroying..." |
|---|
| 26 | 29 | ${JAVA} ${JFLAGS} MQ_Destroyer && echo " pass" |
|---|
| 27 | | |
|---|
| | 30 | exit 0 |
|---|
| 28 | 31 | echo "Testing Shared Memory:" |
|---|
| 29 | 32 | |
|---|
| … | … | |
| 32 | 35 | |
|---|
| 33 | 36 | echo " sending (as a background process)..." |
|---|
| 34 | | ${JAVA} ${JFLAGS} SHM_Sender ../sipc_wrap.c & |
|---|
| | 37 | ${JAVA} ${JFLAGS} SHM_Sender ${SHM_TEST_FILE} & |
|---|
| 35 | 38 | |
|---|
| 36 | 39 | sleep 1 |
|---|
| … | … | |
| 39 | 42 | # because shm does not set the proper number of bytes read, truncate the |
|---|
| 40 | 43 | # output here |
|---|
| 41 | | bytes=$(wc -c ../sipc_wrap.c | cut -f 1 -d ' ') |
|---|
| | 44 | bytes=$(wc -c ${SHM_TEST_FILE} | cut -f 1 -d ' ') |
|---|
| 42 | 45 | dd if=out.dat of=out.trimmed count=1 bs=${bytes} > /dev/null 2>&1 |
|---|
| 43 | | result=$(diff ../sipc_wrap.c out.trimmed) |
|---|
| | 46 | result=$(diff ${SHM_TEST_FILE} out.trimmed) |
|---|
| 44 | 47 | if test ${result}; then |
|---|
| 45 | 48 | echo " diff failed" |
|---|
Download in other formats:
* Generating other formats may take time.