]> git.sur5r.net Git - openldap/blob - servers/slurpd/replica.c
7ed7b20d5eaea5c5405d10da07a1433d810ef4b1
[openldap] / servers / slurpd / replica.c
1 /*
2  * Copyright (c) 1996 Regents of the University of Michigan.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of Michigan at Ann Arbor. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12
13
14 /*
15  * replica.c - code to start up replica threads.
16  */
17
18 #include "portable.h"
19
20 #include <stdio.h>
21
22 #include "slurp.h"
23 #include "globals.h"
24
25
26 /*
27  * Just invoke the Ri's process() member function, and log the start and
28  * finish.
29  */
30 void
31 replicate(
32     Ri  *ri
33 )
34 {
35     Debug( LDAP_DEBUG_ARGS, "begin replication thread for %s:%d\n",
36             ri->ri_hostname, ri->ri_port, 0 );
37
38     ri->ri_process( ri );
39
40     Debug( LDAP_DEBUG_ARGS, "end replication thread for %s:%d\n",
41             ri->ri_hostname, ri->ri_port, 0 );
42     return;
43 }
44
45
46
47 /*
48  * Start a detached thread for the given replica.
49  */
50 int
51 start_replica_thread(
52     Ri  *ri
53 )
54 {
55     pthread_attr_t      attr;
56
57     pthread_attr_init( &attr );
58 #ifdef NOTDEF
59         /* if main wants to join with us, we shouldn't detach */
60     pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
61 #endif
62
63 #if !defined(HAVE_PTHREAD_D4) && !defined(HAVE_DCE)
64     /* POSIX_THREADS or compatible
65      * This is a draft 10 or standard pthreads implementation
66      */
67     if ( pthread_create( &(ri->ri_tid), &attr, replicate,
68             (void *) ri ) != 0 ) {
69         Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" pthread_create failed\n",
70                 ri->ri_hostname, ri->ri_port, 0 );
71         pthread_attr_destroy( &attr );
72         return -1;
73     }
74 #else   /* !final */
75     /*
76      * This is a draft 4 or earlier pthreads implementation
77      */
78     if ( pthread_create( &(ri->ri_tid), attr, replicate,
79             (void *) ri ) != 0 ) {
80         Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" pthread_create failed\n",
81                 ri->ri_hostname, ri->ri_port, 0 );
82         pthread_attr_destroy( &attr );
83         return -1;
84     }
85 #endif  /* !final */
86
87     pthread_attr_destroy( &attr );
88     return 0;
89 }