got everything compiling (should still work too) with aos
diff --git a/aos/build/download_externals.sh b/aos/build/download_externals.sh
index ef843e1..5e07d02 100755
--- a/aos/build/download_externals.sh
+++ b/aos/build/download_externals.sh
@@ -60,3 +60,32 @@
CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
bash -c "cd ${CTEMPLATE_DIR} && ./configure --disable-shared \
--prefix=`readlink -f ${CTEMPLATE_PREFIX}` && make && make install"
+
+# get and build gflags
+GFLAGS_VERSION=2.0
+GFLAGS_DIR=${EXTERNALS}/gflags-${GFLAGS_VERSION}
+GFLAGS_PREFIX=${GFLAGS_DIR}-prefix
+GFLAGS_LIB=${GFLAGS_PREFIX}/lib/libgflags.a
+GFLAGS_URL=https://gflags.googlecode.com/files/gflags-${GFLAGS_VERSION}.tar.gz
+[ -f ${GFLAGS_DIR}.tar.gz ] || wget ${GFLAGS_URL} -O ${GFLAGS_DIR}.tar.gz
+[ -d ${GFLAGS_DIR} ] || ( mkdir ${GFLAGS_DIR} && tar \
+ --strip-components=1 -C ${GFLAGS_DIR} -xf ${GFLAGS_DIR}.tar.gz )
+[ -f ${GFLAGS_LIB} ] || env -i PATH="${PATH}" \
+ CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
+ bash -c "cd ${GFLAGS_DIR} && ./configure \
+ --prefix=`readlink -f ${GFLAGS_PREFIX}` && make && make install"
+
+# get and build libusb
+LIBUSB_VERSION=1.0.9
+LIBUSB_APIVERSION=1.0
+LIBUSB_DIR=${EXTERNALS}/libusb-${LIBUSB_VERSION}
+LIBUSB_PREFIX=${LIBUSB_DIR}-prefix
+LIBUSB_LIB=${LIBUSB_PREFIX}/lib/libusb-${LIBUSB_APIVERSION}.a
+LIBUSB_URL=http://sourceforge.net/projects/libusb/files/libusb-${LIBUSB_APIVERSION}/libusb-${LIBUSB_VERSION}/libusb-${LIBUSB_VERSION}.tar.bz2
+[ -f ${LIBUSB_DIR}.tar.bz2 ] || wget ${LIBUSB_URL} -O ${LIBUSB_DIR}.tar.bz2
+[ -d ${LIBUSB_DIR} ] || ( mkdir ${LIBUSB_DIR} && tar \
+ --strip-components=1 -C ${LIBUSB_DIR} -xf ${LIBUSB_DIR}.tar.bz2 )
+[ -f ${LIBUSB_LIB} ] || env -i PATH="${PATH}" \
+ CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' \
+ bash -c "cd ${LIBUSB_DIR} && ./configure \
+ --prefix=`readlink -f ${LIBUSB_PREFIX}` && make && make install"
diff --git a/aos/build/externals.gyp b/aos/build/externals.gyp
index eb19cd0..ad6a886 100644
--- a/aos/build/externals.gyp
+++ b/aos/build/externals.gyp
@@ -10,6 +10,9 @@
'gtest_version': '1.6.0-p1',
'onejar_version': '0.97',
'ctemplate_version': '2.2',
+ 'gflags_version': '2.0',
+ 'libusb_version': '1.0.9',
+ 'libusb_apiversion': '1.0',
},
'targets': [
{
@@ -139,11 +142,31 @@
'target_name': 'ctemplate',
'type': 'none',
'link_settings': {
- 'libraries': ['<(externals)/ctemplate-<(ctemplate_version)-prefix/lib/libctemplate.a'],
+ 'libraries': ['<(externals_abs)/ctemplate-<(ctemplate_version)-prefix/lib/libctemplate.a'],
},
'direct_dependent_settings': {
'include_dirs': ['<(externals)/ctemplate-<(ctemplate_version)-prefix/include'],
},
},
+ {
+ 'target_name': 'gflags',
+ 'type': 'none',
+ 'link_settings': {
+ 'libraries': ['<(externals_abs)/gflags-<(gflags_version)-prefix/lib/libgflags.a'],
+ },
+ 'direct_dependent_settings': {
+ 'include_dirs': ['<(externals)/gflags-<(gflags_version)-prefix/include'],
+ },
+ },
+ {
+ 'target_name': 'libusb',
+ 'type': 'none',
+ 'link_settings': {
+ 'libraries': ['<(externals_abs)/libusb-<(libusb_version)-prefix/lib/libusb-<(libusb_apiversion).a'],
+ },
+ 'direct_dependent_settings': {
+ 'include_dirs': ['<(externals)/libusb-<(libusb_version)-prefix/include'],
+ },
+ },
],
}
diff --git a/aos/common/common.gyp b/aos/common/common.gyp
index 967eb51..4265b18 100644
--- a/aos/common/common.gyp
+++ b/aos/common/common.gyp
@@ -151,6 +151,7 @@
'queue_testutils',
'common',
'queue_test_queue',
+ '<(AOS)/common/util/util.gyp:thread',
],
},
{
diff --git a/aos/common/queue_test.cc b/aos/common/queue_test.cc
index b24fcd5..65a1c25 100644
--- a/aos/common/queue_test.cc
+++ b/aos/common/queue_test.cc
@@ -5,53 +5,12 @@
#include "gtest/gtest.h"
#include "aos/common/test_queue.q.h"
#include "aos/common/queue_testutils.h"
-
+#include "aos/common/util/thread.h"
using ::aos::time::Time;
namespace aos {
namespace common {
-
-// TODO(aschuh): Pull this out somewhere and test it.
-class Thread {
- public:
- Thread () {
- started_ = false;
- joined_ = false;
- }
-
- ~Thread() {
- if (!joined_ && started_) {
- assert(false);
- }
- }
-
- void Start() {
- assert(!started_);
- pthread_create(&thread_, NULL, &Thread::StaticRun, this);
- started_ = true;
- }
-
- virtual void Run() = 0;
-
- void Join() {
- assert(!joined_);
- pthread_join(thread_, NULL);
- joined_ = true;
- }
- private:
- static void *StaticRun(void *thread_class) {
- static_cast<Thread *>(thread_class)->Run();
- return NULL;
- }
-
- pthread_t thread_;
- bool started_;
- bool joined_;
-
- DISALLOW_COPY_AND_ASSIGN(Thread);
-};
-
namespace testing {
class QueueTest : public ::testing::Test {
@@ -65,7 +24,7 @@
QueueTest() : my_test_queue(".aos.common.testing.test_queue") {}
};
-class MyThread : public Thread {
+class MyThread : public util::Thread {
public:
MyThread() : threaded_test_queue(".aos.common.testing.test_queue") {}
diff --git a/aos/common/util/thread.cc b/aos/common/util/thread.cc
new file mode 100644
index 0000000..fab62eb
--- /dev/null
+++ b/aos/common/util/thread.cc
@@ -0,0 +1,39 @@
+#include "aos/common/util/thread.h"
+
+#include <pthread.h>
+#include <assert.h>
+
+namespace aos {
+namespace util {
+
+Thread::Thread() : started_(false), joined_(false), should_terminate_(false) {}
+
+Thread::~Thread() {
+ if (started_ && !joined_) {
+ assert(false);
+ }
+}
+
+void Thread::Start() {
+ assert(!started_);
+ started_ = true;
+ assert(pthread_create(&thread_, NULL, &Thread::StaticRun, this) == 0);
+}
+
+void Thread::Join() {
+ assert(!joined_ && started_);
+ joined_ = true;
+ {
+ MutexLocker locker(&should_terminate_mutex_);
+ should_terminate_ = true;
+ }
+ assert(pthread_join(thread_, NULL) == 0);
+}
+
+void *Thread::StaticRun(void *self) {
+ static_cast<Thread *>(self)->Run();
+ return NULL;
+}
+
+} // namespace util
+} // namespace aos
diff --git a/aos/common/util/thread.h b/aos/common/util/thread.h
new file mode 100644
index 0000000..10867ec
--- /dev/null
+++ b/aos/common/util/thread.h
@@ -0,0 +1,50 @@
+#ifndef AOS_COMMON_UTIL_THREAD_H_
+#define AOS_COMMON_UTIL_THREAD_H_
+
+#include "aos/common/mutex.h"
+
+namespace aos {
+namespace util {
+
+// A nice wrapper around a pthreads thread.
+//
+// TODO(aschuh): Test this.
+class Thread {
+ public:
+ Thread();
+ ~Thread();
+
+ // Actually creates the thread.
+ void Start();
+
+ // Asks the code to stop and then waits until it has done so.
+ void Join();
+
+ protected:
+ // Subclasses need to call this periodically if they are going to loop to
+ // check whether they have been asked to stop.
+ bool should_continue() {
+ MutexLocker locker(&should_terminate_mutex_);
+ return !should_terminate_;
+ }
+
+ private:
+ // Where subclasses actually do something.
+ //
+ // They should not block for long periods of time without checking
+ // should_continue().
+ virtual void Run() = 0;
+
+ static void *StaticRun(void *self);
+
+ pthread_t thread_;
+ bool started_;
+ bool joined_;
+ bool should_terminate_;
+ Mutex should_terminate_mutex_;
+};
+
+} // namespace util
+} // namespace aos
+
+#endif // AOS_COMMON_UTIL_THREAD_H_
diff --git a/aos/common/util/util.gyp b/aos/common/util/util.gyp
index 15f868f..c00b9e3 100644
--- a/aos/common/util/util.gyp
+++ b/aos/common/util/util.gyp
@@ -1,6 +1,19 @@
{
'targets': [
{
+ 'target_name': 'thread',
+ 'type': 'static_library',
+ 'sources': [
+ 'thread.cc',
+ ],
+ 'dependencies': [
+ '<(AOS)/common/common.gyp:mutex',
+ ],
+ 'export_dependent_settings': [
+ '<(AOS)/common/common.gyp:mutex',
+ ],
+ },
+ {
'target_name': 'trapezoid_profile',
'type': 'static_library',
'sources': [
diff --git a/aos/externals/.gitignore b/aos/externals/.gitignore
index 3417a33..7f6c98d 100644
--- a/aos/externals/.gitignore
+++ b/aos/externals/.gitignore
@@ -15,3 +15,9 @@
/libjpeg/
/ninja/
/one-jar-boot-0.97.jar
+/gflags-2.0-prefix/
+/gflags-2.0.tar.gz
+/gflags-2.0/
+/libusb-1.0.9-prefix/
+/libusb-1.0.9.tar.bz2
+/libusb-1.0.9/