LogCabin
|
00001 /* Copyright (c) 2011-2012 Stanford University 00002 * Copyright (c) 2015 Diego Ongaro 00003 * 00004 * Permission to use, copy, modify, and distribute this software for any 00005 * purpose with or without fee is hereby granted, provided that the above 00006 * copyright notice and this permission notice appear in all copies. 00007 * 00008 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES 00009 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 00010 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR 00011 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 00012 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 00013 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 00014 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 */ 00016 00017 #include <cstring> 00018 #include "Core/Util.h" 00019 00020 namespace LogCabin { 00021 namespace Core { 00022 namespace Util { 00023 00024 bool 00025 isPowerOfTwo(uint64_t x) 00026 { 00027 if (x == 0) 00028 return false; 00029 else 00030 return (x & (x - 1)) == 0; 00031 } 00032 00033 void* 00034 memcpy(void* dest, 00035 std::initializer_list<std::pair<const void*, size_t>> src) 00036 { 00037 uint8_t* target = static_cast<uint8_t*>(dest); 00038 for (auto it = src.begin(); it != src.end(); ++it) { 00039 ::memcpy(target, it->first, it->second); 00040 target += it->second; 00041 } 00042 return dest; 00043 } 00044 00045 ThreadInterruptedException::ThreadInterruptedException() 00046 : std::runtime_error("Thread was interrupted") 00047 { 00048 } 00049 00050 } // namespace LogCabin::Core::Util 00051 } // namespace LogCabin::Core 00052 } // namespace LogCabin