Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 40395200AF8 for ; Thu, 5 May 2016 16:02:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3EB231609F3; Thu, 5 May 2016 14:02:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3AA3F160A03 for ; Thu, 5 May 2016 16:02:39 +0200 (CEST) Received: (qmail 14420 invoked by uid 500); 5 May 2016 14:02:36 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 13051 invoked by uid 99); 5 May 2016 14:02:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 May 2016 14:02:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7A065E97F5; Thu, 5 May 2016 14:02:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Thu, 05 May 2016 14:02:57 -0000 Message-Id: <4e2aa8a15d8b43359cdce2243856de09@git.apache.org> In-Reply-To: <5f1852aff071435f86f1fdcd753d93b5@git.apache.org> References: <5f1852aff071435f86f1fdcd753d93b5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [24/34] ignite git commit: IGNITE-1786: Implemented ODBC driver. archived-at: Thu, 05 May 2016 14:02:42 -0000 http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/linux/include/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/linux/include/Makefile.am b/modules/platforms/cpp/common/os/linux/include/Makefile.am index f6e2803..9332f4f 100644 --- a/modules/platforms/cpp/common/os/linux/include/Makefile.am +++ b/modules/platforms/cpp/common/os/linux/include/Makefile.am @@ -15,10 +15,11 @@ ## limitations under the License. ## -ACLOCAL_AMFLAGS = "-Im4" +ACLOCAL_AMFLAGS =-I m4 -nobase_include_HEADERS = ignite/common/common.h \ - ignite/common/concurrent_os.h +nobase_include_HEADERS = \ + ignite/common/common.h \ + ignite/common/concurrent_os.h uninstall-hook: - find ${includedir}/ignite -type d -empty -delete + if [ -d ${includedir}/ignite ]; then find ${includedir}/ignite -type d -empty -delete; fi http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/linux/include/ignite/common/common.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/linux/include/ignite/common/common.h b/modules/platforms/cpp/common/os/linux/include/ignite/common/common.h index 0ec8e16..5932a6c 100644 --- a/modules/platforms/cpp/common/os/linux/include/ignite/common/common.h +++ b/modules/platforms/cpp/common/os/linux/include/ignite/common/common.h @@ -15,8 +15,8 @@ * limitations under the License. */ -#ifndef _IGNITE_COMMON_OS -#define _IGNITE_COMMON_OS +#ifndef _IGNITE_COMMON_COMMON +#define _IGNITE_COMMON_COMMON #ifndef __has_attribute # define __has_attribute(x) 0 @@ -51,37 +51,4 @@ cls(const cls& src); \ cls& operator= (const cls& other); -namespace ignite -{ - namespace common - { - /** - * Helper class to manage attached threads. - */ - class AttachHelper - { - public: - /** - * Destructor. - */ - ~AttachHelper(); - - /** - * Callback invoked on successful thread attach ot JVM. - */ - static void OnThreadAttach(); - private: - /** - * Helper method to allocate attach key. - */ - static void AllocateAttachKey(); - - /** - * Attach key destructor. - */ - static void DestroyAttachKey(void* key); - }; - } -} - #endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/linux/include/ignite/common/concurrent_os.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/linux/include/ignite/common/concurrent_os.h b/modules/platforms/cpp/common/os/linux/include/ignite/common/concurrent_os.h index 63798b1..27ef998 100644 --- a/modules/platforms/cpp/common/os/linux/include/ignite/common/concurrent_os.h +++ b/modules/platforms/cpp/common/os/linux/include/ignite/common/concurrent_os.h @@ -391,4 +391,4 @@ namespace ignite } } -#endif \ No newline at end of file +#endif http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/linux/src/common.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/linux/src/common.cpp b/modules/platforms/cpp/common/os/linux/src/common.cpp deleted file mode 100644 index c0cccdc..0000000 --- a/modules/platforms/cpp/common/os/linux/src/common.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "ignite/common/common.h" -#include "ignite/common/java.h" - -using namespace ignite::common::java; - -namespace ignite -{ - namespace common - { - /** Key indicating that the thread is attached. */ - static pthread_key_t attachKey; - - /** Helper to ensure that attach key is allocated only once. */ - static pthread_once_t attachKeyInit = PTHREAD_ONCE_INIT; - - AttachHelper::~AttachHelper() - { - JniContext::Detach(); - } - - void AttachHelper::OnThreadAttach() - { - pthread_once(&attachKeyInit, AllocateAttachKey); - - void* val = pthread_getspecific(attachKey); - - if (!val) - pthread_setspecific(attachKey, new AttachHelper()); - } - - void AttachHelper::AllocateAttachKey() - { - pthread_key_create(&attachKey, DestroyAttachKey); - } - - void AttachHelper::DestroyAttachKey(void* key) - { - delete reinterpret_cast(key); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/linux/src/common/concurrent_os.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/linux/src/common/concurrent_os.cpp b/modules/platforms/cpp/common/os/linux/src/common/concurrent_os.cpp new file mode 100644 index 0000000..2336d58 --- /dev/null +++ b/modules/platforms/cpp/common/os/linux/src/common/concurrent_os.cpp @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ignite/common/concurrent_os.h" + +namespace ignite +{ + namespace common + { + namespace concurrent + { + /** Key indicating that the thread is attached. */ + static pthread_key_t tlsKey; + + /** Helper to ensure that attach key is allocated only once. */ + static pthread_once_t tlsKeyInit = PTHREAD_ONCE_INIT; + + /** + * Routine to destroy TLS key. + * + * @param key Key. + */ + void DestroyTlsKey(void* key) { + ThreadLocal::Clear0(key); + } + + /** + * Routine to allocate TLS key. + */ + void AllocateTlsKey() { + pthread_key_create(&tlsKey, DestroyTlsKey); + } + + void Memory::Fence() { + __asm__ volatile ("" ::: "memory"); + } + + CriticalSection::CriticalSection() { + pthread_mutex_init(&mux, NULL); + + Memory::Fence(); + } + + CriticalSection::~CriticalSection() { + Memory::Fence(); + + pthread_mutex_destroy(&mux); + } + + void CriticalSection::Enter() { + Memory::Fence(); + + pthread_mutex_lock(&mux); + } + + void CriticalSection::Leave() { + Memory::Fence(); + + pthread_mutex_unlock(&mux); + } + + SingleLatch::SingleLatch() + { + pthread_mutex_init(&mux, NULL); + pthread_cond_init(&cond, NULL); + ready = false; + + Memory::Fence(); + } + + SingleLatch::~SingleLatch() + { + Memory::Fence(); + + pthread_cond_destroy(&cond); + pthread_mutex_destroy(&mux); + } + + void SingleLatch::CountDown() + { + pthread_mutex_lock(&mux); + + if (!ready) { + ready = true; + + pthread_cond_broadcast(&cond); + } + + pthread_mutex_unlock(&mux); + + Memory::Fence(); + } + + void SingleLatch::Await() + { + pthread_mutex_lock(&mux); + + while (!ready) + pthread_cond_wait(&cond, &mux); + + pthread_mutex_unlock(&mux); + + Memory::Fence(); + } + + bool Atomics::CompareAndSet32(int32_t* ptr, int32_t expVal, int32_t newVal) + { + return __sync_bool_compare_and_swap(ptr, expVal, newVal); + } + + int32_t Atomics::CompareAndSet32Val(int32_t* ptr, int32_t expVal, int32_t newVal) + { + return __sync_val_compare_and_swap(ptr, expVal, newVal); + } + + int32_t Atomics::IncrementAndGet32(int32_t* ptr) + { + return __sync_fetch_and_add(ptr, 1) + 1; + } + + int32_t Atomics::DecrementAndGet32(int32_t* ptr) + { + return __sync_fetch_and_sub(ptr, 1) - 1; + } + + bool Atomics::CompareAndSet64(int64_t* ptr, int64_t expVal, int64_t newVal) + { + return __sync_bool_compare_and_swap(ptr, expVal, newVal); + } + + int64_t Atomics::CompareAndSet64Val(int64_t* ptr, int64_t expVal, int64_t newVal) + { + return __sync_val_compare_and_swap(ptr, expVal, newVal); + } + + int64_t Atomics::IncrementAndGet64(int64_t* ptr) + { + return __sync_fetch_and_add(ptr, 1) + 1; + } + + int64_t Atomics::DecrementAndGet64(int64_t* ptr) + { + return __sync_fetch_and_sub(ptr, 1) - 1; + } + + void* ThreadLocal::Get0() + { + pthread_once(&tlsKeyInit, AllocateTlsKey); + + return pthread_getspecific(tlsKey); + } + + void ThreadLocal::Set0(void* ptr) + { + pthread_once(&tlsKeyInit, AllocateTlsKey); + + pthread_setspecific(tlsKey, ptr); + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/linux/src/common/utils.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/linux/src/common/utils.cpp b/modules/platforms/cpp/common/os/linux/src/common/utils.cpp new file mode 100644 index 0000000..e37a91c --- /dev/null +++ b/modules/platforms/cpp/common/os/linux/src/common/utils.cpp @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include + +namespace ignite +{ + namespace common + { + /** + * Check if string ends with the given ending. + * + * @param str String to check. + * @param ending Ending. + * @return Result. + */ + inline bool StringEndsWith(const std::string& str, const std::string& ending) + { + if (str.length() > ending.length()) + return str.compare(str.length() - ending.length(), ending.length(), ending) == 0; + + return false; + } + + time_t IgniteTimeGm(const tm& time) + { + tm tmc = time; + + return timegm(&tmc); + } + + time_t IgniteTimeLocal(const tm& time) + { + tm tmc = time; + + return mktime(&tmc); + } + + bool IgniteGmTime(time_t in, tm& out) + { + return gmtime_r(&in, &out) != NULL; + } + + bool IgniteLocalTime(time_t in, tm& out) + { + return localtime_r(&in, &out) == 0; + } + + int LeadingZeroesForOctet(int8_t octet) { + if (octet == 0) + return 8; + + int zeroes = 1; + + if (octet >> 4 == 0) { + zeroes += 4; + octet <<= 4; + } + + if (octet >> 6 == 0) { + zeroes += 2; + octet <<= 2; + } + + zeroes -= octet >> 7; + + return zeroes; + } + + char* CopyChars(const char* val) + { + if (val) { + size_t len = strlen(val); + char* dest = new char[len + 1]; + strcpy(dest, val); + *(dest + len) = 0; + return dest; + } + else + return NULL; + } + + void ReleaseChars(char* val) + { + if (val) + delete[] val; + } + + std::string GetEnv(const std::string& name, bool& found) + { + char* val = std::getenv(name.c_str()); + + if (val) + { + found = true; + + return std::string(val); + } + else + { + found = false; + + return std::string(); + } + } + + bool FileExists(const std::string& path) + { + struct stat s; + + int res = stat(path.c_str(), &s); + + return res != -1; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/linux/src/concurrent_os.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/linux/src/concurrent_os.cpp b/modules/platforms/cpp/common/os/linux/src/concurrent_os.cpp deleted file mode 100644 index 44f0b22..0000000 --- a/modules/platforms/cpp/common/os/linux/src/concurrent_os.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/common/concurrent_os.h" - -namespace ignite -{ - namespace common - { - namespace concurrent - { - /** Key indicating that the thread is attached. */ - static pthread_key_t tlsKey; - - /** Helper to ensure that attach key is allocated only once. */ - static pthread_once_t tlsKeyInit = PTHREAD_ONCE_INIT; - - /** - * Routine to destroy TLS key. - * - * @param key Key. - */ - void DestroyTlsKey(void* key) { - ThreadLocal::Clear0(key); - } - - /** - * Routine to allocate TLS key. - */ - void AllocateTlsKey() { - pthread_key_create(&tlsKey, DestroyTlsKey); - } - - void Memory::Fence() { - __asm__ volatile ("" ::: "memory"); - } - - CriticalSection::CriticalSection() { - pthread_mutex_init(&mux, NULL); - - Memory::Fence(); - } - - CriticalSection::~CriticalSection() { - Memory::Fence(); - - pthread_mutex_destroy(&mux); - } - - void CriticalSection::Enter() { - Memory::Fence(); - - pthread_mutex_lock(&mux); - } - - void CriticalSection::Leave() { - Memory::Fence(); - - pthread_mutex_unlock(&mux); - } - - SingleLatch::SingleLatch() - { - pthread_mutex_init(&mux, NULL); - pthread_cond_init(&cond, NULL); - ready = false; - - Memory::Fence(); - } - - SingleLatch::~SingleLatch() - { - Memory::Fence(); - - pthread_cond_destroy(&cond); - pthread_mutex_destroy(&mux); - } - - void SingleLatch::CountDown() - { - pthread_mutex_lock(&mux); - - if (!ready) { - ready = true; - - pthread_cond_broadcast(&cond); - } - - pthread_mutex_unlock(&mux); - - Memory::Fence(); - } - - void SingleLatch::Await() - { - pthread_mutex_lock(&mux); - - while (!ready) - pthread_cond_wait(&cond, &mux); - - pthread_mutex_unlock(&mux); - - Memory::Fence(); - } - - bool Atomics::CompareAndSet32(int32_t* ptr, int32_t expVal, int32_t newVal) - { - return __sync_bool_compare_and_swap(ptr, expVal, newVal); - } - - int32_t Atomics::CompareAndSet32Val(int32_t* ptr, int32_t expVal, int32_t newVal) - { - return __sync_val_compare_and_swap(ptr, expVal, newVal); - } - - int32_t Atomics::IncrementAndGet32(int32_t* ptr) - { - return __sync_fetch_and_add(ptr, 1) + 1; - } - - int32_t Atomics::DecrementAndGet32(int32_t* ptr) - { - return __sync_fetch_and_sub(ptr, 1) - 1; - } - - bool Atomics::CompareAndSet64(int64_t* ptr, int64_t expVal, int64_t newVal) - { - return __sync_bool_compare_and_swap(ptr, expVal, newVal); - } - - int64_t Atomics::CompareAndSet64Val(int64_t* ptr, int64_t expVal, int64_t newVal) - { - return __sync_val_compare_and_swap(ptr, expVal, newVal); - } - - int64_t Atomics::IncrementAndGet64(int64_t* ptr) - { - return __sync_fetch_and_add(ptr, 1) + 1; - } - - int64_t Atomics::DecrementAndGet64(int64_t* ptr) - { - return __sync_fetch_and_sub(ptr, 1) - 1; - } - - void* ThreadLocal::Get0() - { - pthread_once(&tlsKeyInit, AllocateTlsKey); - - return pthread_getspecific(tlsKey); - } - - void ThreadLocal::Set0(void* ptr) - { - pthread_once(&tlsKeyInit, AllocateTlsKey); - - pthread_setspecific(tlsKey, ptr); - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/win/include/ignite/common/common.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/win/include/ignite/common/common.h b/modules/platforms/cpp/common/os/win/include/ignite/common/common.h index cf924c8..8285149 100644 --- a/modules/platforms/cpp/common/os/win/include/ignite/common/common.h +++ b/modules/platforms/cpp/common/os/win/include/ignite/common/common.h @@ -41,22 +41,4 @@ # define IGNITE_NO_THROW throw() #endif -namespace ignite -{ - namespace common - { - /** - * Helper class to manage attached threads. - */ - class AttachHelper - { - public: - /** - * Callback invoked on successful thread attach ot JVM. - */ - static void OnThreadAttach(); - }; - } -} - -#endif \ No newline at end of file +#endif //_IGNITE_COMMON_COMMON \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/win/include/ignite/common/concurrent_os.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/win/include/ignite/common/concurrent_os.h b/modules/platforms/cpp/common/os/win/include/ignite/common/concurrent_os.h index 0a47beb..77de4d8 100644 --- a/modules/platforms/cpp/common/os/win/include/ignite/common/concurrent_os.h +++ b/modules/platforms/cpp/common/os/win/include/ignite/common/concurrent_os.h @@ -26,7 +26,7 @@ namespace ignite { - namespace common + namespace common { namespace concurrent { @@ -403,4 +403,4 @@ namespace ignite } } -#endif \ No newline at end of file +#endif //_IGNITE_COMMON_CONCURRENT_OS \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/win/src/common.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/win/src/common.cpp b/modules/platforms/cpp/common/os/win/src/common.cpp deleted file mode 100644 index e83e736..0000000 --- a/modules/platforms/cpp/common/os/win/src/common.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "ignite/common/common.h" -#include "ignite/common/concurrent.h" -#include "ignite/common/java.h" - -using namespace ignite::common::concurrent; -using namespace ignite::common::java; - -namespace ignite -{ - namespace common - { - void AttachHelper::OnThreadAttach() - { - // No-op. - } - } -} - -BOOL WINAPI DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved) -{ - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - if (!ThreadLocal::OnProcessAttach()) - return FALSE; - - break; - - case DLL_THREAD_DETACH: - ThreadLocal::OnThreadDetach(); - - JniContext::Detach(); - - break; - - case DLL_PROCESS_DETACH: - ThreadLocal::OnProcessDetach(); - - break; - - default: - break; - } - - return TRUE; -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/win/src/common/concurrent_os.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/win/src/common/concurrent_os.cpp b/modules/platforms/cpp/common/os/win/src/common/concurrent_os.cpp new file mode 100644 index 0000000..676d8b6 --- /dev/null +++ b/modules/platforms/cpp/common/os/win/src/common/concurrent_os.cpp @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ignite/common/concurrent_os.h" + +#pragma intrinsic(_InterlockedCompareExchange64) + +namespace ignite +{ + namespace common + { + namespace concurrent + { + /** Thread-local index for Windows. */ + DWORD winTlsIdx; + + void Memory::Fence() { + MemoryBarrier(); + } + + CriticalSection::CriticalSection() : hnd(new CRITICAL_SECTION) { + InitializeCriticalSection(hnd); + + Memory::Fence(); + } + + CriticalSection::~CriticalSection() { + Memory::Fence(); + + delete hnd; + } + + void CriticalSection::Enter() { + Memory::Fence(); + + EnterCriticalSection(hnd); + } + + void CriticalSection::Leave() { + Memory::Fence(); + + LeaveCriticalSection(hnd); + } + + SingleLatch::SingleLatch() : hnd(CreateEvent(NULL, TRUE, FALSE, NULL)) + { + Memory::Fence(); + } + + SingleLatch::~SingleLatch() + { + Memory::Fence(); + + CloseHandle(hnd); + } + + void SingleLatch::CountDown() + { + SetEvent(hnd); + } + + void SingleLatch::Await() + { + WaitForSingleObject(hnd, INFINITE); + } + + bool Atomics::CompareAndSet32(int32_t* ptr, int32_t expVal, int32_t newVal) + { + return CompareAndSet32Val(ptr, expVal, newVal) == expVal; + } + + int32_t Atomics::CompareAndSet32Val(int32_t* ptr, int32_t expVal, int32_t newVal) + { + return InterlockedCompareExchange(reinterpret_cast(ptr), newVal, expVal); + } + + int32_t Atomics::IncrementAndGet32(int32_t* ptr) + { + return InterlockedIncrement(reinterpret_cast(ptr)); + } + + int32_t Atomics::DecrementAndGet32(int32_t* ptr) + { + return InterlockedDecrement(reinterpret_cast(ptr)); + } + + bool Atomics::CompareAndSet64(int64_t* ptr, int64_t expVal, int64_t newVal) + { + return CompareAndSet64Val(ptr, expVal, newVal) == expVal; + } + + int64_t Atomics::CompareAndSet64Val(int64_t* ptr, int64_t expVal, int64_t newVal) + { + return _InterlockedCompareExchange64(reinterpret_cast(ptr), newVal, expVal); + } + + int64_t Atomics::IncrementAndGet64(int64_t* ptr) + { +#ifdef _WIN64 + return InterlockedIncrement64(reinterpret_cast(ptr)); +#else + while (true) + { + int64_t expVal = *ptr; + int64_t newVal = expVal + 1; + + if (CompareAndSet64(ptr, expVal, newVal)) + return newVal; + } +#endif + } + + int64_t Atomics::DecrementAndGet64(int64_t* ptr) + { +#ifdef _WIN64 + return InterlockedDecrement64(reinterpret_cast(ptr)); +#else + while (true) + { + int64_t expVal = *ptr; + int64_t newVal = expVal - 1; + + if (CompareAndSet64(ptr, expVal, newVal)) + return newVal; + } +#endif + } + + bool ThreadLocal::OnProcessAttach() + { + return (winTlsIdx = TlsAlloc()) != TLS_OUT_OF_INDEXES; + } + + void ThreadLocal::OnThreadDetach() + { + if (winTlsIdx != TLS_OUT_OF_INDEXES) + { + void* mapPtr = Get0(); + + Clear0(mapPtr); + } + } + + void ThreadLocal::OnProcessDetach() + { + if (winTlsIdx != TLS_OUT_OF_INDEXES) + TlsFree(winTlsIdx); + } + + void* ThreadLocal::Get0() + { + return TlsGetValue(winTlsIdx); + } + + void ThreadLocal::Set0(void* ptr) + { + TlsSetValue(winTlsIdx, ptr); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/win/src/common/utils.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/win/src/common/utils.cpp b/modules/platforms/cpp/common/os/win/src/common/utils.cpp new file mode 100644 index 0000000..65236d2 --- /dev/null +++ b/modules/platforms/cpp/common/os/win/src/common/utils.cpp @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include + +namespace ignite +{ + namespace common + { + /** + * Check if string ends with the given ending. + * + * @param str String to check. + * @param ending Ending. + * @return Result. + */ + inline bool StringEndsWith(const std::string& str, const std::string& ending) + { + if (str.length() > ending.length()) + return str.compare(str.length() - ending.length(), ending.length(), ending) == 0; + + return false; + } + + time_t IgniteTimeGm(const tm& time) + { + tm tmc = time; + + return _mkgmtime(&tmc); + } + + time_t IgniteTimeLocal(const tm& time) + { + tm tmc = time; + + return mktime(&tmc); + } + + bool IgniteGmTime(time_t in, tm& out) + { + return gmtime_s(&out, &in) == 0; + } + + bool IgniteLocalTime(time_t in, tm& out) + { + return localtime_s(&out, &in) == 0; + } + + int LeadingZeroesForOctet(int8_t octet) { + if (octet == 0) + return 8; + + int zeroes = 1; + + if (octet >> 4 == 0) { + zeroes += 4; + octet <<= 4; + } + + if (octet >> 6 == 0) { + zeroes += 2; + octet <<= 2; + } + + zeroes -= octet >> 7; + + return zeroes; + } + + char* CopyChars(const char* val) + { + if (val) { + size_t len = strlen(val); + char* dest = new char[len + 1]; + strcpy(dest, val); + *(dest + len) = 0; + return dest; + } + else + return NULL; + } + + void ReleaseChars(char* val) + { + if (val) + delete[] val; + } + + std::string GetEnv(const std::string& name, bool& found) + { + char res0[32767]; + + DWORD envRes = GetEnvironmentVariableA(name.c_str(), res0, 32767); + + if (envRes != 0) + { + found = true; + + return std::string(res0); + } + else + { + found = false; + + return std::string(); + } + } + + bool FileExists(const std::string& path) + { + WIN32_FIND_DATAA findres; + + HANDLE hnd = FindFirstFileA(path.c_str(), &findres); + + if (hnd == INVALID_HANDLE_VALUE) + return false; + else + { + FindClose(hnd); + + return true; + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/os/win/src/concurrent_os.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/os/win/src/concurrent_os.cpp b/modules/platforms/cpp/common/os/win/src/concurrent_os.cpp deleted file mode 100644 index 676d8b6..0000000 --- a/modules/platforms/cpp/common/os/win/src/concurrent_os.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/common/concurrent_os.h" - -#pragma intrinsic(_InterlockedCompareExchange64) - -namespace ignite -{ - namespace common - { - namespace concurrent - { - /** Thread-local index for Windows. */ - DWORD winTlsIdx; - - void Memory::Fence() { - MemoryBarrier(); - } - - CriticalSection::CriticalSection() : hnd(new CRITICAL_SECTION) { - InitializeCriticalSection(hnd); - - Memory::Fence(); - } - - CriticalSection::~CriticalSection() { - Memory::Fence(); - - delete hnd; - } - - void CriticalSection::Enter() { - Memory::Fence(); - - EnterCriticalSection(hnd); - } - - void CriticalSection::Leave() { - Memory::Fence(); - - LeaveCriticalSection(hnd); - } - - SingleLatch::SingleLatch() : hnd(CreateEvent(NULL, TRUE, FALSE, NULL)) - { - Memory::Fence(); - } - - SingleLatch::~SingleLatch() - { - Memory::Fence(); - - CloseHandle(hnd); - } - - void SingleLatch::CountDown() - { - SetEvent(hnd); - } - - void SingleLatch::Await() - { - WaitForSingleObject(hnd, INFINITE); - } - - bool Atomics::CompareAndSet32(int32_t* ptr, int32_t expVal, int32_t newVal) - { - return CompareAndSet32Val(ptr, expVal, newVal) == expVal; - } - - int32_t Atomics::CompareAndSet32Val(int32_t* ptr, int32_t expVal, int32_t newVal) - { - return InterlockedCompareExchange(reinterpret_cast(ptr), newVal, expVal); - } - - int32_t Atomics::IncrementAndGet32(int32_t* ptr) - { - return InterlockedIncrement(reinterpret_cast(ptr)); - } - - int32_t Atomics::DecrementAndGet32(int32_t* ptr) - { - return InterlockedDecrement(reinterpret_cast(ptr)); - } - - bool Atomics::CompareAndSet64(int64_t* ptr, int64_t expVal, int64_t newVal) - { - return CompareAndSet64Val(ptr, expVal, newVal) == expVal; - } - - int64_t Atomics::CompareAndSet64Val(int64_t* ptr, int64_t expVal, int64_t newVal) - { - return _InterlockedCompareExchange64(reinterpret_cast(ptr), newVal, expVal); - } - - int64_t Atomics::IncrementAndGet64(int64_t* ptr) - { -#ifdef _WIN64 - return InterlockedIncrement64(reinterpret_cast(ptr)); -#else - while (true) - { - int64_t expVal = *ptr; - int64_t newVal = expVal + 1; - - if (CompareAndSet64(ptr, expVal, newVal)) - return newVal; - } -#endif - } - - int64_t Atomics::DecrementAndGet64(int64_t* ptr) - { -#ifdef _WIN64 - return InterlockedDecrement64(reinterpret_cast(ptr)); -#else - while (true) - { - int64_t expVal = *ptr; - int64_t newVal = expVal - 1; - - if (CompareAndSet64(ptr, expVal, newVal)) - return newVal; - } -#endif - } - - bool ThreadLocal::OnProcessAttach() - { - return (winTlsIdx = TlsAlloc()) != TLS_OUT_OF_INDEXES; - } - - void ThreadLocal::OnThreadDetach() - { - if (winTlsIdx != TLS_OUT_OF_INDEXES) - { - void* mapPtr = Get0(); - - Clear0(mapPtr); - } - } - - void ThreadLocal::OnProcessDetach() - { - if (winTlsIdx != TLS_OUT_OF_INDEXES) - TlsFree(winTlsIdx); - } - - void* ThreadLocal::Get0() - { - return TlsGetValue(winTlsIdx); - } - - void ThreadLocal::Set0(void* ptr) - { - TlsSetValue(winTlsIdx, ptr); - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/project/vs/common.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/project/vs/common.vcxproj b/modules/platforms/cpp/common/project/vs/common.vcxproj index ac7d504..67f01ff 100644 --- a/modules/platforms/cpp/common/project/vs/common.vcxproj +++ b/modules/platforms/cpp/common/project/vs/common.vcxproj @@ -19,32 +19,32 @@ - {4F7E4917-4612-4B96-9838-025711ADE391} + {B63F2E01-5157-4719-8491-0E1C7CD3B701} Win32Proj common - DynamicLibrary + StaticLibrary true v100 Unicode - DynamicLibrary + StaticLibrary true v100 Unicode - DynamicLibrary + StaticLibrary false v100 true Unicode - DynamicLibrary + StaticLibrary false v100 true @@ -67,10 +67,10 @@ - false ignite.common $(SolutionDir)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ + false ignite.common @@ -79,8 +79,10 @@ false - false ignite.common + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + false ignite.common @@ -94,15 +96,11 @@ Level3 Disabled WIN32;_DEBUG;_WINDOWS;_USRDLL;IGNITEJVM_EXPORTS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions) - $(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories) + $(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories) Windows true - $(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies) - $(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories) - jvm.dll - module.def false false Default @@ -112,19 +110,15 @@ Level3 false - $(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories) + $(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;IGNITEJVM_EXPORTS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions) ProgramDatabase true - $(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories) - $(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies) true true - jvm.dll Default - module.def @@ -135,7 +129,7 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;IGNITEJVM_EXPORTS;_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;%(PreprocessorDefinitions) - $(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories) + $(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories) AnySuitable Speed true @@ -147,10 +141,6 @@ true true true - $(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies) - $(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories) - jvm.dll - module.def @@ -160,7 +150,7 @@ true true false - $(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories) + $(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include;%(AdditionalIncludeDirectories) AnySuitable Speed true @@ -172,32 +162,29 @@ true true true - $(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories) - $(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies) - jvm.dll - module.def - - + + + + - - - - - + + + + + + + - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/project/vs/common.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/project/vs/common.vcxproj.filters b/modules/platforms/cpp/common/project/vs/common.vcxproj.filters index 01a47a0..1a6f069 100644 --- a/modules/platforms/cpp/common/project/vs/common.vcxproj.filters +++ b/modules/platforms/cpp/common/project/vs/common.vcxproj.filters @@ -8,50 +8,60 @@ {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hh;hpp;hxx;hm;inl;inc;xsd + + {9d664b8a-3a09-460b-9d53-c1a7f08217c0} + + + Misc + - Code + Code\common + + + Code\common + + + Code\common - Code + Code\common - + Code - + Code - + Code - - Misc - - + Code - + Code - + Code - + Code - - Code + + Code\common - + + Code\common + + + Code\common + + Code - - - Misc - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/project/vs/module.def ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/project/vs/module.def b/modules/platforms/cpp/common/project/vs/module.def deleted file mode 100644 index 5f2e941..0000000 --- a/modules/platforms/cpp/common/project/vs/module.def +++ /dev/null @@ -1,135 +0,0 @@ -LIBRARY ignite.common.dll -EXPORTS -IgniteReallocate @1 -IgniteIgnitionStart @2 -IgniteIgnitionInstance @3 -IgniteIgnitionEnvironmentPointer @4 -IgniteIgnitionStop @5 -IgniteIgnitionStopAll @6 -IgniteTargetOutLong @7 -IgniteProcessorReleaseStart @8 -IgniteProcessorProjection @9 -IgniteProcessorCache @10 -IgniteProcessorCreateCache @11 -IgniteProcessorGetOrCreateCache @12 -IgniteProcessorAffinity @13 -IgniteProcessorDataStreamer @14 -IgniteProcessorTransactions @15 -IgniteProcessorServices @16 -IgniteTargetInStreamOutObject @17 -IgniteTargetInStreamOutLong @18 -IgniteTargetOutStream @19 -IgniteTargetInStreamOutStream @20 -IgniteTargetInObjectStreamOutStream @21 -IgniteTargetListenFuture @22 -IgniteTargetListenFutureForOperation @23 -IgniteAffinityPartitions @24 -IgniteCacheWithSkipStore @25 -IgniteCacheWithNoRetries @26 -IgniteCacheWithExpiryPolicy @27 -IgniteCacheWithAsync @28 -IgniteCacheWithKeepPortable @29 -IgniteCacheClear @30 -IgniteCacheRemoveAll @31 -IgniteCacheOutOpQueryCursor @32 -IgniteCacheOutOpContinuousQuery @33 -IgniteCacheIterator @34 -IgniteCacheLocalIterator @35 -IgniteCacheEnterLock @36 -IgniteCacheExitLock @37 -IgniteCacheTryEnterLock @38 -IgniteCacheCloseLock @39 -IgniteCacheRebalance @40 -IgniteCacheSize @41 -IgniteCacheStoreCallbackInvoke @42 -IgniteComputeWithNoFailover @43 -IgniteComputeWithTimeout @44 -IgniteComputeExecuteNative @45 -IgniteContinuousQueryClose @46 -IgniteContinuousQueryGetInitialQueryCursor @47 -IgniteDataStreamerListenTopology @48 -IgniteDataStreamerAllowOverwriteGet @49 -IgniteDataStreamerAllowOverwriteSet @50 -IgniteDataStreamerSkipStoreGet @51 -IgniteDataStreamerSkipStoreSet @52 -IgniteDataStreamerPerNodeBufferSizeGet @53 -IgniteDataStreamerPerNodeBufferSizeSet @54 -IgniteDataStreamerPerNodeParallelOperationsGet @55 -IgniteDataStreamerPerNodeParallelOperationsSet @56 -IgniteMessagingWithAsync @57 -IgniteProjectionForOthers @58 -IgniteProjectionForRemotes @59 -IgniteProjectionForDaemons @60 -IgniteProjectionForRandom @61 -IgniteProjectionForOldest @62 -IgniteProjectionForYoungest @63 -IgniteProcessorCompute @64 -IgniteProcessorMessage @65 -IgniteProcessorEvents @66 -IgniteProjectionResetMetrics @67 -IgniteProjectionOutOpRet @68 -IgniteQueryCursorIterator @69 -IgniteQueryCursorClose @70 -IgniteTransactionsStart @71 -IgniteTransactionsCommit @72 -IgniteTransactionsCommitAsync @73 -IgniteTransactionsRollback @74 -IgniteTransactionsRollbackAsync @75 -IgniteTransactionsClose @76 -IgniteTransactionsState @77 -IgniteTransactionsSetRollbackOnly @78 -IgniteTransactionsResetMetrics @79 -IgniteAcquire @80 -IgniteRelease @81 -IgniteThrowToJava @82 -IgniteHandlersSize @83 -IgniteCreateContext @84 -IgniteDeleteContext @85 -IgniteDestroyJvm @86 -IgniteEventsWithAsync @87 -IgniteEventsStopLocalListen @88 -IgniteEventsLocalListen @89 -IgniteEventsIsEnabled @90 -IgniteTargetOutObject @91 -IgniteServicesWithAsync @92 -IgniteServicesWithServerKeepPortable @93 -IgniteServicesCancel @94 -IgniteServicesCancelAll @95 -IgniteServicesGetServiceProxy @96 -IgniteProcessorExtensions @97 -IgniteProcessorAtomicLong @98 -IgniteAtomicLongGet @99 -IgniteAtomicLongIncrementAndGet @100 -IgniteAtomicLongGetAndIncrement @101 -IgniteAtomicLongAddAndGet @102 -IgniteAtomicLongGetAndAdd @103 -IgniteAtomicLongDecrementAndGet @104 -IgniteAtomicLongGetAndDecrement @105 -IgniteAtomicLongGetAndSet @106 -IgniteAtomicLongCompareAndSetAndGet @107 -IgniteAtomicLongIsClosed @108 -IgniteAtomicLongClose @109 -IgniteListenableCancel @110 -IgniteListenableIsCancelled @111 -IgniteTargetListenFutureAndGet @112 -IgniteTargetListenFutureForOperationAndGet @113 -IgniteProcessorCreateCacheFromConfig @114 -IgniteProcessorGetOrCreateCacheFromConfig @115 -IgniteProcessorGetIgniteConfiguration @116 -IgniteProcessorDestroyCache @117 -IgniteProcessorAtomicSequence @118 -IgniteAtomicSequenceGet @119 -IgniteAtomicSequenceIncrementAndGet @120 -IgniteAtomicSequenceGetAndIncrement @121 -IgniteAtomicSequenceAddAndGet @122 -IgniteAtomicSequenceGetAndAdd @123 -IgniteAtomicSequenceGetBatchSize @124 -IgniteAtomicSequenceSetBatchSize @125 -IgniteAtomicSequenceIsClosed @126 -IgniteAtomicSequenceClose @127 -IgniteProcessorAtomicReference @128 -IgniteAtomicReferenceIsClosed @129 -IgniteAtomicReferenceClose @130 -IgniteProcessorCreateNearCache @131 -IgniteProcessorGetOrCreateNearCache @132 -IgniteProcessorGetCacheNames @133 http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/src/common/concurrent.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/src/common/concurrent.cpp b/modules/platforms/cpp/common/src/common/concurrent.cpp new file mode 100644 index 0000000..5b62387 --- /dev/null +++ b/modules/platforms/cpp/common/src/common/concurrent.cpp @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ignite/common/concurrent.h" + +namespace ignite +{ + namespace common + { + namespace concurrent + { + /** Thread-local index generator for application. */ + int32_t appTlsIdxGen = 0; + + int32_t ThreadLocal::NextIndex() + { + return Atomics::IncrementAndGet32(&appTlsIdxGen); + } + + void ThreadLocal::Remove(int32_t idx) + { + void* val = Get0(); + + if (val) + { + std::map* map = + static_cast*>(val); + + ThreadLocalEntry* appVal = (*map)[idx]; + + if (appVal) + delete appVal; + + map->erase(idx); + + if (map->size() == 0) + { + delete map; + + Set0(NULL); + } + } + } + + void ThreadLocal::Clear0(void* mapPtr) + { + if (mapPtr) + { + std::map* map = + static_cast*>(mapPtr); + + for (std::map::iterator it = map->begin(); it != map->end(); ++it) + delete it->second; + + delete map; + } + } + + SharedPointerImpl::SharedPointerImpl(void* ptr, DeleterType deleter) : + ptr(ptr), deleter(deleter), refCnt(1) + { + Memory::Fence(); + } + + void* SharedPointerImpl::Pointer() + { + return ptr; + } + + const void* SharedPointerImpl::Pointer() const + { + return ptr; + } + + SharedPointerImpl::DeleterType SharedPointerImpl::Deleter() + { + return deleter; + } + + void SharedPointerImpl::Increment() + { + Atomics::IncrementAndGet32(&refCnt); + } + + bool SharedPointerImpl::Decrement() + { + return Atomics::DecrementAndGet32(&refCnt) == 0; + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/src/concurrent.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/src/concurrent.cpp b/modules/platforms/cpp/common/src/concurrent.cpp deleted file mode 100644 index 5b62387..0000000 --- a/modules/platforms/cpp/common/src/concurrent.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/common/concurrent.h" - -namespace ignite -{ - namespace common - { - namespace concurrent - { - /** Thread-local index generator for application. */ - int32_t appTlsIdxGen = 0; - - int32_t ThreadLocal::NextIndex() - { - return Atomics::IncrementAndGet32(&appTlsIdxGen); - } - - void ThreadLocal::Remove(int32_t idx) - { - void* val = Get0(); - - if (val) - { - std::map* map = - static_cast*>(val); - - ThreadLocalEntry* appVal = (*map)[idx]; - - if (appVal) - delete appVal; - - map->erase(idx); - - if (map->size() == 0) - { - delete map; - - Set0(NULL); - } - } - } - - void ThreadLocal::Clear0(void* mapPtr) - { - if (mapPtr) - { - std::map* map = - static_cast*>(mapPtr); - - for (std::map::iterator it = map->begin(); it != map->end(); ++it) - delete it->second; - - delete map; - } - } - - SharedPointerImpl::SharedPointerImpl(void* ptr, DeleterType deleter) : - ptr(ptr), deleter(deleter), refCnt(1) - { - Memory::Fence(); - } - - void* SharedPointerImpl::Pointer() - { - return ptr; - } - - const void* SharedPointerImpl::Pointer() const - { - return ptr; - } - - SharedPointerImpl::DeleterType SharedPointerImpl::Deleter() - { - return deleter; - } - - void SharedPointerImpl::Increment() - { - Atomics::IncrementAndGet32(&refCnt); - } - - bool SharedPointerImpl::Decrement() - { - return Atomics::DecrementAndGet32(&refCnt) == 0; - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/common/src/date.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/src/date.cpp b/modules/platforms/cpp/common/src/date.cpp new file mode 100644 index 0000000..2bdcfd5 --- /dev/null +++ b/modules/platforms/cpp/common/src/date.cpp @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ignite/date.h" + +namespace ignite +{ + Date::Date() : milliseconds(0) + { + // No-op. + } + + Date::Date(const Date& another) : milliseconds(another.milliseconds) + { + // No-op. + } + + Date::Date(int64_t ms) : milliseconds(ms) + { + // No-op. + } + + Date& Date::operator=(const Date& another) + { + milliseconds = another.milliseconds; + + return *this; + } + + int64_t Date::GetMilliseconds() const + { + return milliseconds; + } + + int64_t Date::GetSeconds() const + { + return milliseconds / 1000; + } + + bool operator==(const Date& val1, const Date& val2) + { + return val1.milliseconds == val2.milliseconds; + } + + bool operator!=(const Date& val1, const Date& val2) + { + return val1.milliseconds != val2.milliseconds; + } + + bool operator<(const Date& val1, const Date& val2) + { + return val1.milliseconds < val2.milliseconds; + } + + bool operator<=(const Date& val1, const Date& val2) + { + return val1.milliseconds <= val2.milliseconds; + } + + bool operator>(const Date& val1, const Date& val2) + { + return val1.milliseconds > val2.milliseconds; + } + + bool operator>=(const Date& val1, const Date& val2) + { + return val1.milliseconds >= val2.milliseconds; + } +}