]> git.sur5r.net Git - openldap/blob - servers/slurpd/replica.c
Merge from LAMBERT branch
[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
19 #include <stdio.h>
20
21 #include "slurp.h"
22 #include "globals.h"
23
24
25 /*
26  * Just invoke the Ri's process() member function, and log the start and
27  * finish.
28  */
29 void
30 replicate(
31     Ri  *ri
32 )
33 {
34     int i;
35     unsigned long seq;
36
37     Debug( LDAP_DEBUG_ARGS, "begin replication thread for %s:%d\n",
38             ri->ri_hostname, ri->ri_port, 0 );
39
40     ri->ri_process( ri );
41
42     Debug( LDAP_DEBUG_ARGS, "end replication thread for %s:%d\n",
43             ri->ri_hostname, ri->ri_port, 0 );
44     return;
45 }
46
47
48
49 /*
50  * Start a detached thread for the given replica.
51  */
52 int
53 start_replica_thread(
54     Ri  *ri
55 )
56 {
57     pthread_attr_t      attr;
58
59     pthread_attr_init( &attr );
60     pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
61
62 #ifdef PTHREAD_MUTEX_INITIALIZER
63     /*
64      * This is a draft 10 or standard pthreads implementation
65      */
66     if ( pthread_create( &(ri->ri_tid), attr, (void *) replicate,
67             (void *) ri ) != 0 ) {
68         Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" pthread_create failed\n",
69                 ri->ri_hostname, ri->ri_port, 0 );
70         pthread_attr_destroy( &attr );
71         return -1;
72     }
73 #else   /* !PTHREAD_MUTEX_INITIALIZER */
74     /*
75      * This is a draft 4 or earlier pthreads implementation
76      */
77     if ( pthread_create( &(ri->ri_tid), &attr, (void *) replicate,
78             (void *) ri ) != 0 ) {
79         Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" pthread_create failed\n",
80                 ri->ri_hostname, ri->ri_port, 0 );
81         pthread_attr_destroy( &attr );
82         return -1;
83     }
84 #endif  /* !PTHREAD_MUTEX_INITIALIZER */
85     pthread_attr_destroy( &attr );
86     return 0;
87 }