got rid of all the absolute paths in the fitpc code
Previously, there were 2 places (BinaryLogReader and the HTTP file server) that
had "/home/driver/" hard coded. I changed both of those to use paths relative to
the location of the executable (retrieved from /proc/self/exe).
git-svn-id: https://robotics.mvla.net/svn/frc971/2013/trunk/src@4162 f308d9b7-e957-4cde-b6ac-9a88185e7312
diff --git a/aos/common/once-tmpl.h b/aos/common/once-tmpl.h
new file mode 100644
index 0000000..9b9c8c5
--- /dev/null
+++ b/aos/common/once-tmpl.h
@@ -0,0 +1,47 @@
+#ifdef __VXWORKS__
+#include <taskLib.h>
+#else
+#include <sched.h>
+#endif
+
+#include "aos/common/type_traits.h"
+
+// It doesn't use pthread_once, because Brian looked at the pthreads
+// implementation for vxworks and noticed that it is completely and entirely
+// broken for doing just about anything (including its pthread_once). It has the
+// same implementation on the atom for simplicity.
+
+namespace aos {
+
+// Setting function_ multiple times would be OK because it'll get set to the
+// same value each time.
+template<typename T>
+Once<T>::Once(Function function)
+ : function_(function) {
+ static_assert(shm_ok<Once<T>>::value, "Once should work in shared memory");
+}
+
+template<typename T>
+void Once<T>::Reset() {
+ done_ = false;
+ run_ = 0;
+}
+
+template<typename T>
+T *Once<T>::Get() {
+ if (__sync_lock_test_and_set(&run_, 1) == 0) {
+ result_ = function_();
+ done_ = true;
+ } else {
+ while (!done_) {
+#ifdef __VXWORKS__
+ taskDelay(1);
+#else
+ sched_yield();
+#endif
+ }
+ }
+ return result_;
+}
+
+} // namespace aos