aboutsummaryrefslogtreecommitdiffstats
path: root/src/nSocket/include
diff options
context:
space:
mode:
authornanger <zhenyinan@huawei.com>2018-09-29 16:41:15 +0800
committernanger <zhenyinan@huawei.com>2018-09-29 16:45:14 +0800
commit74c9aed15303d388d7d0429128bc3af96f7eb45c (patch)
treeb4659364e410ef5b0f36b61bbf98c48e5763d8e5 /src/nSocket/include
parent31ea86798426cf236d70c9de1944c723a6cb1d95 (diff)
Refactor: change to dmm share memory
Change-Id: Iff87eb5c6610c1db9247a898dd4c8ffbe6eeabdf Signed-off-by: nanger <zhenyinan@huawei.com>
Diffstat (limited to 'src/nSocket/include')
-rw-r--r--src/nSocket/include/nstack_atomic.h57
-rw-r--r--src/nSocket/include/nstack_eventpoll.h26
-rw-r--r--src/nSocket/include/nstack_types.h1
-rw-r--r--src/nSocket/include/select_adapt.h11
4 files changed, 16 insertions, 79 deletions
diff --git a/src/nSocket/include/nstack_atomic.h b/src/nSocket/include/nstack_atomic.h
deleted file mode 100644
index bb5ec13..0000000
--- a/src/nSocket/include/nstack_atomic.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed 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 _NSTACK_ATOMIC_H_
-#define _NSTACK_ATOMIC_H_
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "nstack_types.h"
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-extern "C"{
-/* *INDENT-ON* */
-#endif
-
-typedef struct
-{
- volatile ns_int32 counter;
-} atomic_t;
-
-#define atomic_set(v, i) ((v)->counter = (i))
-
-#define atomic_fetch_and_add(v, i) __sync_fetch_and_add(&(v)->counter, i)
-#define atomic_add_and_fetch(v, i) __sync_add_and_fetch(&(v)->counter, i)
-
-#define atomic_fetch_and_sub(v, i) __sync_fetch_and_sub(&(v)->counter, i)
-#define atomic_sub_and_fetch(v, i) __sync_sub_and_fetch(&(v)->counter, i)
-
-#define atomic_read(v) atomic_fetch_and_add(v, 0)
-#define atomic_inc(v) atomic_add_and_fetch(v, 1)
-#define atomic_dec(v)atomic_sub_and_fetch(v, 1)
-#define atomic_add(v, i) atomic_add_and_fetch(v, i)
-#define atomic_sub(v, i) atomic_sub_and_fetch(v,i)
-
-#define cas(ptr, oldValue, exchange) __sync_bool_compare_and_swap(ptr, oldValue, exchange)
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-}
-/* *INDENT-ON* */
-#endif
-
-#endif
diff --git a/src/nSocket/include/nstack_eventpoll.h b/src/nSocket/include/nstack_eventpoll.h
index afb0b05..ac9622d 100644
--- a/src/nSocket/include/nstack_eventpoll.h
+++ b/src/nSocket/include/nstack_eventpoll.h
@@ -19,14 +19,17 @@
#include "ephlist.h"
#include "eprb_tree.h"
-#include "common_mem_api.h"
#include "types.h"
#include <semaphore.h>
#include <sys/epoll.h>
#include <stdio.h>
#include <stdlib.h>
+
+#include "nstack_types.h"
#include "nstack_securec.h"
#include "nstack_log.h"
+#include "dmm_ring.h"
+#include "dmm_spinlock.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -68,8 +71,7 @@ struct eventpoll
* Protect the this structure access
* This is for event add to ready list and poll out
*/
- sys_sem_st lock;
-
+ dmm_spinlock_t lock;
/*
* This semaphore is used to ensure that files are not removed
* while epoll is using them. This is read-held during the event
@@ -78,7 +80,7 @@ struct eventpoll
* When we do epoll_ctl, we write lock
* When we collecting data , we read lock
*/
- sys_sem_st sem;
+ dmm_spinlock_t sem;
/*
* This semaphore is used to block epoll_wait function
@@ -102,14 +104,12 @@ struct eventpoll
struct eventpoll_pool
{
- void *ring;
+ struct dmm_ring *ring;
struct eventpoll *pool;
};
typedef struct
{
- int iindex;
- int iNext;
int fd;
i32 epaddflag;
i32 fdtype; /*0: socket fd, 1: epoll fd */
@@ -117,21 +117,18 @@ typedef struct
i32 rmidx; /* copy of fdInf->rmidx */
i32 protoFD[NSEP_SMOD_MAX]; /* copy of fdInf->protoFD */// Here we need to set router infomations dependency
struct eventpoll *ep;
- sys_sem_st epiLock;
- sys_sem_st freeLock;
+ dmm_spinlock_t epiLock;
+ dmm_spinlock_t freeLock;
struct ep_list epiList; /* This restore the epitem of this file descriptor */
u32 sleepTime; //add for NSTACK_SEM_SLEEP
nsep_pidinfo pidinfo;
nsfw_res res_chk;
- void *private_data; /*add for debug, just used to record extern infomation, for example sbr conn */
- i32 reserv[4];
} nsep_epollInfo_t;
typedef struct
{
- void *ring;
+ struct dmm_ring *ring;
nsep_epollInfo_t *pool;
- char last_reserve[8]; //reserve for update
} nsep_infoPool_t;
struct epitem
@@ -149,13 +146,12 @@ struct epitem
unsigned int ovf_revents;
int fd;
u32 pid;
- void *private_data;
nsfw_res res_chk;
};
struct epitem_pool
{
- void *ring;
+ struct dmm_ring *ring;
struct epitem *pool;
};
diff --git a/src/nSocket/include/nstack_types.h b/src/nSocket/include/nstack_types.h
index 90b538e..556dc7e 100644
--- a/src/nSocket/include/nstack_types.h
+++ b/src/nSocket/include/nstack_types.h
@@ -20,7 +20,6 @@
#include <time.h>
#include <stdint.h>
#include <stdlib.h>
-#include <common_pal_bitwide_adjust.h>
#ifdef __cplusplus
/* *INDENT-OFF* */
diff --git a/src/nSocket/include/select_adapt.h b/src/nSocket/include/select_adapt.h
index 2898c76..072f53b 100644
--- a/src/nSocket/include/select_adapt.h
+++ b/src/nSocket/include/select_adapt.h
@@ -35,9 +35,8 @@
#include "types.h"
#include "nstack_module.h"
-#include "common_mem_spinlock.h"
#include "nstack_securec.h"
-#include "common_func.h"
+#include "dmm_spinlock.h"
#define SBR_MAX_FD_NUM MAX_SOCKET_NUM
@@ -54,11 +53,11 @@
}
typedef sem_t select_sem_t;
-typedef common_mem_spinlock_t select_spinlock_t;
+typedef dmm_spinlock_t select_spinlock_t;
-#define select_spin_lock(lock) (common_mem_spinlock_lock((lock)))
-#define select_spin_unlock(lock) (common_mem_spinlock_unlock((lock)))
-#define select_spin_lock_init(lock) (common_mem_spinlock_init((lock)))
+#define select_spin_lock(lock) (dmm_spin_lock((lock)))
+#define select_spin_unlock(lock) (dmm_spin_unlock((lock)))
+#define select_spin_lock_init(lock) (dmm_spin_init((lock)))
#define select_sem_wait(sem) (sem_wait((sem)))
#define select_sem_init(sem, share, val) (sem_init((sem), (share), (val)))