copied everything over from 2012 and removed all of the actual robot code except the drivetrain stuff
git-svn-id: https://robotics.mvla.net/svn/frc971/2013/trunk/src@4078 f308d9b7-e957-4cde-b6ac-9a88185e7312
diff --git a/aos/crio/shared_libs/mutex.cpp b/aos/crio/shared_libs/mutex.cpp
new file mode 100644
index 0000000..35ac4e3
--- /dev/null
+++ b/aos/crio/shared_libs/mutex.cpp
@@ -0,0 +1,48 @@
+#include "aos/common/mutex.h"
+
+#include <semLib.h>
+
+namespace aos {
+
+Mutex::Mutex() : impl_(semBCreate(SEM_Q_PRIORITY, SEM_FULL)) {
+ if (impl_ == NULL) {
+ LOG(FATAL,
+ "semBCreate(SEM_Q_PRIORITY, SEM_FULL) failed because of %d: %s\n",
+ errno, strerror(errno));
+ }
+}
+
+Mutex::~Mutex() {
+ if (semDelete(impl_) != 0) {
+ LOG(FATAL, "semDelete(%p) failed because of %d: %s\n",
+ impl_, errno, strerror(errno));
+ }
+}
+
+void Mutex::Lock() {
+ if (semTake(impl_, WAIT_FOREVER) != 0) {
+ LOG(FATAL, "semTake(%p, WAIT_FOREVER) failed because of %d: %s\n",
+ impl_, errno, strerror(errno));
+ }
+}
+
+void Mutex::Unlock() {
+ if (semGive(impl_) != 0) {
+ LOG(FATAL, "semGive(%p) failed because of %d: %s\n",
+ impl_, errno, strerror(errno));
+ }
+}
+
+bool Mutex::TryLock() {
+ if (semTake(impl_, NO_WAIT) == 0) {
+ return true;
+ }
+ // The semLib documention is wrong about what the errno will be.
+ if (errno != S_objLib_OBJ_UNAVAILABLE) {
+ LOG(FATAL, "semTake(%p, WAIT_FOREVER) failed because of %d: %s\n",
+ impl_, errno, strerror(errno));
+ }
+ return false;
+}
+
+} // namespace aos