Commit 6db7e605 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Align Operation buffers using LBER_ALIGNED_BUFFER

parent 0ea43c9d
......@@ -29,6 +29,10 @@
#define LDAP_THREAD_POOL_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename symbols defined below */
#ifdef LDAP_DEVEL
#define SLAP_SEM_LOAD_CONTROL
#endif
#ifndef LDAP_THREAD_HAVE_TPOOL
typedef enum ldap_int_thread_pool_state_e {
......@@ -118,6 +122,123 @@ ldap_int_thread_pool_shutdown ( void )
return(0);
}
typedef struct ldap_lazy_sem_t {
ldap_pvt_thread_mutex_t ls_mutex;
ldap_pvt_thread_cond_t ls_cond;
int ls_sem_value;
/*
* when more than ls_lazy_count number of resources
* becmoes available, the thread wating for the resources will
* be waken up in order to prevent frequent blocking/waking-up
*/
unsigned int ls_lazy_count;
/*
* only one thread(listener) will wait on this semaphore
* using a flag instead of a list
*/
int ls_wait;
} ldap_lazy_sem_t;
ldap_lazy_sem_t* thread_pool_sem = NULL;
int
ldap_lazy_sem_init( unsigned int value, unsigned int lazyness ) {
thread_pool_sem = (ldap_lazy_sem_t*) LDAP_CALLOC(1,
sizeof( ldap_lazy_sem_t ));
if( thread_pool_sem == NULL ) return -1;
ldap_pvt_thread_mutex_init( &thread_pool_sem->ls_mutex );
ldap_pvt_thread_cond_init( &thread_pool_sem->ls_cond );
thread_pool_sem->ls_sem_value = value;
thread_pool_sem->ls_lazy_count = lazyness;
thread_pool_sem->ls_wait = 0;
return 0;
}
/*
* ldap_lazy_sem_wait is used if a caller is blockable(listener).
* Otherwise use ldap_lazy_sem_dec (worker)
*/
int
ldap_lazy_sem_op_submit( ldap_lazy_sem_t* ls ) {
if ( ls == NULL ) return -1;
/* only worker thread has its thread ctx */
if ( ldap_pvt_thread_pool_context() ) {
/* worker thread */
return ldap_lazy_sem_dec( ls );
} else {
/* listener */
return ldap_lazy_sem_wait( ls );
}
}
/*
* test if given semaphore's count is zero.
* If 0, the caller is blocked
* If not, the count is decremented.
*/
int
ldap_lazy_sem_wait ( ldap_lazy_sem_t* ls ) {
ldap_pvt_thread_mutex_lock( &ls->ls_mutex );
lazy_sem_retry:
if ( ls->ls_sem_value <= 0 ) {
/* no more avaliable resources */
ls->ls_wait = 1;
ldap_pvt_thread_cond_wait( &ls->ls_cond, &ls->ls_mutex );
goto lazy_sem_retry;
} else {
/* avaliable resources */
ls->ls_sem_value--;
}
ldap_pvt_thread_mutex_unlock( &ls->ls_mutex );
return 0;
}
/*
* decrement the count without blocking
* even when the count becomes less than or equal to 0
*/
int
ldap_lazy_sem_dec ( ldap_lazy_sem_t* ls ) {
ldap_pvt_thread_mutex_lock( &ls->ls_mutex );
ls->ls_sem_value--;
ldap_pvt_thread_mutex_unlock( &ls->ls_mutex );
return 0;
}
/*
* Increment the count by one and test if it is greater or
* equal to lazyness. If it is, wake up a blocked thread.
*/
int
ldap_lazy_sem_post( ldap_lazy_sem_t* ls ) {
if( ls == NULL ) return (-1);
ldap_pvt_thread_mutex_lock( &ls->ls_mutex );
ls->ls_sem_value++;
if ( ls->ls_wait ) {
if ( ls->ls_sem_value >= ls->ls_lazy_count ) {
ls->ls_wait = 0;
ldap_pvt_thread_cond_signal( &ls->ls_cond );
}
}
ldap_pvt_thread_mutex_unlock( &ls->ls_mutex );
return 0;
}
int
ldap_pvt_thread_pool_init (
ldap_pvt_thread_pool_t *tpool,
......@@ -257,6 +378,10 @@ ldap_pvt_thread_pool_submit (
}
ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex);
#ifdef SLAP_SEM_LOAD_CONTROL
ldap_lazy_sem_op_submit( thread_pool_sem );
#endif
if (need_thread) {
int rc;
......@@ -408,6 +533,11 @@ ldap_pvt_thread_pool_destroy ( ldap_pvt_thread_pool_t *tpool, int run_pending )
ldap_pvt_thread_cond_destroy(&pool->ltp_cond);
ldap_pvt_thread_mutex_destroy(&pool->ltp_mutex);
LDAP_FREE(pool);
#ifdef SLAP_SEM_LOAD_CONTROL
if ( thread_pool_sem ) {
LDAP_FREE( thread_pool_sem );
}
#endif
return(0);
}
......@@ -484,6 +614,9 @@ ldap_int_thread_pool_wrapper (
ctx->ltc_start_routine(ltc_key, ctx->ltc_arg);
#ifdef SLAP_SEM_LOAD_CONTROL
ldap_lazy_sem_post( thread_pool_sem );
#endif
ldap_pvt_thread_mutex_lock(&pool->ltp_mutex);
LDAP_SLIST_REMOVE(&pool->ltp_active_list, ctx,
ldap_int_thread_ctx_s, ltc_next.al);
......
......@@ -172,8 +172,8 @@ bdb_online_index( void *ctx, void *arg )
struct bdb_info *bdb = be->be_private;
Connection conn = {0};
char opbuf[OPERATION_BUFFER_SIZE];
Operation *op = (Operation *)opbuf;
OperationBuffer opbuf;
Operation *op = (Operation *) &opbuf;
DBC *curs;
DBT key, data;
......
......@@ -642,7 +642,7 @@ monitor_filter2ndn(
struct berval *ndn )
{
Connection conn = { 0 };
char opbuf[OPERATION_BUFFER_SIZE];
OperationBuffer opbuf;
Operation *op;
SlapReply rs = { 0 };
slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
......@@ -654,7 +654,7 @@ monitor_filter2ndn(
return -1;
}
op = (Operation *)opbuf;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, &conn );
op->o_tag = LDAP_REQ_SEARCH;
......
......@@ -224,8 +224,8 @@ backsql_db_open(
SQLHDBC dbh = SQL_NULL_HDBC;
struct berbuf bb = BB_NULL;
char opbuf[ OPERATION_BUFFER_SIZE ];
Operation* op = (Operation *)opbuf;
OperationBuffer opbuf;
Operation* op = (Operation *) &opbuf;
Debug( LDAP_DEBUG_TRACE, "==>backsql_db_open(): "
"testing RDBMS connection\n", 0, 0, 0 );
......@@ -581,8 +581,8 @@ backsql_db_close(
int
backsql_connection_destroy( Backend *bd, Connection *c )
{
char opbuf[ OPERATION_BUFFER_SIZE ];
Operation* op = (Operation *)opbuf;
OperationBuffer opbuf;
Operation* op = (Operation *) &opbuf;
op->o_hdr = (Opheader *)&op[ 1 ];
op->o_connid = c->c_connid;
......
......@@ -2623,7 +2623,7 @@ config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
setup_cookie sc;
slap_callback cb = { NULL, config_ldif_resp, NULL, NULL };
Connection conn = {0};
char opbuf[OPERATION_BUFFER_SIZE];
OperationBuffer opbuf;
Operation *op;
SlapReply rs = {REP_RESULT};
Filter filter = { LDAP_FILTER_PRESENT };
......@@ -2675,7 +2675,7 @@ config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
if ( readit ) {
void *thrctx = ldap_pvt_thread_pool_context();
op = (Operation *)opbuf;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, thrctx );
filter.f_desc = slap_schema.si_ad_objectClass;
......@@ -4063,7 +4063,7 @@ config_back_db_open( BackendDB *be )
BackendInfo *bi;
ConfigArgs c;
Connection conn = {0};
char opbuf[OPERATION_BUFFER_SIZE];
OperationBuffer opbuf;
Operation *op;
slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
SlapReply rs = {REP_RESULT};
......@@ -4075,7 +4075,7 @@ config_back_db_open( BackendDB *be )
if ( cfb->cb_use_ldif ) {
thrctx = ldap_pvt_thread_pool_context();
op = (Operation *)opbuf;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, thrctx );
op->o_dn = be->be_rootdn;
......
This diff is collapsed.
This diff is collapsed.
......@@ -464,8 +464,8 @@ accesslog_purge( void *ctx, void *arg )
struct log_info *li = rtask->arg;
Connection conn = {0};
char opbuf[OPERATION_BUFFER_SIZE];
Operation *op = (Operation *)opbuf;
OperationBuffer opbuf;
Operation *op = (Operation *) &opbuf;
SlapReply rs = {REP_RESULT};
slap_callback cb = { NULL, log_old_lookup, NULL, NULL };
Filter f;
......
......@@ -1462,7 +1462,7 @@ consistency_check(
cache_manager *cm = on->on_bi.bi_private;
query_manager *qm = cm->qm;
Connection conn = {0};
char opbuf[OPERATION_BUFFER_SIZE];
OperationBuffer opbuf;
Operation *op;
SlapReply rs = {REP_RESULT};
......@@ -1470,7 +1470,7 @@ consistency_check(
int i, return_val, pause = 1;
QueryTemplate* templ;
op = (Operation *)opbuf;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, ctx );
op->o_bd = &cm->db;
......
......@@ -861,11 +861,11 @@ syncprov_qtask( void *ctx, void *arg )
struct re_s *rtask = arg;
syncops *so = rtask->arg;
slap_overinst *on = so->s_op->o_private;
char opbuf[OPERATION_BUFFER_SIZE];
OperationBuffer opbuf;
Operation *op;
BackendDB be;
op = (Operation *)opbuf;
op = (Operation *) &opbuf;
*op = *so->s_op;
op->o_hdr = (Opheader *)(op+1);
op->o_controls = (void **)(op->o_hdr+1);
......@@ -2217,9 +2217,9 @@ syncprov_db_open(
syncprov_info_t *si = (syncprov_info_t *)on->on_bi.bi_private;
Connection conn;
char opbuf[OPERATION_BUFFER_SIZE];
OperationBuffer opbuf;
char ctxcsnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
Operation *op = (Operation *)opbuf;
Operation *op = (Operation *) &opbuf;
Entry *e;
Attribute *a;
int rc;
......@@ -2307,8 +2307,8 @@ syncprov_db_close(
}
if ( si->si_numops ) {
Connection conn;
char opbuf[OPERATION_BUFFER_SIZE];
Operation *op = (Operation *)opbuf;
OperationBuffer opbuf;
Operation *op = (Operation *) &opbuf;
SlapReply rs = {REP_RESULT};
void *thrctx;
......
......@@ -646,7 +646,11 @@ LDAP_SLAPD_F (const char *) connection_state2str LDAP_P(( int state ))
LDAP_GCCATTR((const));
LDAP_SLAPD_F (int) connection_write LDAP_P((ber_socket_t s));
#ifdef SLAP_LIGHTWEIGHT_LISTENER
LDAP_SLAPD_F (int) connection_read LDAP_P((ber_socket_t, Operation **));
#else
LDAP_SLAPD_F (int) connection_read LDAP_P((ber_socket_t s));
#endif
LDAP_SLAPD_F (unsigned long) connections_nextid(void);
......
......@@ -60,6 +60,10 @@ LDAP_BEGIN_DECL
#ifdef LDAP_DEVEL
#define SLAP_LIGHTWEIGHT_LISTENER /* experimental slapd architecture */
#define SLAP_SEM_LOAD_CONTROL /* must also be defined in libldap_r/tpool.c */
#define SLAP_MULTI_CONN_ARRAY
#define SLAP_ACL_HONOR_DISCLOSE /* partially implemented */
#define SLAP_ACL_HONOR_MANAGE /* not yet implemented */
#define SLAP_DYNACL
......@@ -2555,7 +2559,11 @@ typedef struct slap_op {
LDAP_STAILQ_ENTRY(slap_op) o_next; /* next operation in list */
} Operation;
#define OPERATION_BUFFER_SIZE (sizeof(Operation)+sizeof(Opheader)+SLAP_MAX_CIDS*sizeof(void *))
#define OPERATION_BUFFER_SIZE ( sizeof(Operation) + sizeof(Opheader) + \
SLAP_MAX_CIDS*sizeof(void *) )
typedef LBER_ALIGNED_BUFFER(operation_buffer_u,OPERATION_BUFFER_SIZE)
OperationBuffer;
#define send_ldap_error( op, rs, err, text ) do { \
(rs)->sr_err = err; (rs)->sr_text = text; \
......
......@@ -65,7 +65,7 @@ slapacl( int argc, char **argv )
const char *progname = "slapacl";
Connection conn = { 0 };
Listener listener;
char opbuf[OPERATION_BUFFER_SIZE];
OperationBuffer opbuf;
Operation *op = NULL;
Entry e = { 0 }, *ep = &e;
char *attr = NULL;
......@@ -94,7 +94,7 @@ slapacl( int argc, char **argv )
argv = &argv[ optind ];
argc -= optind;
op = (Operation *)opbuf;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, &conn );
conn.c_listener = &listener;
......
......@@ -56,8 +56,8 @@ slapadd( int argc, char **argv )
Attribute *attr;
Entry *ctxcsn_e;
ID ctxcsn_id, id;
OperationBuffer opbuf;
Operation *op;
char opbuf[OPERATION_BUFFER_SIZE];
int match;
int ret;
......@@ -69,8 +69,8 @@ slapadd( int argc, char **argv )
slap_tool_init( progname, SLAPADD, argc, argv );
memset( opbuf, 0, sizeof(opbuf) );
op = (Operation *)opbuf;
memset( &opbuf, 0, sizeof(opbuf) );
op = (Operation *) &opbuf;
if( !be->be_entry_open ||
!be->be_entry_close ||
......
......@@ -80,7 +80,7 @@ slapauth( int argc, char **argv )
int rc = EXIT_SUCCESS;
const char *progname = "slapauth";
Connection conn = {0};
char opbuf[OPERATION_BUFFER_SIZE];
OperationBuffer opbuf;
Operation *op;
slap_tool_init( progname, SLAPAUTH, argc, argv );
......@@ -88,7 +88,7 @@ slapauth( int argc, char **argv )
argv = &argv[ optind ];
argc -= optind;
op = (Operation *)opbuf;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, &conn );
conn.c_sasl_bind_mech = mech;
......
......@@ -902,7 +902,7 @@ do_syncrepl(
struct re_s* rtask = arg;
syncinfo_t *si = ( syncinfo_t * ) rtask->arg;
Connection conn = {0};
char opbuf[OPERATION_BUFFER_SIZE];
OperationBuffer opbuf;
Operation *op;
int rc = LDAP_SUCCESS;
int first = 0;
......@@ -938,7 +938,7 @@ do_syncrepl(
return NULL;
}
op = (Operation *)opbuf;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, ctx );
/* use global malloc for now */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment