Skip to content
Snippets Groups Projects
Commit c593893e authored by naeper's avatar naeper
Browse files

:q

parent 290c54ae
No related branches found
No related tags found
No related merge requests found
Pipeline #7277 passed with stage
in 11 seconds
...@@ -2,7 +2,7 @@ project(cellframe-sdk C) ...@@ -2,7 +2,7 @@ project(cellframe-sdk C)
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(CELLFRAME_SDK_NATIVE_VERSION "2.8-22") set(CELLFRAME_SDK_NATIVE_VERSION "2.8-23")
add_definitions ("-DCELLFRAME_SDK_VERSION=\"${CELLFRAME_SDK_NATIVE_VERSION}\"") add_definitions ("-DCELLFRAME_SDK_VERSION=\"${CELLFRAME_SDK_NATIVE_VERSION}\"")
set(DAPSDK_MODULES "") set(DAPSDK_MODULES "")
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
QMAKE_CFLAGS_DEBUG += -DDAP_DEBUG QMAKE_CFLAGS_DEBUG += -DDAP_DEBUG
QMAKE_CXXFLAGS += -std=c++11 QMAKE_CXXFLAGS += -std=c++11
QMAKE_CFLAGS += -std=gnu11 QMAKE_CFLAGS += -std=gnu11
unix { unix {
include(src/unix/unix.pri) include(src/unix/unix.pri)
DEFINES += DAP_OS_UNIX DEFINES += DAP_OS_UNIX
...@@ -12,15 +13,17 @@ android { ...@@ -12,15 +13,17 @@ android {
DEFINES += DAP_OS_ANDROID DAP_OS_LINUX DAP_OS_UNIX DEFINES += DAP_OS_ANDROID DAP_OS_LINUX DAP_OS_UNIX
} }
unix: !android { unix: !android : ! darwin {
QMAKE_CFLAGS_DEBUG += -Wall -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols -fno-strict-aliasing QMAKE_CFLAGS_DEBUG += -Wall -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols -fno-strict-aliasing
QMAKE_LFLAGS_DEBUG += -pg QMAKE_LFLAGS_DEBUG += -pg
DEFINES += _GNU_SOURCE DEFINES += _GNU_SOURCE
LIBS += -lrt -ljson-c -lmagic LIBS += -lrt -ljson-c -lmagic
} }
darwin { darwin {
QMAKE_CFLAGS_DEBUG += -Wall -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -g3 -ggdb -fno-eliminate-unused-debug-symbols -fno-strict-aliasing
DEFINES += _GNU_SOURCE
include(src/darwin/darwin.pri) include(src/darwin/darwin.pri)
DEFINES += DAP_OS_DARWIN DEFINES += DAP_OS_DARWIN DAP_OS_BSD
LIBS -= -lrt LIBS -= -lrt
} }
......
...@@ -969,12 +969,14 @@ int dap_interval_timer_delete(void *a_timer) ...@@ -969,12 +969,14 @@ int dap_interval_timer_delete(void *a_timer)
if (s_timers_count == 0) { if (s_timers_count == 0) {
pthread_mutex_destroy(&s_timers_lock); pthread_mutex_destroy(&s_timers_lock);
} }
#ifdef DAP_OS_UNIX #ifdef DAP_OS_DARWIN
return timer_delete((timer_t)a_timer);
#else
dispatch_source_cancel(a_timer); dispatch_source_cancel(a_timer);
return 0; return 0;
#elif defined(DAP_OS_UNIX)
// POSIX timer delete
return timer_delete((timer_t)a_timer);
#endif // DAP_OS_UNIX #endif // DAP_OS_UNIX
#endif // _WIN32 #endif // _WIN32
} }
......
...@@ -3,7 +3,7 @@ HEADERS += $$PWD/pthread_barrier.h ...@@ -3,7 +3,7 @@ HEADERS += $$PWD/pthread_barrier.h
SOURCES += $$PWD/dap_network_monitor.c SOURCES += $$PWD/dap_network_monitor.c
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD /usr/local/include
LIBS += -framework CoreFoundation LIBS += -framework CoreFoundation
LIBS += -framework SystemConfiguration LIBS += -framework SystemConfiguration
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <stdint.h> #include <stdint.h>
#ifdef DAP_OS_UNIX #ifdef DAP_OS_UNIX
#include <pthread.h>
#include <fcntl.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
...@@ -46,22 +48,29 @@ ...@@ -46,22 +48,29 @@
#include <signal.h> #include <signal.h>
#include <sched.h> #include <sched.h>
#ifdef DAP_OS_LINUX #if defined(DAP_OS_LINUX)
#include <sys/timerfd.h> #include <sys/timerfd.h>
#endif #endif
#if defined(DAP_OS_BSD)
#include <sys/event.h>
#include <err.h>
#endif
#include <pthread.h> #if defined(DAP_OS_DARWIN)
#include <sys/types.h>
#include <sys/sysctl.h>
#ifdef DAP_OS_BSD #include <mach/thread_policy.h>
#include <mach/thread_act.h>
#elif defined (DAP_OS_BSD)
#include <pthread_np.h> #include <pthread_np.h>
#include <sys/event.h>
#include <err.h>
#include <fcntl.h>
typedef cpuset_t cpu_set_t; // Adopt BSD CPU setstructure to POSIX variant typedef cpuset_t cpu_set_t; // Adopt BSD CPU setstructure to POSIX variant
#endif #endif
#if defined(DAP_OS_ANDROID) #if defined(DAP_OS_ANDROID)
#define NO_POSIX_SHED #define NO_POSIX_SHED
#define NO_TIMER #define NO_TIMER
...@@ -78,6 +87,7 @@ typedef cpuset_t cpu_set_t; // Adopt BSD CPU setstructure to POSIX variant ...@@ -78,6 +87,7 @@ typedef cpuset_t cpu_set_t; // Adopt BSD CPU setstructure to POSIX variant
#endif #endif
#include <utlist.h> #include <utlist.h>
#include <pthread.h>
#include "dap_common.h" #include "dap_common.h"
#include "dap_strfuncs.h" #include "dap_strfuncs.h"
...@@ -103,20 +113,31 @@ uint32_t dap_get_cpu_count( ) ...@@ -103,20 +113,31 @@ uint32_t dap_get_cpu_count( )
return si.dwNumberOfProcessors; return si.dwNumberOfProcessors;
#else #else
#ifndef NO_POSIX_SHED #ifndef NO_POSIX_SHED
#ifndef DAP_OS_DARWIN
cpu_set_t cs; cpu_set_t cs;
CPU_ZERO( &cs ); CPU_ZERO( &cs );
#endif
#if defined (DAP_OS_ANDROID) #if defined (DAP_OS_ANDROID)
sched_getaffinity( 0, sizeof(cs), &cs ); sched_getaffinity( 0, sizeof(cs), &cs );
#elif defined (DAP_OS_DARWIN)
int count=0;
size_t count_len = sizeof(count);
sysctlbyname("hw.logicalcpu", &count, &count_len, NULL, 0);
#else #else
pthread_getaffinity_np(pthread_self(), sizeof(cs), &cs); pthread_getaffinity_np(pthread_self(), sizeof(cs), &cs);
#endif #endif
#ifndef DAP_OS_DARWIN
uint32_t count = 0; uint32_t count = 0;
for ( int i = 0; i < 32; i++ ){ for ( int i = 0; i < 32; i++ ){
if ( CPU_ISSET(i, &cs) ) if ( CPU_ISSET(i, &cs) )
count ++; count ++;
} }
#endif
return count; return count;
#else #else
return 1; return 1;
#endif #endif
...@@ -127,15 +148,23 @@ void dap_cpu_assign_thread_on(uint32_t a_cpu_id) ...@@ -127,15 +148,23 @@ void dap_cpu_assign_thread_on(uint32_t a_cpu_id)
{ {
#ifndef DAP_OS_WINDOWS #ifndef DAP_OS_WINDOWS
#ifndef NO_POSIX_SHED #ifndef NO_POSIX_SHED
#ifdef DAP_OS_DARWIN
pthread_t l_pthread_id = pthread_self();
mach_port_t l_pthread_mach_port = pthread_mach_thread_np(l_pthread_id);
#else
cpu_set_t mask; cpu_set_t mask;
CPU_ZERO(&mask); CPU_ZERO(&mask);
CPU_SET(a_cpu_id, &mask); CPU_SET(a_cpu_id, &mask);
#endif
int l_retcode; int l_retcode;
#ifndef __ANDROID__ #ifdef DAP_OS_DARWIN
l_retcode = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mask); thread_affinity_policy_data_t l_policy_data={.affinity_tag = a_cpu_id};
thread_policy_set(l_pthread_mach_port , THREAD_AFFINITY_POLICY, (thread_policy_t)&l_policy_data , 1);
#elif defined(DAP_OS_ANDROID)
err = sched_setaffinity(pthread_self(), sizeof(cpu_set_t), &mask);
#else #else
err = sched_setaffinity(pthread_self(), sizeof(cpu_set_t), &mask); l_retcode = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mask);
#endif #endif
if(l_retcode != 0) if(l_retcode != 0)
{ {
......
...@@ -59,10 +59,17 @@ ...@@ -59,10 +59,17 @@
#endif #endif
#ifdef DAP_OS_BSD #ifdef DAP_OS_BSD
#include <pthread_np.h>
#include <sys/event.h> #include <sys/event.h>
#include <err.h> #include <err.h>
#ifndef DAP_OS_DARWIN
#include <pthread_np.h>
typedef cpuset_t cpu_set_t; // Adopt BSD CPU setstructure to POSIX variant typedef cpuset_t cpu_set_t; // Adopt BSD CPU setstructure to POSIX variant
#else
#define NOTE_READ NOTE_LOWAT
#endif
#endif #endif
...@@ -176,7 +183,11 @@ dap_events_socket_t *dap_events_socket_wrap_no_add( dap_events_t *a_events, ...@@ -176,7 +183,11 @@ dap_events_socket_t *dap_events_socket_wrap_no_add( dap_events_t *a_events,
l_ret->poll_base_flags = POLLERR | POLLRDHUP | POLLHUP; l_ret->poll_base_flags = POLLERR | POLLRDHUP | POLLHUP;
#elif defined(DAP_EVENTS_CAPS_KQUEUE) #elif defined(DAP_EVENTS_CAPS_KQUEUE)
l_ret->kqueue_base_flags = EV_ADD | EV_ENABLE | EV_CLEAR; l_ret->kqueue_base_flags = EV_ADD | EV_ENABLE | EV_CLEAR;
l_ret->kqueue_base_fflags = NOTE_CLOSE | NOTE_CLOSE_WRITE | NOTE_DELETE | NOTE_REVOKE ;
l_ret->kqueue_base_fflags = NOTE_DELETE | NOTE_REVOKE ;
#if !defined(DAP_OS_DARWIN)
l_ret->kqueue_base_fflags |= NOTE_CLOSE | NOTE_CLOSE_WRITE ;
#endif
l_ret->kqueue_base_filter = EVFILT_VNODE; l_ret->kqueue_base_filter = EVFILT_VNODE;
#endif #endif
...@@ -278,7 +289,10 @@ dap_events_socket_t * s_create_type_pipe(dap_worker_t * a_w, dap_events_socket_c ...@@ -278,7 +289,10 @@ dap_events_socket_t * s_create_type_pipe(dap_worker_t * a_w, dap_events_socket_c
l_es->poll_base_flags = POLLIN | POLLERR | POLLRDHUP | POLLHUP; l_es->poll_base_flags = POLLIN | POLLERR | POLLRDHUP | POLLHUP;
#elif defined(DAP_EVENTS_CAPS_KQUEUE) #elif defined(DAP_EVENTS_CAPS_KQUEUE)
l_es->kqueue_base_flags = EV_ADD | EV_ENABLE | EV_CLEAR; l_es->kqueue_base_flags = EV_ADD | EV_ENABLE | EV_CLEAR;
l_es->kqueue_base_fflags = NOTE_CLOSE | NOTE_CLOSE_WRITE | NOTE_DELETE | NOTE_REVOKE ; l_es->kqueue_base_fflags = NOTE_DELETE | NOTE_REVOKE ;
#if !defined(DAP_OS_DARWIN)
l_es->kqueue_base_fflags |= NOTE_CLOSE | NOTE_CLOSE_WRITE ;
#endif
l_es->kqueue_base_filter = EVFILT_VNODE; l_es->kqueue_base_filter = EVFILT_VNODE;
#else #else
#error "Not defined s_create_type_pipe for your platform" #error "Not defined s_create_type_pipe for your platform"
...@@ -361,7 +375,11 @@ dap_events_socket_t * dap_events_socket_create(dap_events_desc_type_t a_type, da ...@@ -361,7 +375,11 @@ dap_events_socket_t * dap_events_socket_create(dap_events_desc_type_t a_type, da
if (ioctlsocket((SOCKET)l_sock, (long)FIONBIO, &l_socket_flags)) if (ioctlsocket((SOCKET)l_sock, (long)FIONBIO, &l_socket_flags))
log_it(L_ERROR, "Error ioctl %d", WSAGetLastError()); log_it(L_ERROR, "Error ioctl %d", WSAGetLastError());
#else #else
int l_sock = socket(l_sock_class, l_sock_type | SOCK_NONBLOCK , 0); int l_sock = socket(l_sock_class, l_sock_type, 0);
int l_sock_flags = fcntl( l_sock, F_GETFL);
l_sock_flags |= O_NONBLOCK;
fcntl( l_sock, F_SETFL, l_sock_flags);
if (l_sock == INVALID_SOCKET) { if (l_sock == INVALID_SOCKET) {
log_it(L_ERROR, "Socket create error"); log_it(L_ERROR, "Socket create error");
return NULL; return NULL;
......
...@@ -32,10 +32,17 @@ ...@@ -32,10 +32,17 @@
#elif defined (DAP_EVENTS_CAPS_POLL) #elif defined (DAP_EVENTS_CAPS_POLL)
#include <poll.h> #include <poll.h>
#elif defined (DAP_EVENTS_CAPS_KQUEUE) #elif defined (DAP_EVENTS_CAPS_KQUEUE)
#include <pthread_np.h>
#include <sys/event.h> #include <sys/event.h>
#include <err.h> #include <err.h>
#ifndef DAP_OS_DARWIN
#include <pthread_np.h>
typedef cpuset_t cpu_set_t; // Adopt BSD CPU setstructure to POSIX variant typedef cpuset_t cpu_set_t; // Adopt BSD CPU setstructure to POSIX variant
#else
#define NOTE_READ NOTE_LOWAT
#endif
#else #else
#error "Unimplemented poll for this platform" #error "Unimplemented poll for this platform"
#endif #endif
...@@ -557,21 +564,24 @@ static void * s_proc_thread_function(void * a_arg) ...@@ -557,21 +564,24 @@ static void * s_proc_thread_function(void * a_arg)
l_flag_pri = l_cur_events & POLLPRI; l_flag_pri = l_cur_events & POLLPRI;
l_flag_msg = l_cur_events & POLLMSG; l_flag_msg = l_cur_events & POLLMSG;
#elif defined (DAP_EVENTS_CAPS_KQUEUE) #elif defined (DAP_EVENTS_CAPS_KQUEUE)
l_cur = (dap_events_socket_t*) l_thread->kqueue_events[n].udata; l_cur = (dap_events_socket_t*) l_thread->kqueue_events[n].udata;
if (!l_cur) assert(l_cur);
continue;
l_cur->kqueue_event_catched = &l_thread->kqueue_events[n]; l_cur->kqueue_event_catched = &l_thread->kqueue_events[n];
u_int l_cur_events = l_thread->kqueue_events[n].fflags; #ifndef DAP_OS_DARWIN
u_int l_cur_events = l_thread->kqueue_events[n].flags;
#else
uint32_t l_cur_events = l_thread->kqueue_events[n].fflags;
#endif
l_flag_write = l_cur_events & EVFILT_WRITE; l_flag_write = l_cur_events & EVFILT_WRITE;
l_flag_read = l_cur_events & EVFILT_READ; l_flag_read = l_cur_events & EVFILT_READ;
l_flag_error = l_cur_events & EVFILT_EXCEPT;
l_flag_nval = l_flag_pri = l_flag_msg = l_flag_hup= 0;
l_flag_rdhup = l_cur_events & EVFILT_EXCEPT & NOTE_DELETE;
#else #else
#error "Unimplemented fetch esocket after poll" #error "Unimplemented fetch esocket after poll"
#endif #endif
assert(l_cur);
if(!l_cur) {
log_it(L_ERROR, "dap_events_socket NULL");
continue;
}
if(s_debug_reactor) if(s_debug_reactor)
log_it(L_DEBUG, "Proc thread #%u esocket %p fd=%d type=%d flags=0x%0X (%s:%s:%s:%s:%s:%s:%s:%s)", l_thread->cpu_id, l_cur, l_cur->socket, log_it(L_DEBUG, "Proc thread #%u esocket %p fd=%d type=%d flags=0x%0X (%s:%s:%s:%s:%s:%s:%s:%s)", l_thread->cpu_id, l_cur, l_cur->socket,
l_cur->type, l_cur_events, l_flag_read?"read":"", l_flag_write?"write":"", l_flag_error?"error":"", l_cur->type, l_cur_events, l_flag_read?"read":"", l_flag_write?"write":"", l_flag_error?"error":"",
......
...@@ -156,8 +156,13 @@ dap_timerfd_t* dap_timerfd_create(uint64_t a_timeout_ms, dap_timerfd_callback_t ...@@ -156,8 +156,13 @@ dap_timerfd_t* dap_timerfd_create(uint64_t a_timeout_ms, dap_timerfd_callback_t
#elif defined (DAP_OS_BSD) #elif defined (DAP_OS_BSD)
l_events_socket->kqueue_base_flags = EV_ADD | EV_ONESHOT | EV_DISPATCH; l_events_socket->kqueue_base_flags = EV_ADD | EV_ONESHOT | EV_DISPATCH;
l_events_socket->kqueue_base_filter = EVFILT_TIMER; l_events_socket->kqueue_base_filter = EVFILT_TIMER;
#ifdef DAP_OS_DARWIN
l_events_socket->kqueue_base_fflags = NOTE_USECONDS;
l_events_socket->kqueue_data =(int64_t) a_timeout_ms*1000;
#else
l_events_socket->kqueue_base_fflags = NOTE_MSECONDS; l_events_socket->kqueue_base_fflags = NOTE_MSECONDS;
l_events_socket->kqueue_data =(int64_t) a_timeout_ms; l_events_socket->kqueue_data =(int64_t) a_timeout_ms;
#endif
l_events_socket->socket = rand(); l_events_socket->socket = rand();
#elif defined (DAP_OS_WINDOWS) #elif defined (DAP_OS_WINDOWS)
HANDLE l_th = CreateWaitableTimer(NULL, true, NULL); HANDLE l_th = CreateWaitableTimer(NULL, true, NULL);
......
...@@ -35,6 +35,11 @@ ...@@ -35,6 +35,11 @@
#elif defined DAP_OS_WINDOWS #elif defined DAP_OS_WINDOWS
#include <ws2tcpip.h> #include <ws2tcpip.h>
#endif #endif
#ifdef DAP_OS_DARWIN
#define NOTE_READ NOTE_LOWAT
#endif
#include "dap_common.h" #include "dap_common.h"
#include "dap_config.h" #include "dap_config.h"
#include "dap_math_ops.h" #include "dap_math_ops.h"
...@@ -214,13 +219,22 @@ void *dap_worker_thread(void *arg) ...@@ -214,13 +219,22 @@ void *dap_worker_thread(void *arg)
l_cur = l_worker->poll_esocket[n]; l_cur = l_worker->poll_esocket[n];
//log_it(L_DEBUG, "flags: returned events 0x%0X requested events 0x%0X",l_worker->poll[n].revents,l_worker->poll[n].events ); //log_it(L_DEBUG, "flags: returned events 0x%0X requested events 0x%0X",l_worker->poll[n].revents,l_worker->poll[n].events );
#elif defined (DAP_EVENTS_CAPS_KQUEUE) #elif defined (DAP_EVENTS_CAPS_KQUEUE)
l_cur = (dap_events_socket_t*) l_worker->kqueue_events[n].udata; struct kevent * l_kevent_selected = l_cur->kqueue_event_catched = &l_worker->kqueue_events[n];
u_int l_cur_flags = l_worker->kqueue_events[n].fflags; l_cur = (dap_events_socket_t*) l_kevent_selected->udata;
assert(l_cur);
#ifndef DAP_OS_DARWIN
u_int l_cur_flags = l_kevent_selected->flags;
#else
uint32_t l_cur_flags = l_kevent_selected->fflags;
#endif
l_flag_write = l_cur_flags & EVFILT_WRITE; l_flag_write = l_cur_flags & EVFILT_WRITE;
l_flag_read = l_cur_flags & EVFILT_READ; l_flag_read = l_cur_flags & EVFILT_READ;
if( !l_cur) l_flag_error = l_cur_flags & EVFILT_EXCEPT;
continue; l_flag_nval = l_flag_pri = l_flag_msg = l_flag_hup= 0;
l_cur->kqueue_event_catched = &l_worker->kqueue_events[n]; l_flag_rdhup = l_cur_flags & EVFILT_EXCEPT & NOTE_DELETE;
#else #else
#error "Unimplemented fetch esocket after poll" #error "Unimplemented fetch esocket after poll"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment