summaryrefslogtreecommitdiff
path: root/src/Sockets/tests/semtest.cpp
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@anytun.org>2008-10-19 20:06:14 +0000
committerOthmar Gsenger <otti@anytun.org>2008-10-19 20:06:14 +0000
commit7ec2d1c53b753238509bf7a89587509305b9216d (patch)
tree2e81d3fbd6b2a515f71449a2a16b2c69ecf4ddad /src/Sockets/tests/semtest.cpp
parentswitched from PracticalSocket to libasio (diff)
move to asio socket libary for sync
bugs / todos: * new connections don't sync * anyrtpproxy broken * anytun-controlld doesn't send data
Diffstat (limited to 'src/Sockets/tests/semtest.cpp')
-rw-r--r--src/Sockets/tests/semtest.cpp96
1 files changed, 0 insertions, 96 deletions
diff --git a/src/Sockets/tests/semtest.cpp b/src/Sockets/tests/semtest.cpp
deleted file mode 100644
index 442d5d6..0000000
--- a/src/Sockets/tests/semtest.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#ifndef _WIN32
-#include <unistd.h>
-#include <Semaphore.h>
-#include <Mutex.h>
-#include <Thread.h>
-#include <Utility.h>
-#include <Lock.h>
-
-
-class MyThread : public Thread
-{
-public:
- void Run() {
- printf("Thread\n");
- }
-};
-
-
-class SemLock
-{
-public:
- SemLock(Semaphore& sem) : m_sem(sem) {
- m_sem.Wait();
- }
- ~SemLock() {
- m_sem.Post();
- }
-
-private:
- Semaphore& m_sem;
-};
-
-
-/**
- * Return time difference between two struct timeval's, in seconds
- * \param t0 start time
- * \param t end time
- */
-double Diff(struct timeval t0,struct timeval t)
-{
- t.tv_sec -= t0.tv_sec;
- t.tv_usec -= t0.tv_usec;
- if (t.tv_usec < 0)
- {
- t.tv_usec += 1000000;
- t.tv_sec -= 1;
- }
- return t.tv_sec + (double)t.tv_usec / 1000000;
-}
-
-
-static int val = 0;
-
-void lock(Mutex& m, int i)
-{
- Lock l(m);
- val += i;
-}
-
-
-void lock(Semaphore& s, int i)
-{
- SemLock l(s);
- val += i;
-}
-#endif // WIN32
-
-
-int main()
-{
-#ifndef _WIN32
- Mutex mutex;
- Semaphore sema(1);
- struct timeval start;
- struct timeval tt;
- double d;
-
- Utility::GetTime(&start);
- for (int i = 0; i < 100000; i++)
- lock(mutex, i);
- Utility::GetTime(&tt);
- d = Diff(start, tt);
- printf("%.4f sec\n", d);
-
- Utility::GetTime(&start);
- for (int i = 0; i < 100000; i++)
- lock(sema, i);
- Utility::GetTime(&tt);
- d = Diff(start, tt);
- printf("%.4f sec\n", d);
-#endif
-}
-
-