ivandasch commented on a change in pull request #9713: URL: https://github.com/apache/ignite/pull/9713#discussion_r781311826
########## File path: modules/platforms/cpp/network/include/ignite/network/data_buffer.h ########## @@ -0,0 +1,139 @@ +/* + * 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. + */ + +#ifndef _IGNITE_NETWORK_DATA_BUFFER +#define _IGNITE_NETWORK_DATA_BUFFER + +#include <ignite/impl/interop/interop_memory.h> +#include <ignite/impl/interop/interop_input_stream.h> + +namespace ignite +{ + namespace network + { + /** + * Data buffer. + */ + class IGNITE_IMPORT_EXPORT DataBuffer + { + public: + /** + * Default constructor. + */ + DataBuffer(); + + /** + * Constructor. + * + * @param data Data. + */ + explicit DataBuffer(const impl::interop::SP_ConstInteropMemory& data); + + /** + * Constructor. + * + * @param data Data. + * @param pos Start of data. + * @param len Length. + */ + DataBuffer(const impl::interop::SP_ConstInteropMemory& data, int32_t pos, int32_t len); + + /** + * Destructor. + */ + ~DataBuffer() + { + // No-op. + } + + /** + * Copy data from buffer to specified place in memory. + * + * @param dst Destination in memory. + * @param size Number of bytes to copy. + */ + void GetData(int8_t* dst, int32_t size); Review comment: May be rename to `CopyTo`? It'c a little bit embarrassing naming, IMHO. And is it necessary to use signed size here? ########## File path: modules/platforms/cpp/common/include/ignite/future.h ########## @@ -279,6 +279,130 @@ namespace ignite /** Shared state. */ common::concurrent::SharedPointer< common::SharedState<ValueType> > state; }; + + /** + * Specialization for shared pointer. + */ + template<typename T> + class Future< common::concurrent::SharedPointer<T> > + { + friend class common::Promise< common::concurrent::SharedPointer<T> >; + + public: + /** Template value type */ + typedef T ValueType; + + /** Template value type shared pointer */ + typedef common::concurrent::SharedPointer<ValueType> SP_ValueType; + + /** + * Copy constructor. + * + * @param src Instance to copy. + */ + Future(const Future<SP_ValueType>& src) : + state(src.state) + { + // No-op. + } + + /** + * Assignment operator. + * + * @param other Other instance. + * @return *this. + */ + Future& operator=(const Future<SP_ValueType>& other) + { Review comment: In copy assignment it is a good idea to check `this != &other`. Here and above in the file ########## File path: modules/platforms/cpp/common/include/ignite/future.h ########## @@ -279,6 +279,130 @@ namespace ignite /** Shared state. */ common::concurrent::SharedPointer< common::SharedState<ValueType> > state; }; + + /** + * Specialization for shared pointer. + */ + template<typename T> + class Future< common::concurrent::SharedPointer<T> > + { + friend class common::Promise< common::concurrent::SharedPointer<T> >; + + public: + /** Template value type */ + typedef T ValueType; + + /** Template value type shared pointer */ + typedef common::concurrent::SharedPointer<ValueType> SP_ValueType; + + /** + * Copy constructor. + * + * @param src Instance to copy. + */ + Future(const Future<SP_ValueType>& src) : + state(src.state) + { + // No-op. + } + + /** + * Assignment operator. + * + * @param other Other instance. + * @return *this. + */ + Future& operator=(const Future<SP_ValueType>& other) + { + state = other.state; + + return *this; + } + + /** + * Wait for value to be set. + * Active thread will be blocked until value or error will be set. + */ + void Wait() const + { + const common::SharedState<SP_ValueType>* state0 = state.Get(); + + assert(state0 != 0); Review comment: MAY be check for not `NULL`? ########## File path: modules/platforms/cpp/common/include/ignite/common/concurrent.h ########## @@ -20,6 +20,7 @@ #include <cassert> #include <utility> +#include <iostream> Review comment: Is `iostream` needed here? ########## File path: modules/platforms/cpp/common/os/linux/src/common/concurrent_os.cpp ########## @@ -203,6 +203,39 @@ namespace ignite pthread_setspecific(tlsKey, ptr); } + + Thread::Thread() : + thread() + { + // No-op. + } + + Thread::~Thread() + { + // No-op. + } + + void* Thread::ThreadRoutine(void* arg) + { + Thread* self = static_cast<Thread*>(arg); + + self->Run(); + + return 0; + } + + void Thread::Start() + { + int res = pthread_create(&thread, 0, Thread::ThreadRoutine, this); Review comment: May be use `NULL` here? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
