summaryrefslogtreecommitdiff
path: root/src/zmq.cpp
diff options
context:
space:
mode:
authorunknown <sustrik@.(none)>2009-09-08 11:30:49 +0200
committerunknown <sustrik@.(none)>2009-09-08 11:30:49 +0200
commitec6822a477b89ac77afc90425bf36c4829dbef3d (patch)
treed8708a7d56fc2a1db9a163be795bc5b84955f48c /src/zmq.cpp
parentb71c3005e68d02f800ff09bcacece79d167bff75 (diff)
win port for c and cpp perf tests
Diffstat (limited to 'src/zmq.cpp')
-rw-r--r--src/zmq.cpp67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/zmq.cpp b/src/zmq.cpp
index ad4839f..63a7b4b 100644
--- a/src/zmq.cpp
+++ b/src/zmq.cpp
@@ -27,6 +27,13 @@
#include "err.hpp"
#include "dispatcher.hpp"
#include "msg_content.hpp"
+#include "platform.hpp"
+#include "stdint.hpp"
+
+#if !defined ZMQ_HAVE_WINDOWS
+#include <unistd.h>
+#include <sys/time.h>
+#endif
int zmq_msg_init (zmq_msg_t *msg_)
{
@@ -39,7 +46,7 @@ int zmq_msg_init_size (zmq_msg_t *msg_, size_t size_)
{
if (size_ <= ZMQ_MAX_VSM_SIZE) {
msg_->content = (zmq::msg_content_t*) ZMQ_VSM;
- msg_->vsm_size = (uint16_t) size_;
+ msg_->vsm_size = (uint8_t) size_;
}
else {
msg_->content =
@@ -228,3 +235,61 @@ int zmq_recv (void *s_, zmq_msg_t *msg_, int flags_)
{
return (((zmq::socket_base_t*) s_)->recv (msg_, flags_));
}
+
+#if defined ZMQ_HAVE_WINDOWS
+
+static uint64_t now ()
+{
+ // Get the high resolution counter's accuracy.
+ LARGE_INTEGER ticksPerSecond;
+ QueryPerformanceFrequency (&ticksPerSecond);
+
+ // What time is it?
+ LARGE_INTEGER tick;
+ QueryPerformanceCounter (&tick);
+
+ // Convert the tick number into the number of seconds
+ // since the system was started.
+ double ticks_div = (double) (ticksPerSecond.QuadPart / 1000000);
+ return (uint64_t) (tick.QuadPart / ticks_div);
+}
+
+void zmq_sleep (int seconds_)
+{
+ Sleep (seconds_ * 1000);
+}
+
+#else
+
+static uint64_t now ()
+{
+ struct timeval tv;
+ int rc;
+
+ rc = gettimeofday (&tv, NULL);
+ assert (rc == 0);
+ return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_usec);
+}
+
+void zmq_sleep (int seconds_)
+{
+ sleep (seconds_);
+}
+
+#endif
+
+void *zmq_stopwatch_start ()
+{
+ uint64_t *watch = (uint64_t*) malloc (sizeof (uint64_t));
+ zmq_assert (watch);
+ *watch = now ();
+ return (void*) watch;
+}
+
+unsigned long zmq_stopwatch_stop (void *watch_)
+{
+ uint64_t end = now ();
+ uint64_t start = *(uint64_t*) watch_;
+ free (watch_);
+ return (unsigned long) (end - start);
+} \ No newline at end of file