got all of the code to actually compile again
I don't think it actually works though.
diff --git a/aos/common/common.gyp b/aos/common/common.gyp
index 442e4ac..c867193 100644
--- a/aos/common/common.gyp
+++ b/aos/common/common.gyp
@@ -21,7 +21,6 @@
'queue_testutils.cc',
],
'dependencies': [
- '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:ipc_lib',
'<(AOS)/build/aos.gyp:logging',
'once',
'<(EXTERNALS):gtest',
@@ -54,10 +53,10 @@
},
{
'dependencies': [
- '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:ipc_lib',
+ '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:queue',
],
'export_dependent_settings': [
- '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:ipc_lib',
+ '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:queue',
],
}]
],
@@ -216,6 +215,24 @@
],
},
{
+ 'target_name': 'condition',
+ 'type': 'static_library',
+ 'sources': [
+ '<(AOS)/atom_code/ipc_lib/condition.cc',
+ ],
+ 'dependencies': [
+ 'mutex',
+ '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:aos_sync',
+ # TODO(aschuh): Fix this dependency loop by
+ # providing a logging interface.
+ # '<(AOS)/build/aos.gyp:logging',
+ ],
+ 'export_dependent_settings': [
+ 'mutex',
+ '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:aos_sync',
+ ],
+ },
+ {
'target_name': 'mutex',
'type': 'static_library',
'conditions': [
@@ -228,10 +245,10 @@
'<(AOS)/atom_code/ipc_lib/mutex.cpp',
],
'dependencies': [
- '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:ipc_lib',
+ '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:aos_sync',
],
'export_dependent_settings': [
- '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:ipc_lib',
+ '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:aos_sync',
],
}],
],
diff --git a/aos/common/condition.h b/aos/common/condition.h
index c527f34..956dc6c 100644
--- a/aos/common/condition.h
+++ b/aos/common/condition.h
@@ -1,60 +1,41 @@
#ifndef AOS_COMMON_CONDITION_H_
#define AOS_COMMON_CONDITION_H_
-#ifdef __VXWORKS__
-#include <semLib.h>
-#endif
-
-#include "aos/aos_core.h"
#include "aos/common/mutex.h"
+#include "aos/atom_code/ipc_lib/aos_sync.h"
namespace aos {
// A condition variable (IPC mechanism where 1 process/task can notify all
// others that are waiting for something to happen).
-// There are implementations for both the atom and the cRIO.
-// They both LOG(FATAL) if anything weird happens.
+// This implementation will LOG(FATAL) if anything weird happens.
//
-// A condition is either set or unset, and multiple processes/tasks can wait on
-// one for it to be set.
+// Multiple condition variables may be associated with the same mutex but
+// exactly 1 mutex must be associated with each condition variable.
class Condition {
public:
- // Creates an unset condition.
- Condition();
-#ifdef __VXWORKS__
- // Will not make sure that it is either set or unset.
- ~Condition();
-#endif
- // Waits for the condition to be set. Will return true immediately if it is
- // already set.
- // Returns false if returning before a confirmed condition set, although doing
- // anything very useful with the return value is difficult because the
- // condition may have been set (and possibly even unset again) between the
- // time when the system call to block returned and this function returns.
- bool Wait();
- // Waits for the next Set(), regardless of whether or not the condition is
- // currently set.
- // Same return value as Wait().
- bool WaitNext();
+ // m is the mutex that will be associated with this condition variable.
+ explicit Condition(Mutex *m);
- // Sets the condition. Any processes/tasks that are currently Wait()ing will
- // continue.
- // All implementations will wake all waiting processes/tasks at once so that
- // the highest priority one(s) will run before others like usual.
- void Set();
- // Unsets the condition.
- void Unset();
+ // Waits for the condition variable to be signalled, atomically unlocking m at
+ // the same time. The mutex associated with this condition variable must be
+ // locked when this is called and will be locked when this method returns.
+ void Wait();
+
+ // Signals at most 1 other process currently Wait()ing on this condition
+ // variable. Calling this does not require the mutex associated with this
+ // condition variable to be locked.
+ // One of the processes with the highest priority level will be woken if there
+ // are multiple ones.
+ void Signal();
+ // Wakes all processes that are currently Wait()ing on this condition
+ // variable. Calling this does not require the mutex associated with this
+ // condition variable to be locked.
+ void Broadcast();
private:
-#ifdef __VXWORKS__
- // Always empty. Used to make tasks wait and then gets flushed to unblock all
- // of them.
- SEM_ID wait_;
- // Whether or not the conditon is set.
- bool set_;
-#else
- mutex impl_;
-#endif
+ condition_variable impl_;
+ Mutex *m_;
};
} // namespace aos
diff --git a/aos/common/macros.h b/aos/common/macros.h
index 88fc52e..2018b36 100644
--- a/aos/common/macros.h
+++ b/aos/common/macros.h
@@ -6,8 +6,8 @@
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
- TypeName(const TypeName&); \
- void operator=(const TypeName&)
+ TypeName(const TypeName&) = delete; \
+ void operator=(const TypeName&) = delete
// A macro to wrap arguments to macros that contain commas.
// Useful for DISALLOW_COPY_AND_ASSIGNing templated types with multiple template
// arguments.
diff --git a/aos/common/messages/messages.gyp b/aos/common/messages/messages.gyp
index 3b8d389..b76dbba 100644
--- a/aos/common/messages/messages.gyp
+++ b/aos/common/messages/messages.gyp
@@ -19,10 +19,10 @@
'conditions': [
['OS!="crio"', {
'dependencies': [
- '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:ipc_lib',
+ '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:queue',
],
'export_dependent_settings': [
- '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:ipc_lib',
+ '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:queue',
],
}],
],
diff --git a/aos/common/mutex.h b/aos/common/mutex.h
index 4c06aae..b6b277c 100644
--- a/aos/common/mutex.h
+++ b/aos/common/mutex.h
@@ -11,6 +11,8 @@
namespace aos {
+class Condition;
+
// An abstraction of a mutex that has implementations both for the
// atom and for the cRIO.
// If there are multiple tasks or processes contending for the mutex,
@@ -42,6 +44,9 @@
typedef mutex ImplementationType;
#endif
ImplementationType impl_;
+
+ friend class Condition; // for access to impl_
+
#ifdef __VXWORKS__
DISALLOW_COPY_AND_ASSIGN(Mutex);
#endif
diff --git a/aos/common/mutex_test.cpp b/aos/common/mutex_test.cpp
index 6af126b..7a5c2ce 100644
--- a/aos/common/mutex_test.cpp
+++ b/aos/common/mutex_test.cpp
@@ -9,7 +9,7 @@
#include "gtest/gtest.h"
-#include "aos/common/condition.h"
+#include "aos/atom_code/ipc_lib/aos_sync.h"
namespace aos {
namespace testing {
@@ -68,15 +68,15 @@
ASSERT_TRUE(test_mutex.TryLock());
test_mutex.Unlock();
}
- EXPECT_TRUE(test_mutex.TryLock());
+ EXPECT_FALSE(test_mutex.TryLock());
}
// A worker thread for testing the fairness of the mutex implementation.
class MutexFairnessWorkerThread {
public:
MutexFairnessWorkerThread(int *cycles, int index,
- Mutex *mutex, Condition *start)
- : cycles_(cycles), index_(index), mutex_(mutex), start_(start) {}
+ Mutex *in_mutex, mutex *start)
+ : cycles_(cycles), index_(index), mutex_(in_mutex), start_(start) {}
static void *RunStatic(void *self_in) {
MutexFairnessWorkerThread *self =
@@ -94,7 +94,7 @@
private:
void Run() {
cycles_[index_] = 0;
- start_->Wait();
+ ASSERT_EQ(futex_wait(start_), 0);
while (cyclesRun < totalCycles) {
{
MutexLocker locker(mutex_);
@@ -117,7 +117,7 @@
int *cycles_;
int index_;
Mutex *mutex_;
- Condition *start_;
+ mutex *start_;
static int cyclesRun, totalCycles;
};
int MutexFairnessWorkerThread::cyclesRun;
@@ -141,11 +141,11 @@
int cycles[kThreads];
pthread_t workers[kThreads];
- Condition start;
+ mutex start = 0;
for (int repeats = 0; repeats < 2; ++repeats) {
+ futex_unset(&start);
MutexFairnessWorkerThread::Reset(repeats ? kRunCycles : kWarmupCycles);
- start.Unset();
for (int i = 0; i < kThreads; ++i) {
MutexFairnessWorkerThread *c = new MutexFairnessWorkerThread(cycles, i,
&test_mutex,
@@ -153,7 +153,7 @@
ASSERT_EQ(0, pthread_create(&workers[i], NULL,
MutexFairnessWorkerThread::RunStatic, c));
}
- start.Set();
+ futex_set(&start);
for (int i = 0; i < kThreads; ++i) {
ASSERT_EQ(0, pthread_join(workers[i], NULL));
}
diff --git a/aos/common/queue.h b/aos/common/queue.h
index 612429a..68cb338 100644
--- a/aos/common/queue.h
+++ b/aos/common/queue.h
@@ -138,7 +138,7 @@
#ifndef USE_UNSAFE
// Only Queue should be able to build a queue.
- ScopedMessagePtr(aos_queue *queue, T *msg)
+ ScopedMessagePtr(RawQueue *queue, T *msg)
: queue_(queue), msg_(msg) {}
#else
ScopedMessagePtr(T *msg)
@@ -152,10 +152,10 @@
#ifndef USE_UNSAFE
// Sets the queue that owns this message.
- void set_queue(aos_queue *queue) { queue_ = queue; }
+ void set_queue(RawQueue *queue) { queue_ = queue; }
// The queue that the message is a part of.
- aos_queue *queue_;
+ RawQueue *queue_;
#endif // USE_UNSAFE
// The message or NULL.
T *msg_;
@@ -281,7 +281,7 @@
#else
T *MakeRawMessage();
// Pointer to the queue that this object fetches from.
- aos_queue *queue_;
+ RawQueue *queue_;
#endif
// Scoped pointer holding the latest message or NULL.
ScopedMessagePtr<const T> queue_msg_;