Line 1... |
Line 1... |
/**
|
/*
|
* @file
|
* Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
|
* @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
|
*
|
* @author Sergey Khabarov - sergeykhbr@gmail.com
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
* @brief Core API utils methods implementation.
|
* 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 <string.h>
|
#include <string.h>
|
|
#include <stdlib.h>
|
#include <time.h>
|
#include <time.h>
|
#include <iostream>
|
#include <iostream>
|
#include <dirent.h>
|
#include <dirent.h>
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
#else
|
#else
|
Line 24... |
Line 34... |
|
|
/** Plugin Entry point type definition */
|
/** Plugin Entry point type definition */
|
typedef void (*plugin_init_proc)();
|
typedef void (*plugin_init_proc)();
|
|
|
/** Temporary buffer for the log messages. */
|
/** Temporary buffer for the log messages. */
|
static char bufLog[1<<12];
|
static char bufLog[1024*1024];
|
static int uniqueIdx_ = 0;
|
static int uniqueIdx_ = 0;
|
|
|
/** Redirect output to specified console. */
|
/** Redirect output to specified console. */
|
static AttributeType default_console(Attr_List);
|
static AttributeType default_console(Attr_List);
|
mutex_def mutexDefaultConsoles_;
|
mutex_def mutexDefaultConsoles_;
|
Line 184... |
Line 194... |
#else
|
#else
|
return getpid();
|
return getpid();
|
#endif
|
#endif
|
}
|
}
|
|
|
|
extern "C" void RISCV_memory_barrier() {
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
MemoryBarrier();
|
|
#else
|
|
__sync_synchronize();
|
|
#endif
|
|
}
|
|
|
extern "C" void RISCV_thread_create(void *data) {
|
extern "C" void RISCV_thread_create(void *data) {
|
LibThreadType *p = (LibThreadType *)data;
|
LibThreadType *p = (LibThreadType *)data;
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
p->Handle = (thread_def)_beginthreadex(0, 0, p->func, p->args, 0, 0);
|
p->Handle = (thread_def)_beginthreadex(0, 0, p->func, p->args, 0, 0);
|
Line 308... |
Line 325... |
}
|
}
|
return 0;
|
return 0;
|
#endif
|
#endif
|
}
|
}
|
|
|
|
extern "C" sharemem_def RISCV_memshare_create(const char *name, int sz) {
|
|
sharemem_def ret = 0;
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
ret = CreateFileMapping(
|
|
INVALID_HANDLE_VALUE, // use paging file
|
|
NULL, // default security
|
|
PAGE_READWRITE, // read/write access
|
|
0, // maximum object size (high-order DWORD)
|
|
sz, // maximum object size (low-order DWORD)
|
|
name); // name of mapping object
|
|
#else
|
|
#endif
|
|
if (!ret) {
|
|
RISCV_error("Couldn't create map object %s", name);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
extern "C" void* RISCV_memshare_map(sharemem_def h, int sz) {
|
|
void *ret = 0;
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
ret = MapViewOfFile(h, // handle to map object
|
|
FILE_MAP_ALL_ACCESS, // read/write permission
|
|
0,
|
|
0,
|
|
sz);
|
|
#else
|
|
#endif
|
|
if (!ret) {
|
|
RISCV_error("Couldn't map view of file with size %d", sz);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
extern "C" void RISCV_memshare_unmap(void *buf) {
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
UnmapViewOfFile(buf);
|
|
#else
|
|
#endif
|
|
}
|
|
|
|
extern "C" void RISCV_memshare_delete(sharemem_def h) {
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
|
CloseHandle(h);
|
|
#else
|
|
#endif
|
|
}
|
|
|
extern "C" int RISCV_mutex_init(mutex_def *mutex) {
|
extern "C" int RISCV_mutex_init(mutex_def *mutex) {
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
InitializeCriticalSection(mutex);
|
InitializeCriticalSection(mutex);
|
#else
|
#else
|
pthread_mutex_init(mutex, NULL);
|
pthread_mutex_init(mutex, NULL);
|
Line 451... |
Line 516... |
}
|
}
|
#else
|
#else
|
// reset errors
|
// reset errors
|
dlerror();
|
dlerror();
|
if ((hlib = dlopen(plugin_lib.c_str(), RTLD_LAZY)) == 0) {
|
if ((hlib = dlopen(plugin_lib.c_str(), RTLD_LAZY)) == 0) {
|
RISCV_info("Can't open library '%s': %s",
|
printf("Can't open library '%s': %s\n",
|
plugin_lib.c_str(), dlerror());
|
plugin_lib.c_str(), dlerror());
|
continue;
|
continue;
|
}
|
}
|
plugin_init = (plugin_init_proc)dlsym(hlib, "plugin_init");
|
plugin_init = (plugin_init_proc)dlsym(hlib, "plugin_init");
|
if (dlerror()) {
|
if (dlerror()) {
|
RISCV_info("Not found plugin_init() in file '%s'",
|
printf("Not found plugin_init() in file '%s'\n",
|
plugin_lib.c_str());
|
plugin_lib.c_str());
|
dlclose(hlib);
|
dlclose(hlib);
|
continue;
|
continue;
|
}
|
}
|
#endif
|
#endif
|