...
 
Commits (4)
......@@ -1022,6 +1022,38 @@ optional class Mutex
locks++;
return MutexKey (dec_locks);
}
Condition condition ()
{
return Condition(this);
}
}
// Fallback implementation of Thread.Condition.
class Condition (protected Mutex|void mutex)
{
variant void wait(MutexKey key, void|int|float seconds)
{
if (!seconds || seconds == 0.0) {
// To be really accurate we should hang now, but somehow
// that doesn't seem too useful.
error ("Deadlock detected.\n");
}
sleep(seconds);
}
variant void wait(MutexKey key, int seconds, int nanos)
{
wait(key, seconds + nanos*1e-9);
}
void signal()
{
}
void broadcast()
{
}
}
// Fallback implementation of Thread.Fifo.
......@@ -1125,6 +1157,7 @@ optional class Queue
mixed try_read()
{
if (w_ptr == r_ptr) return UNDEFINED;
mixed tmp=buffer[r_ptr];
buffer[r_ptr++] = 0; // Throw away any references.
return tmp;
......@@ -1160,6 +1193,11 @@ optional class Queue
return ret;
}
array peek_array()
{
return buffer[r_ptr..w_ptr-1];
}
int write(mixed value)
{
if(w_ptr >= sizeof(buffer))
......@@ -1180,4 +1218,58 @@ optional class Queue
}
}
// Fallback implementation of Thread.ResourceCountKey.
class ResourceCountKey {
private inherit __builtin.DestructImmediate;
/*semi*/private ResourceCount parent;
protected void create(ResourceCount _parent)
{
parent = _parent;
}
protected void destroy()
{
--parent->_count;
}
}
// Fallback implementation of Thread.ResourceCount.
class ResourceCount {
/*semi*/final int _count;
/*semi*/final int(0..1) drained(void|int level) {
return level >= _count;
}
/*semi*/final void wait_till_drained(void|int level) {
if (_count > level) {
// To be really accurate we should hang now, but somehow
// that doesn't seem too useful.
error ("Deadlock detected.\n");
}
}
/*semi*/final ResourceCountKey acquire() {
_count++;
return ResourceCountKey(this);
}
protected string _sprintf(int type)
{
string res = UNDEFINED;
switch(type) {
case 'O':
res = sprintf("Count: %d", _count);
break;
case 'd':
res = sprintf("%d", _count);
break;
}
return res;
}
}
#endif /* !constant(thread_create) */