summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsharedmemory/lackey/scripts/producer.js
blob: 88b2b80905e2898f160de8691d45094a7cae17dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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");

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");