]> git.sur5r.net Git - openldap/blob - libraries/libldap_r/threads.c
ITS#5490
[openldap] / libraries / libldap_r / threads.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2008 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15
16 #include "portable.h"
17
18 #include <stdio.h>
19
20 #include <ac/stdarg.h>
21 #include <ac/stdlib.h>
22 #include <ac/string.h>
23 #include <ac/unistd.h>
24
25 #include "ldap_pvt_thread.h" /* Get the thread interface */
26 #include "ldap_thr_debug.h"  /* May redirect thread initialize/destroy calls */
27
28
29 /*
30  * Common LDAP thread routines
31  *      see thr_*.c for implementation specific routines
32  *      see rdwr.c for generic reader/writer lock implementation
33  *      see tpool.c for generic thread pool implementation
34  */
35
36
37 int ldap_pvt_thread_initialize( void )
38 {
39         int rc;
40         static int init = 0;
41
42         /* we only get one shot at this */
43         if( init++ ) return -1;
44
45         rc = ldap_int_thread_initialize();
46         if( rc ) return rc;
47
48 #ifndef LDAP_THREAD_HAVE_TPOOL
49         rc = ldap_int_thread_pool_startup();
50         if( rc ) return rc;
51 #endif
52
53         return 0;
54 }
55
56 int ldap_pvt_thread_destroy( void )
57 {
58 #ifndef LDAP_THREAD_HAVE_TPOOL
59         (void) ldap_int_thread_pool_shutdown();
60 #endif
61         return ldap_int_thread_destroy();
62 }
63
64
65 /*
66  * Default implementations of some LDAP thread routines
67  */
68
69 #define LDAP_THREAD_IMPLEMENTATION
70 #include "ldap_thr_debug.h"     /* May rename the symbols defined below */
71
72
73 #ifndef LDAP_THREAD_HAVE_GETCONCURRENCY
74 int
75 ldap_pvt_thread_get_concurrency ( void )
76 {
77         return 1;
78 }
79 #endif
80
81 #ifndef LDAP_THREAD_HAVE_SETCONCURRENCY
82 int
83 ldap_pvt_thread_set_concurrency ( int concurrency )
84 {
85         return 1;
86 }
87 #endif
88
89 #ifndef LDAP_THREAD_HAVE_SLEEP
90 /*
91  * Here we assume we have fully preemptive threads and that sleep()
92  * does the right thing.
93  */
94 unsigned int
95 ldap_pvt_thread_sleep(
96         unsigned int interval
97 )
98 {
99         sleep( interval );
100         return 0;
101 }
102 #endif