]> git.sur5r.net Git - openldap/commitdiff
Add ldap_pvt_thread_destory() to un-ldap_pvt_thread_initialize().
authorKurt Zeilenga <kurt@openldap.org>
Tue, 6 Apr 1999 21:57:16 +0000 (21:57 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 6 Apr 1999 21:57:16 +0000 (21:57 +0000)
Move all SunOS routines (ie: _sleep() and its helpers) to thr_lwp.c
so that it's internals can be 'static'.  Add 'static' to thr_lwp.c.
Add comment to LWP:  NEEDS WORK, may not compile!  Need some
SunOS user to sort out the details.  Volunteers?

include/ldap_pvt_thread.h
libraries/libldap_r/thr_cthreads.c
libraries/libldap_r/thr_lwp.c
libraries/libldap_r/thr_nt.c
libraries/libldap_r/thr_posix.c
libraries/libldap_r/thr_sleep.c
libraries/libldap_r/thr_stub.c
libraries/libldap_r/thr_thr.c
servers/slapd/init.c
servers/slurpd/main.c

index 6024713bbc70e377f12be3e42f30ab2bc4440d16..d0d0b597fbc5c53dad53d8876e36408ba660a7d5 100644 (file)
@@ -163,6 +163,8 @@ LDAP_BEGIN_DECL
 
 LDAP_F int
 ldap_pvt_thread_initialize LDAP_P(( void ));
+LDAP_F int
+ldap_pvt_thread_destory LDAP_P(( void ));
 
 LDAP_F unsigned int
 ldap_pvt_thread_sleep LDAP_P(( unsigned int s ));
index 6eddb69317b61ca08c931c4c2ada18f1712d9a4b..a52c406a9cb5ef2f2e5addfd1ff7d591384947cc 100644 (file)
@@ -28,6 +28,12 @@ ldap_pvt_thread_initialize( void )
        return 0;
 }
 
+int
+ldap_pvt_thread_destroy( void )
+{
+       return 0;
+}
+
 int 
 ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
        int detach,
index 27be3a8d19250fbbe26dec02c32d5718996bc002..f9bc0b415f7dab16df43d3d9afdbeb0d9206ffd3 100644 (file)
@@ -25,6 +25,9 @@
  * SunOS LWP *
  *           *
  *************/
+
+/* This implementation NEEDS WORK.   It currently does not compile */
+
 #include <stdio.h>
 
 #include <ac/time.h>
@@ -58,6 +61,14 @@ ldap_pvt_thread_initialize( void )
        return 0;
 }
 
