summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2017-07-13 01:25:19 +0200
committerAndreas Schneider <asn@samba.org>2018-05-02 16:31:42 +0200
commit7299ab3541c94f38ee62a9d39348bbeb438bfc1a (patch)
treeaf0d424428f70919611a6f5c0878a5a006b7aeee
parent01ceb512ccfb60431754fb40704c9fcfb46fc4ac (diff)
downloadsocket_wrapper-7299ab3541c94f38ee62a9d39348bbeb438bfc1a.tar.gz
socket_wrapper-7299ab3541c94f38ee62a9d39348bbeb438bfc1a.tar.xz
socket_wrapper-7299ab3541c94f38ee62a9d39348bbeb438bfc1a.zip
swrap: Move metadata into socket_info_meta structure
Separating out the metadata related information to another sub-structure to make it more clean and structured. Pair-Programmed-With: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org>
-rw-r--r--src/socket_wrapper.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 6b67224..ed42b2d 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -190,12 +190,12 @@ enum swrap_dbglvl_e {
#define SWRAP_LOCK_SI(si) do { \
struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si); \
- pthread_mutex_lock(&sic->mutex); \
+ pthread_mutex_lock(&sic->meta.mutex); \
} while(0)
#define SWRAP_UNLOCK_SI(si) do { \
struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si); \
- pthread_mutex_unlock(&sic->mutex); \
+ pthread_mutex_unlock(&sic->meta.mutex); \
} while(0)
#define DLIST_ADD(list, item) do { \
@@ -355,14 +355,19 @@ struct socket_info
} io;
};
-struct socket_info_container
+struct socket_info_meta
{
- struct socket_info info;
unsigned int refcount;
int next_free;
pthread_mutex_t mutex;
};
+struct socket_info_container
+{
+ struct socket_info info;
+ struct socket_info_meta meta;
+};
+
static struct socket_info_container *sockets;
static size_t max_sockets = 0;
@@ -1255,34 +1260,35 @@ static struct socket_info *swrap_get_socket_info(int si_index)
static int swrap_get_refcount(struct socket_info *si)
{
struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
- return sic->refcount;
+ return sic->meta.refcount;
}
static void swrap_inc_refcount(struct socket_info *si)
{
struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
- sic->refcount += 1;
+ sic->meta.refcount += 1;
}
static void swrap_dec_refcount(struct socket_info *si)
{
struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
- sic->refcount -= 1;
+ sic->meta.refcount -= 1;
}
static int swrap_get_next_free(struct socket_info *si)
{
struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
- return sic->next_free;
+ return sic->meta.next_free;
}
static void swrap_set_next_free(struct socket_info *si, int next_free)
{
struct socket_info_container *sic = SOCKET_INFO_CONTAINER(si);
- sic->next_free = next_free;
+
+ sic->meta.next_free = next_free;
}
static const char *socket_wrapper_dir(void)
@@ -1394,7 +1400,7 @@ static void socket_wrapper_init_sockets(void)
for (i = 0; i < max_sockets; i++) {
swrap_set_next_free(&sockets[i].info, i+1);
- sockets[i].mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
+ sockets[i].meta.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
}
/* mark the end of the free list */