clean up;
This commit is contained in:
		
							parent
							
								
									f12bb01571
								
							
						
					
					
						commit
						c5dbf0b654
					
				
							
								
								
									
										2
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							@ -11,7 +11,7 @@ Homepage: http://askele.com/software
 | 
			
		||||
Package: libsntl-dev
 | 
			
		||||
Section: libdevel
 | 
			
		||||
Architecture: any
 | 
			
		||||
Depends: libsntl (= ${binary:Version}), libsexpr-dev, libssl1.0.0-dev, libtdata-dev, uuid-dev
 | 
			
		||||
Depends: libsntl (= ${binary:Version}), libsexpr-dev, libssl-dev, libtdata-dev, uuid-dev
 | 
			
		||||
Description: Development files for libsntl
 | 
			
		||||
 Development files for sntl library
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,50 +0,0 @@
 | 
			
		||||
#ifndef __MCACHE_H__
 | 
			
		||||
#define	__MCACHE_H__
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
 | 
			
		||||
#include <tdata/usrtc.h>
 | 
			
		||||
#include <tdata/idx_allocator.h>
 | 
			
		||||
 | 
			
		||||
#define _MCACHE_MAGIC  0xabcdbeef
 | 
			
		||||
#define _MPG_SIZE      4096
 | 
			
		||||
 | 
			
		||||
#define _MCACHE_EMINSIZE  sizeof(unsigned long) + 8
 | 
			
		||||
#define _MCACHE_EMAXSIZE  sizeof(unsigned long) + 224
 | 
			
		||||
 | 
			
		||||
#define _MCACHE_PREALLOC    (1 << 1)  /* preallocate elements on initialization */
 | 
			
		||||
#define _MCACHE_ALLOCAHEAD  (1 << 2)  /* allocate more ahead */
 | 
			
		||||
#define _MCACHE_MEMFREE     (1 << 3)  /* free as possible */
 | 
			
		||||
 | 
			
		||||
/* this structure used to store info on page, and located
 | 
			
		||||
 * at the beginning of the allocated page
 | 
			
		||||
 */
 | 
			
		||||
struct _mpg {
 | 
			
		||||
  void *addr;
 | 
			
		||||
  unsigned int use;
 | 
			
		||||
  usrtc_node_t node;
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
 | 
			
		||||
typedef struct __sntl_mcache_ {
 | 
			
		||||
  unsigned int magic; /** < first 32bit to check it */
 | 
			
		||||
  usrtc_t pg_tree;    /** < pages tree */
 | 
			
		||||
  size_t esize;       /** < element size*/
 | 
			
		||||
  pthread_rwlock_t lock;  /** < thread safe cap */
 | 
			
		||||
  usrtc_t allocated;  /** < allocated elements to increase allocation */
 | 
			
		||||
  usrtc_t used;       /** < used ones */
 | 
			
		||||
  unsigned int epc;   /** < elements per cache page */
 | 
			
		||||
  int flags;          /** < flags of the cache */
 | 
			
		||||
} sntl_mcache_t;
 | 
			
		||||
 | 
			
		||||
int sntl_mcache_init(sntl_mcache_t*, size_t, int);
 | 
			
		||||
 | 
			
		||||
void* sntl_mcache_alloc(sntl_mcache_t*);
 | 
			
		||||
 | 
			
		||||
void sntl_mcache_free(void*);
 | 
			
		||||
 | 
			
		||||
void sntl_mcache_destroy(sntl_mcache_t*);
 | 
			
		||||
 | 
			
		||||
#endif /* __MCACHE_H__ */
 | 
			
		||||
							
								
								
									
										96
									
								
								lib/mcache.c
									
									
									
									
									
								
							
							
						
						
									
										96
									
								
								lib/mcache.c
									
									
									
									
									
								
							@ -1,96 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Secure Network Transport Layer Library implementation.
 | 
			
		||||
 * This is a proprietary software. See COPYING for further details.
 | 
			
		||||
 *
 | 
			
		||||
 * (c) 2013-2014 Copyright Askele, inc. <http://askele.com>
 | 
			
		||||
 * (c) 2013-2014 Copyright Askele Ingria, inc. <http://askele-ingria.com>
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <sys/time.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
// #include <sys/mman.h>
 | 
			
		||||
#ifdef WIN32
 | 
			
		||||
#include <Winsock2.h>
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
 | 
			
		||||
#include <tdata/usrtc.h>
 | 
			
		||||
 | 
			
		||||
#include <sntl/mcache.h>
 | 
			
		||||
 | 
			
		||||
static long __cmp_longs(const void *a, const void *b)
 | 
			
		||||
{
 | 
			
		||||
  return (long)(*(unsigned long*)a - *(unsigned long*)b);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sntl_mcache_init(sntl_mcache_t *mc, size_t esize, int flags)
 | 
			
		||||
{
 | 
			
		||||
  int r = 0, i;
 | 
			
		||||
  usrtc_t *tree;
 | 
			
		||||
  void *pt;
 | 
			
		||||
  struct _mpg *pg;
 | 
			
		||||
 | 
			
		||||
  /* check it */
 | 
			
		||||
  if((esize < _MCACHE_EMINSIZE) || (esize > _MCACHE_EMAXSIZE)) return EINVAL;
 | 
			
		||||
 | 
			
		||||
  /* yep, nil it */
 | 
			
		||||
  memset(mc, 0, sizeof(sntl_mcache_t));
 | 
			
		||||
 | 
			
		||||
  mc->magic = _MCACHE_MAGIC; /* let it be */
 | 
			
		||||
 | 
			
		||||
  if((r = pthread_rwlock_init(&(mc->lock), NULL))) return -r;
 | 
			
		||||
 | 
			
		||||
  /* init trees */
 | 
			
		||||
  for(i = 0; i < 3; i ++) {
 | 
			
		||||
    switch(i) {
 | 
			
		||||
    case 0: tree = &(mc->pg_tree); break;
 | 
			
		||||
    case 1: tree = &(mc->allocated); break;
 | 
			
		||||
    case 2: tree = &(mc->used); break;
 | 
			
		||||
    }
 | 
			
		||||
    usrtc_init(tree, USRTC_REDBLACK, 129038, __cmp_longs);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* deal with flags */
 | 
			
		||||
  mc->flags = flags;
 | 
			
		||||
  /* sizes */
 | 
			
		||||
  mc->esize = esize + sizeof(unsigned long);
 | 
			
		||||
  mc->epc = (_MPG_SIZE - sizeof(struct _mpg)) / mc->esize;
 | 
			
		||||
  #if 0
 | 
			
		||||
  if((flags & _MCACHE_PREALLOC)) {
 | 
			
		||||
    pt = mmap(NULL, _MPG_SIZE, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, -1, 0);
 | 
			
		||||
    if(pt == MAP_FAILED) {
 | 
			
		||||
      pthread_rwlock_destroy(&(mc->lock));
 | 
			
		||||
      return ENOMEM;
 | 
			
		||||
    } else pg = (struct _mpg *)pt;
 | 
			
		||||
  }
 | 
			
		||||
  #endif
 | 
			
		||||
  return r;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void* sntl_mcache_alloc(sntl_mcache_t *mc)
 | 
			
		||||
{
 | 
			
		||||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sntl_mcache_free(void *p)
 | 
			
		||||
{
 | 
			
		||||
  return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sntl_mcache_destroy(sntl_mcache_t *mc)
 | 
			
		||||
{
 | 
			
		||||
  return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user