szaszm commented on a change in pull request #674: Minificpp 1007 - ECU C2 integration. URL: https://github.com/apache/nifi-minifi-cpp/pull/674#discussion_r371959937
########## File path: nanofi/src/core/synchutils.c ########## @@ -0,0 +1,189 @@ +/** + * + * 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 <assert.h> +#include <errno.h> +#include <stdint.h> +#include <core/synchutils.h> + +void initialize_lock(lock_t * lock) { +#ifndef WIN32 + pthread_mutex_init(&lock->mutex, NULL); +#else + InitializeCriticalSection(&lock->cs); +#endif +} + +#ifndef WIN32 +void initialize_cvattr(conditionvariable_attr_t * cv_attr) { + assert(cv_attr != NULL); + pthread_condattr_init(&cv_attr->cv_attr); + cv_attr->initialized = 1; +} +#endif + +#if !defined(_WIN32) && !defined(__APPLE__) +void condition_attr_set_clock(conditionvariable_attr_t * cv_attr, clockid_t clock) { + assert(cv_attr != NULL); + pthread_condattr_setclock(&cv_attr->cv_attr, clock); +} +#endif + +void initialize_cv(conditionvariable_t * cv, conditionvariable_attr_t * cv_attr) { + assert(cv != NULL); +#ifndef WIN32 + if (cv_attr && cv_attr->initialized) { + pthread_cond_init(&cv->cv, &cv_attr->cv_attr); + } + else { + pthread_cond_init(&cv->cv, NULL); + } +#else + InitializeConditionVariable(&cv->cv); +#endif +} + +void acquire_lock(lock_t * lock) { + assert(lock != NULL); +#ifndef WIN32 + pthread_mutex_lock(&lock->mutex); +#else + EnterCriticalSection(&lock->cs); +#endif +} + +void release_lock(lock_t * lock) { + assert(lock != NULL); +#ifndef WIN32 + pthread_mutex_unlock(&lock->mutex); +#else + LeaveCriticalSection(&lock->cs); +#endif +} + +#ifndef WIN32 +uint64_t get_time_millis(struct timespec ts) { + ts.tv_sec += ts.tv_nsec / 1000000000L; + ts.tv_nsec = ts.tv_nsec % 1000000000L; + + uint64_t ms = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000L); + ts.tv_nsec = ts.tv_nsec % 1000000L; + + ms += lround((double)((double)ts.tv_nsec / 1000000L)); + return ms; +} + +struct timespec get_timespec_millis_from_now(uint64_t millis) { + struct timespec ts; + memset(&ts, 0, sizeof(ts)); Review comment: Missing `#include <string.h>` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
