tests/auto/qtipc/lackey/scripts/producer.js
branchRCL_3
changeset 7 3f74d0d4af4c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/auto/qtipc/lackey/scripts/producer.js	Thu Apr 08 14:19:33 2010 +0300
@@ -0,0 +1,44 @@
+function QVERIFY(x, debugInfo) {
+    if (!(x)) {
+        print(debugInfo);
+        throw(debugInfo);
+    }
+}
+
+var producer = new ScriptSharedMemory;
+producer.setKey("market");
+
+var size = 1024;
+if (!producer.create(size)) {
+    QVERIFY(producer.error() == 4, "create");
+    QVERIFY(producer.attach());
+}
+//print ("producer created and attached");
+
+QVERIFY(producer.lock());
+producer.set(0, 'Q');
+QVERIFY(producer.unlock());
+
+var i = 0;
+while(i < 5) {
+    QVERIFY(producer.lock(), "lock");
+    if (producer.get(0) == 'Q') {
+        QVERIFY(producer.unlock(), "unlock");
+        producer.sleep(1);
+        continue;
+    }
+    //print("producer: " + i);
+    ++i;
+    producer.set(0, 'Q');
+    QVERIFY(producer.unlock(), "unlock");
+    producer.sleep(1);
+}
+QVERIFY(producer.lock());
+producer.set(0, 'E');
+QVERIFY(producer.unlock());
+
+//print ("producer done");
+
+// Sleep for a bit to let all consumers start, otherwise they will get stuck in the attach loop,
+// because at least in Symbian the shared memory will be destroyed if there are no active handles to it.
+producer.sleep(3000);
\ No newline at end of file