Debian Codegraph @

storage/mroonga/vendor/groonga/lib/file_lock.c

raw symbols SCIP
1 /* -*- c-basic-offset: 2 -*- */cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/file_lock.c`/
2 /*
3 Copyright(C) 2017 Brazil
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License version 2.1 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
17 */
18
19 #include "grn_file_lock.h"cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/grn_file_lock.h`/
20 #include "grn_ctx.h"cxx . . $ `<file>/storage/mroonga/vendor/groonga/lib/grn_ctx.h`/
21
22 #include <sys/stat.h>
23
24 #ifdef WIN32
25 # include <io.h>
26 # include <share.h>
27 #else /* WIN32 */
28 # include <sys/types.h>
29 # include <fcntl.h>
30 #endif /* WIN32 */
31
32 #ifdef WIN32
33 # define GRN_FILE_LOCK_IS_INVALID(file_lock) \
34 ((file_lock)->handle == INVALID_HANDLE_VALUE)
35 #else /* WIN32 */
36 # define GRN_FILE_LOCK_IS_INVALIDcxx . . $ `storage/mroonga/vendor/groonga/lib/file_lock.c:36:10`!(file_lock) \
37 ((file_lock)->fd == -1)
38 #endif /* WIN32 */
39
40 void
41 grn_file_lock_initcxx . . $ grn_file_lock_init(b6f038a97f7c4fb7).(grn_ctxcxx . . $ grn_ctx# *ctx,
42 grn_file_lockcxx . . $ grn_file_lock# *file_lock,
43 const char *path)
44 {
45 file_lock->pathcxx . . $ $anonymous_type_d1138a34d461fd23_0#path. = path;
46 #ifdef WIN32
47 file_lock->handle = INVALID_HANDLE_VALUE;
48 #else /* WIN32 */
49 file_lock->fdcxx . . $ $anonymous_type_d1138a34d461fd23_0#fd. = -1;
50 #endif /* WIN32 */
51 }
52
53 grn_boolcxx . . $ grn_bool#
54 grn_file_lock_acquirecxx . . $ grn_file_lock_acquire(24e4cd5c1c13dce9).(grn_ctxcxx . . $ grn_ctx# *ctx,
55 grn_file_lockcxx . . $ grn_file_lock# *file_lock,
56 int timeout,
57 const char *error_message_tag)
58 {
59 int i;
60 int n_lock_tries = timeout;
61
62 if (!file_lock->pathcxx . . $ $anonymous_type_d1138a34d461fd23_0#path.) {
63 return GRN_TRUEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:44:9`!;
64 }
65
66 for (i = 0; i < n_lock_tries; i++) {
67 #ifdef WIN32
68 file_lock->handle = CreateFile(file_lock->path,
69 GENERIC_READ | GENERIC_WRITE,
70 0,
71 NULL,
72 CREATE_ALWAYS,
73 FILE_ATTRIBUTE_NORMAL,
74 NULL);
75 #else /* WIN32 */
76 file_lock->fdcxx . . $ $anonymous_type_d1138a34d461fd23_0#fd. = opencxx . . $ open(ac5e327aedb29b06).(file_lock->pathcxx . . $ $anonymous_type_d1138a34d461fd23_0#path., O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`! | O_EXCLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:50:10`!, S_IRUSRcxx . . $ `<external>/14710646456994434043/fcntl.h:105:10`! | S_IWUSRcxx . . $ `<external>/14710646456994434043/fcntl.h:106:10`!);
77 #endif
78 if (!GRN_FILE_LOCK_IS_INVALIDcxx . . $ `storage/mroonga/vendor/groonga/lib/file_lock.c:36:10`!(file_lock)) {
79 break;
80 }
81 grn_nanosleepcxx . . $ grn_nanosleep(2c44cd906ae4e829).(GRN_LOCK_WAIT_TIME_NANOSECONDcxx . . $ `build/storage/mroonga/vendor/groonga/config.h:35:9`!);
82 }
83
84 if (GRN_FILE_LOCK_IS_INVALIDcxx . . $ `storage/mroonga/vendor/groonga/lib/file_lock.c:36:10`!(file_lock)) {
85 ERRcxx . . $ `storage/mroonga/vendor/groonga/lib/grn_ctx.h:143:9`!(GRN_NO_LOCKS_AVAILABLE,
86 "%s failed to acquire lock: <%s>",
87 error_message_tag, file_lock->path);
88 return GRN_FALSEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:45:9`!;
89 } else {
90 return GRN_TRUEcxx . . $ `storage/mroonga/vendor/groonga/include/groonga/groonga.h:44:9`!;
91 }
92 }
93
94 void
95 grn_file_lock_releasecxx . . $ grn_file_lock_release(7fc6e84b96ea19e9).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_file_lockcxx . . $ grn_file_lock# *file_lock)
96 {
97 if (GRN_FILE_LOCK_IS_INVALIDcxx . . $ `storage/mroonga/vendor/groonga/lib/file_lock.c:36:10`!(file_lock)) {
98 return;
99 }
100
101 #ifdef WIN32
102 CloseHandle(file_lock->handle);
103 DeleteFile(file_lock->path);
104
105 file_lock->handle = INVALID_HANDLE_VALUE;
106 #else /* WIN32 */
107 closecxx . . $ close(7864480464b09eea).(file_lock->fdcxx . . $ $anonymous_type_d1138a34d461fd23_0#fd.);
108 unlinkcxx . . $ unlink(5c4306d8553b3696).(file_lock->pathcxx . . $ $anonymous_type_d1138a34d461fd23_0#path.);
109
110 file_lock->fdcxx . . $ $anonymous_type_d1138a34d461fd23_0#fd. = -1;
111 #endif /* WIN32 */
112 file_lock->pathcxx . . $ $anonymous_type_d1138a34d461fd23_0#path. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
113 }
114
115 void
116 grn_file_lock_fincxx . . $ grn_file_lock_fin(7fc6e84b96ea19e9).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_file_lockcxx . . $ grn_file_lock# *file_lock)
117 {
118 if (!GRN_FILE_LOCK_IS_INVALIDcxx . . $ `storage/mroonga/vendor/groonga/lib/file_lock.c:36:10`!(file_lock)) {
119 grn_file_lock_releasecxx . . $ grn_file_lock_release(7fc6e84b96ea19e9).(ctx, file_lock);
120 }
121 }