[Aptitude-svn-commit] r4034 - in branches/aptitude-0.3/aptitude: .
src/generic
Daniel Burrows
dburrows at costa.debian.org
Thu Sep 1 22:48:19 UTC 2005
Author: dburrows
Date: Thu Sep 1 22:48:17 2005
New Revision: 4034
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/generic/threads.h
Log:
Add a convenience box proxy.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Thu Sep 1 22:48:17 2005
@@ -1,5 +1,10 @@
2005-09-01 Daniel Burrows <dburrows at debian.org>
+ * src/generic/threads.h:
+
+ Add a convenience box proxy that stores a pointer and deletes it
+ when destroyed (if it's full).
+
* src/generic/event_queue.h, src/generic/threads.h, tests/test_threads.cc:
Add support for timed waits.
Modified: branches/aptitude-0.3/aptitude/src/generic/threads.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/threads.h (original)
+++ branches/aptitude-0.3/aptitude/src/generic/threads.h Thu Sep 1 22:48:17 2005
@@ -640,6 +640,62 @@
val = new_val;
cond.wake_one();
}
+
+ // A ptr_box is like a box, but it wraps a pointer to its internal
+ // object. When a filled ptr_box is destroyed, it deletes the
+ // pointer that it contains.
+ template<typename T>
+ class ptr_box
+ {
+ box<T *> b;
+ public:
+ ptr_box()
+ {
+ }
+
+ ptr_box(const T *val)
+ :b(val)
+ {
+ }
+
+ ~ptr_box()
+ {
+ T *x;
+
+ if(b.try_get(x))
+ delete x;
+ }
+
+ T *take()
+ {
+ return b.take();
+ }
+
+ bool try_take(const T * &out)
+ {
+ return b.try_take(out);
+ }
+
+ bool timed_take(const T * &out, const timespec &until)
+ {
+ return b.timed_take(out);
+ }
+
+ void put(const T *in)
+ {
+ b.put(in);
+ }
+
+ bool try_put(const T *in)
+ {
+ return b.try_put(in);
+ }
+
+ bool timed_put(const T *in, const timespec &until)
+ {
+ return b.timed_put(in, until);
+ }
+ };
}
#endif
More information about the Aptitude-svn-commit
mailing list