+int
+ldap_pvt_thread_destroy( void )
+{
+       /* need to destory lwp_scheduler thread and clean up private
+               variables */
+       return 0;
+}
+
 struct stackinfo {
        int             stk_inuse;
        stkalign_t      *stk_stack;
@@ -65,7 +76,7 @@ struct stackinfo {
 
 static struct stackinfo        *stacks;
 
-stkalign_t * ldap_pvt_thread_get_stack( int *stacknop )
+static stkalign_t * ldap_pvt_thread_get_stack( int *stacknop )
 {
        int     i;
 
@@ -98,7 +109,7 @@ stkalign_t * ldap_pvt_thread_get_stack( int *stacknop )
        return( stacks[i].stk_stack + MAX_STACK / sizeof(stkalign_t) );
 }
 
-void
+static void
 ldap_pvt_thread_free_stack( int        stackno )
 {
        if ( stackno < 0 || stackno > MAX_THREADS ) {
@@ -109,7 +120,7 @@ ldap_pvt_thread_free_stack( int     stackno )
        stacks[stackno].stk_inuse = 0;
 }
 
-static void
+static static void
 lwp_create_stack( void *(*func)(), void *arg, int stackno )
 {
        (*func)( arg );
@@ -139,6 +150,106 @@ ldap_pvt_thread_exit( void *retval )
        lwp_destroy( SELF );
 }
 
+unsigned int
+ldap_pvt_thread_sleep(
+       unsigned int interval
+)
+{
+       thread_t                mylwp;
+       tl_t            *t, *nt;
+       time_t          now;
+
+
+       if ( lwp_self( &mylwp ) < 0 ) {
+               return -1;
+       }
+
+       time( &now );
+
+       mon_enter( &sglob->tsl_mon );
+
+       if ( sglob->tsl_list != NULL ) {
+               for ( t = sglob->tsl_list; t != NULL; t = t->tl_next ) {
+                       if ( SAMETHREAD( t->tl_tid, mylwp )) {
+                               /* We're already sleeping? */
+                               t->tl_wake = now + interval;
+                               mon_exit( &sglob->tsl_mon );
+                               lwp_suspend( mylwp );
+                               return 0;
+                       }
+               }
+       }
+
+       nt = (tl_t *) malloc( sizeof( tl_t ));
+
+       nt->tl_next = sglob->tsl_list;
+       nt->tl_wake = now + interval;
+       nt->tl_tid = mylwp;
+       sglob->tsl_list = nt;
+
+       mon_exit( &sglob->tsl_mon );
+
+       lwp_suspend( mylwp );
+       return 0;
+}
+
+/*
+ * The lwp_scheduler thread periodically checks to see if any threads
+ * are due to be resumed.  If there are, it resumes them.  Otherwise,
+ * it computes the lesser of ( 1 second ) or ( the minimum time until
+ * a thread need to be resumed ) and puts itself to sleep for that amount
+ * of time.
+ */
+static void
+lwp_scheduler(
+       int             stackno
+)
+{
+       time_t                  now, min;
+       struct timeval          interval;
+       tl_t                    *t;
+
+       while ( !sglob->slurpd_shutdown ) {
+               mon_enter( &sglob->tsl_mon );
+
+               time( &now );
+               min = 0L;
+               if ( sglob->tsl_list != NULL ) {
+                       for ( t = sglob->tsl_list; t != NULL; t = t->tl_next ) {
+                               if (( t->tl_wake  > 0L ) && ( t->tl_wake < now )) {
+                                       lwp_resume( t->tl_tid );
+                                       t->tl_wake = 0L;
+                               }
+
+                               if (( t->tl_wake > now ) && ( t->tl_wake < min )) {
+                                       min =  t->tl_wake;
+                               }
+                       }
+               }
+
+               mon_exit( &sglob->tsl_mon );
+
+               interval.tv_usec = 0L;
+               if ( min == 0L ) {
+                       interval.tv_sec = 1L;
+               } else {
+                       interval.tv_sec = min;
+               }
+
+               lwp_sleep( &interval );
+       }
+
+       mon_enter( &sglob->tsl_mon );
+
+       for ( t = sglob->tsl_list; t != NULL; t = t->tl_next ) {
+               lwp_resume( t->tl_tid );
+       }
+
+       mon_exit( &sglob->tsl_mon );
+
+       free_stack( stackno );
+}
+
 int 
 ldap_pvt_thread_join( ldap_pvt_thread_t thread, void **thread_return )
 {
index f6be8e6ad051ea9f966ab71fc81fd00f1e29fab9..1a884eba07d03a0d7bd43993b7520b38ab3f9087 100644 (file)
@@ -22,6 +22,12 @@ ldap_pvt_thread_initialize( void )
        return 0;
 }
 
+int
+ldap_pvt_thread_destroy( void )
+{
+       return 0;
+}
+
 int 
 ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
        int detach,
index 96c5e8be99874b747d68902249d1cccf0aa710ae..da8ef99c433ac8a97eb4b0411f65c9b3143c7c58 100644 (file)
@@ -39,6 +39,12 @@ ldap_pvt_thread_initialize( void )
        return 0;
 }
 
+int
+ldap_pvt_thread_destroy( void )
+{
+       return 0;
+}
+
 #ifdef HAVE_PTHREAD_SETCONCURRENCY
 int
 ldap_pvt_thread_set_concurrency(int n)
index 97ad586424a8d265665491acd5b64121a7de4472..b6328fcd702af6fa1fa5aa06b2d6ae432d6e4393 100644 (file)
@@ -50,104 +50,6 @@ ldap_pvt_thread_sleep(
 
 #else
 
-unsigned int
-ldap_pvt_thread_sleep(
-       unsigned int interval
-)
-{
-       thread_t                mylwp;
-       tl_t            *t, *nt;
-       time_t          now;
-
-
-       if ( lwp_self( &mylwp ) < 0 ) {
-               return -1;
-       }
-
-       time( &now );
-
-       mon_enter( &sglob->tsl_mon );
-
-       if ( sglob->tsl_list != NULL ) {
-               for ( t = sglob->tsl_list; t != NULL; t = t->tl_next ) {
-                       if ( SAMETHREAD( t->tl_tid, mylwp )) {
-                               /* We're already sleeping? */
-                               t->tl_wake = now + interval;
-                               mon_exit( &sglob->tsl_mon );
-                               lwp_suspend( mylwp );
-                               return 0;
-                       }
-               }
-       }
-
-       nt = (tl_t *) malloc( sizeof( tl_t ));
-
-       nt->tl_next = sglob->tsl_list;
-       nt->tl_wake = now + interval;
-       nt->tl_tid = mylwp;
-       sglob->tsl_list = nt;
-
-       mon_exit( &sglob->tsl_mon );
-
-       lwp_suspend( mylwp );
-       return 0;
-}
-
-/*
- * The lwp_scheduler thread periodically checks to see if any threads
- * are due to be resumed.  If there are, it resumes them.  Otherwise,
- * it computes the lesser of ( 1 second ) or ( the minimum time until
- * a thread need to be resumed ) and puts itself to sleep for that amount
- * of time.
- */
-void
-lwp_scheduler(
-       int             stackno
-)
-{
-       time_t                  now, min;
-       struct timeval          interval;
-       tl_t                    *t;
-
-       while ( !sglob->slurpd_shutdown ) {
-               mon_enter( &sglob->tsl_mon );
-
-               time( &now );
-               min = 0L;
-               if ( sglob->tsl_list != NULL ) {
-                       for ( t = sglob->tsl_list; t != NULL; t = t->tl_next ) {
-                               if (( t->tl_wake  > 0L ) && ( t->tl_wake < now )) {
-                                       lwp_resume( t->tl_tid );
-                                       t->tl_wake = 0L;
-                               }
-
-                               if (( t->tl_wake > now ) && ( t->tl_wake < min )) {
-                                       min =  t->tl_wake;
-                               }
-                       }
-               }
-
-               mon_exit( &sglob->tsl_mon );
-
-               interval.tv_usec = 0L;
-               if ( min == 0L ) {
-                       interval.tv_sec = 1L;
-               } else {
-                       interval.tv_sec = min;
-               }
-
-               lwp_sleep( &interval );
-       }
-
-       mon_enter( &sglob->tsl_mon );
-
-       for ( t = sglob->tsl_list; t != NULL; t = t->tl_next ) {
-               lwp_resume( t->tl_tid );
-       }
-
-       mon_exit( &sglob->tsl_mon );
-
-       free_stack( stackno );
-}
+/* LWP implementation of sleep can be found in thr_lwp.c */
 
 #endif /* HAVE_LWP */
index 0b8f661d5b1defe896f86742cbca2ee8d13c6f71..7cd8e5f6be430721bed54e5dd909dd9156b79c19 100644 (file)
@@ -28,6 +28,12 @@ ldap_pvt_thread_initialize( void )
        return 0;
 }
 
+int
+ldap_pvt_thread_destroy( void )
+{
+       return 0;
+}
+
 static void* ldap_int_status = NULL;
 
 int 
index 54f2b6ba94d89b2f34ca981bc4ec76ca853a2067..29a6c390a2a72977bf98894ab0ca27626581880d 100644 (file)
@@ -30,6 +30,12 @@ ldap_pvt_thread_initialize( void )
        return 0;
 }
 
+int
+ldap_pvt_thread_destroy( void )
+{
+       return 0;
+}
+
 int
 ldap_pvt_thread_set_concurrency(int n)
 {
index c807014185bd5547b4330c5395e7ebc3958471c0..0990d4b533bfa5f201ece1ffef1612042e9dd8c1 100644 (file)
@@ -154,6 +154,8 @@ int slap_destroy(void)
 
        rc = backend_destroy();
 
+       ldap_pvt_thread_destroy();
+
        /* should destory the above mutex */
        return rc;
 }
index 3e3c81175680fad3f9b488df63238d9ba73a1147..719633954ab3b0e1d8dbf90ed15b32119c5dfd22 100644 (file)
@@ -125,6 +125,10 @@ main(
     for ( i = 0; sglob->replicas[ i ] != NULL; i++ ) {
        ldap_pvt_thread_join( sglob->replicas[ i ]->ri_tid, (void *) NULL );
     }
+
+       /* destroy the thread package */
+       ldap_pvt_thread_destroy();
+
     Debug( LDAP_DEBUG_ANY, "slurpd: terminating normally\n", 0, 0, 0 );
     sglob->slurpd_shutdown = 1;