]> git.sur5r.net Git - openldap/blob - servers/slapd/alock.h
82fa432901f473e48f43cc82a24d1b1c8e512de6
[openldap] / servers / slapd / alock.h
1 /* alock.h - access lock header */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2005-2017 The OpenLDAP Foundation.
6  * Portions Copyright 2004-2005 Symas Corporation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Emily Backes at Symas
19  * Corporation for inclusion in OpenLDAP Software.
20  */
21
22 #ifndef _ALOCK_H_
23 #define _ALOCK_H_
24
25 #include "portable.h"
26 #include <ac/time.h>
27 #include <ac/unistd.h>
28
29 /* environment states (all the slots together) */
30 #define ALOCK_CLEAN             (0)
31 #define ALOCK_RECOVER   (1)
32 #define ALOCK_BUSY              (2)
33 #define ALOCK_UNSTABLE  (3)
34
35 /* lock user types and states */
36 #define ALOCK_UNLOCKED  (0)
37 #define ALOCK_LOCKED    (1)
38 #define ALOCK_UNIQUE    (2)
39 #define ALOCK_DIRTY             (3)
40
41 #define ALOCK_SMASK             3
42
43 /* lock/state where recovery is not available */
44 #define ALOCK_NOSAVE    4
45
46 /* constants */
47 #define ALOCK_SLOT_SIZE         (1024)
48 #define ALOCK_SLOT_IATTRS       (4)
49 #define ALOCK_MAX_APPNAME       (ALOCK_SLOT_SIZE - 8 * ALOCK_SLOT_IATTRS)
50 #define ALOCK_MAGIC                     (0x12345678)
51
52 LDAP_BEGIN_DECL
53
54 typedef struct alock_info {
55         int al_fd;
56         int al_slot;
57 } alock_info_t;
58
59 typedef struct alock_slot {
60         unsigned int al_lock;
61         time_t al_stamp;
62         pid_t al_pid;
63         char * al_appname;
64 } alock_slot_t;
65
66 LDAP_SLAPD_F (int) alock_open LDAP_P(( alock_info_t * info, const char * appname,
67         const char * envdir, int locktype ));
68 LDAP_SLAPD_F (int) alock_scan LDAP_P(( alock_info_t * info ));
69 LDAP_SLAPD_F (int) alock_close LDAP_P(( alock_info_t * info, int nosave ));
70 LDAP_SLAPD_F (int) alock_recover LDAP_P(( alock_info_t * info ));
71
72 LDAP_END_DECL
73
74 #endif