Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/libdap
1 result
Show changes
Commits on Source (6)
......@@ -104,6 +104,11 @@ if(DARWIN)
target_link_libraries(${PROJECT_NAME} dap_core_darwin)
endif()
if(ANDROID)
add_subdirectory(src/android)
target_link_libraries(${PROJECT_NAME} dap_core_android)
endif()
if(BUILD_DAP_TESTS)
enable_testing()
add_subdirectory(test)
......
......@@ -352,6 +352,7 @@ void dap_set_log_tag_width(size_t width);
char *dap_itoa(int i);
int dap_time_to_str_rfc822(char * out, size_t out_size_max, time_t t);
int timespec_diff(struct timespec *a_start, struct timespec *a_stop, struct timespec *a_result);
int get_select_breaker(void);
int send_select_break(void);
......
......@@ -74,7 +74,10 @@ char* dap_strdown(const char *a_str, ssize_t a_len);
char* dap_strreverse(char *a_string);
#ifdef _WIN32
char *strndup(char *str, unsigned long len);
#ifdef HAVE_STRNDUP
#define strndup(s, l) _strndup(s, l)
#endif
char *_strndup(char *str, unsigned long len);
#endif
#define DAP_USEC_PER_SEC 1000000
......
cmake_minimum_required(VERSION 3.0)
project (dap_core_android C)
file(GLOB CORE_ANDROID_SRCS *.c)
file(GLOB CORE_ANDROID_HEADERS *.h)
add_library(${PROJECT_NAME} STATIC ${CORE_ANDROID_SRCS} ${CORE_ANDROID_HEADERS})
#target_link_libraries(${PROJECT_NAME} dap_core pthread)
target_include_directories(${PROJECT_NAME} INTERFACE .)
#if __ANDROID_API__ < __ANDROID_API_N__
#include "pthread_barrier.h"
#include <errno.h>
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
{
if(count == 0)
{
errno = EINVAL;
return -1;
}
if(pthread_mutex_init(&barrier->mutex, 0) < 0)
{
return -2;
}
if(pthread_cond_init(&barrier->cond, 0) < 0)
{
pthread_mutex_destroy(&barrier->mutex);
return -3;
}
barrier->tripCount = count;
barrier->count = 0;
return 0;
}
int pthread_barrier_destroy(pthread_barrier_t *barrier)
{
pthread_cond_destroy(&barrier->cond);
pthread_mutex_destroy(&barrier->mutex);
return 0;
}
int pthread_barrier_wait(pthread_barrier_t *barrier)
{
pthread_mutex_lock(&barrier->mutex);
++(barrier->count);
if(barrier->count >= barrier->tripCount)
{
barrier->count = 0;
pthread_cond_broadcast(&barrier->cond);
pthread_mutex_unlock(&barrier->mutex);
return 1;
}
else
{
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
pthread_mutex_unlock(&barrier->mutex);
return 0;
}
}
#endif
#ifndef PTHREAD_BARRIER_H
#define PTHREAD_BARRIER_H
#include <pthread.h>
#if __ANDROID_API__ < __ANDROID_API_N__
typedef int pthread_barrierattr_t;
typedef struct
{
pthread_mutex_t mutex;
pthread_cond_t cond;
int count;
int tripCount;
} pthread_barrier_t;
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count);
int pthread_barrier_destroy(pthread_barrier_t *barrier);
int pthread_barrier_wait(pthread_barrier_t *barrier);
#endif // PTHREAD_BARRIER_H
#endif // PTHREAD_BARRIER_H
......@@ -370,6 +370,32 @@ int dap_time_to_str_rfc822(char * out, size_t out_size_max, time_t t)
return ret;
}
/**
* @brief Calculate diff of two struct timespec
* @param[in] a_start - first time
* @param[in] a_stop - second time
* @param[out] a_result - diff time, may be NULL
* @return diff time in millisecond
*/
int timespec_diff(struct timespec *a_start, struct timespec *a_stop, struct timespec *a_result)
{
if(!a_start || !a_stop)
return 0;
if(!a_result) {
struct timespec l_time_tmp = { 0 };
a_result = &l_time_tmp;
}
if((a_stop->tv_nsec - a_start->tv_nsec) < 0) {
a_result->tv_sec = a_stop->tv_sec - a_start->tv_sec - 1;
a_result->tv_nsec = a_stop->tv_nsec - a_start->tv_nsec + 1000000000;
} else {
a_result->tv_sec = a_stop->tv_sec - a_start->tv_sec;
a_result->tv_nsec = a_stop->tv_nsec - a_start->tv_nsec;
}
return (a_result->tv_sec * 1000 + a_result->tv_nsec / 1000000);
}
#define BREAK_LATENCY 1
static int breaker_set[2] = { -1, -1 };
......
......@@ -690,7 +690,7 @@ char *strptime( char *buff, const char *fmt, struct tm *tm ) {
return buff + len;
}
char *strndup(char *str, unsigned long len) {
char *_strndup(char *str, unsigned long len) {
char *buf = (char*)memchr(str, '\0', len);
if (buf)
len = buf - str;
......
......@@ -53,6 +53,11 @@ extern "C" {
//! Flag to rpaligned_realloc to not preserve content in reallocation
#define RPMALLOC_NO_PRESERVE 1
//redefinition from mman-linux.h For POSIX
#ifndef POSIX_MADV_DONTNEED
#define POSIX_MADV_DONTNEED 4/* Don't need these pages. */
#endif
typedef struct rpmalloc_global_statistics_t {
//! Current amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1)
size_t mapped;
......
......@@ -13,7 +13,11 @@ endif()
add_library(${PROJECT_NAME} STATIC ${CORE_UNIX_SRCS} ${CORE_UNIX_HEADERS}
${CORE_LINUX_SRCS} ${CORE_LINUX_HEADERS})
target_link_libraries(${PROJECT_NAME} dap_core pthread)
target_link_libraries(${PROJECT_NAME} dap_core)
if (NOT ANDROID)
target_link_libraries(${PROJECT_NAME} pthread)
endif()
target_include_directories(dap_core_unix INTERFACE .)
......