libzmq master
The Intelligent Transport Layer

zmq_utils.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2009-2011 250bpm s.r.o.
00003     Copyright (c) 2007-2009 iMatix Corporation
00004     Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
00005 
00006     This file is part of 0MQ.
00007 
00008     0MQ is free software; you can redistribute it and/or modify it under
00009     the terms of the GNU Lesser General Public License as published by
00010     the Free Software Foundation; either version 3 of the License, or
00011     (at your option) any later version.
00012 
00013     0MQ is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public License
00019     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #include "platform.hpp"
00023 
00024 #include "../include/zmq_utils.h"
00025 
00026 #include <stdlib.h>
00027 
00028 #include "stdint.hpp"
00029 #include "clock.hpp"
00030 #include "err.hpp"
00031 
00032 #if !defined ZMQ_HAVE_WINDOWS
00033 #include <unistd.h>
00034 #else
00035 #include "windows.hpp"
00036 #endif
00037 
00038 void zmq_sleep (int seconds_)
00039 {
00040 #if defined ZMQ_HAVE_WINDOWS
00041     Sleep (seconds_ * 1000);
00042 #else
00043     sleep (seconds_);
00044 #endif
00045 }
00046 
00047 void *zmq_stopwatch_start ()
00048 {
00049     uint64_t *watch = (uint64_t*) malloc (sizeof (uint64_t));
00050     alloc_assert (watch);
00051     *watch = zmq::clock_t::now_us ();
00052     return (void*) watch;
00053 }
00054 
00055 unsigned long zmq_stopwatch_stop (void *watch_)
00056 {
00057     uint64_t end = zmq::clock_t::now_us ();
00058     uint64_t start = *(uint64_t*) watch_;
00059     free (watch_);
00060     return (unsigned long) (end - start);
00061 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines