|
1 | 1 | /* |
2 | | - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. |
| 2 | + * Copyright (c) 2006-2018, NVIDIA CORPORATION. All rights reserved. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
15 | 15 | * |
16 | 16 | */ |
17 | 17 |
|
18 | | -/* |
19 | | - * Four routines to be able to lock access to a file in the Linux |
20 | | - * approved manner. This seems to be the only method that works |
21 | | - * over NFS: |
22 | | - * |
23 | | - * __pg_make_lock_file() |
24 | | - * Creates a uniquely-named file in the current directory. |
25 | | - * To work, this must be created on the same filesystem |
26 | | - * as the file which we are attempting to lock. |
27 | | - * If there are multiple processes running each competing for the |
28 | | - * same lock, each gets a unique file here. |
29 | | - * __pg_get_lock( char* lname ) |
30 | | - * The argument is the name of the lock. |
31 | | - * Each process tries to create a hard link with this name |
32 | | - * to its own uniquely-named file from __pg_make_lock_file(). |
33 | | - * The one that succeeds is the new lock owner. The others |
34 | | - * fail and try again. There is a fail-over to handle the case |
35 | | - * where the process with the lock dies, which is inherently unsafe, |
36 | | - * but we haven't come up with a better solution. |
37 | | - * __pg_release_lock( char* lname ) |
38 | | - * The argument is the same name for the lock. |
39 | | - * The lock is released by deleting (calling unlink) for the |
40 | | - * hard link we had just created. |
41 | | - * __pg_delete_lock_file() |
42 | | - * Clean up by deleting the uniquely named file we had created earlier. |
43 | | - * These routines only allow one lock to be managed at a time. |
44 | | - * They dynamically allocate and free memory. |
| 18 | +/** |
| 19 | + \file |
| 20 | +
|
| 21 | + Four routines to be able to lock access to a file in the Linux |
| 22 | + approved manner. This seems to be the only method that works |
| 23 | + over NFS. |
| 24 | + */ |
| 25 | + |
| 26 | +#ifdef __cplusplus |
| 27 | +extern "C" { |
| 28 | +#endif |
| 29 | + |
| 30 | +/** |
| 31 | + \brief Creates a uniquely-named file in the current directory. |
| 32 | +
|
| 33 | + To work, this must be created on the same filesystem as the file which we are |
| 34 | + attempting to lock. If there are multiple processes running each competing |
| 35 | + for the same lock, each gets a unique file here. |
| 36 | + */ |
| 37 | +int __pg_make_lock_file(char *dir); |
| 38 | + |
| 39 | +/** |
| 40 | + \brief The argument is the name of the lock. |
| 41 | +
|
| 42 | + Each process tries to create a hard link with this name to its own |
| 43 | + uniquely-named file from __pg_make_lock_file(). The one that succeeds is the |
| 44 | + new lock owner. The others fail and try again. There is a fail-over to |
| 45 | + handle the case where the process with the lock dies, which is inherently |
| 46 | + unsafe, but we haven't come up with a better solution. |
| 47 | + */ |
| 48 | +void __pg_get_lock(char *lname); |
| 49 | + |
| 50 | +/** |
| 51 | + \brief The argument is the same name for the lock. |
| 52 | +
|
| 53 | + The lock is released by deleting (calling unlink) for the hard link we had |
| 54 | + just created. |
| 55 | + */ |
| 56 | +void __pg_release_lock(char *lname); |
| 57 | + |
| 58 | +/** |
| 59 | + \brief Clean up by deleting the uniquely named file we had created earlier. |
| 60 | +
|
| 61 | + These routines only allow one lock to be managed at a time. They dynamically |
| 62 | + allocate and free memory. |
45 | 63 | */ |
| 64 | +void __pg_delete_lock_file(void); |
46 | 65 |
|
47 | | -extern int __pg_make_lock_file(char *dir); |
48 | | -extern void __pg_get_lock(char *lname); |
49 | | -extern void __pg_release_lock(char *lname); |
50 | | -extern void __pg_delete_lock_file(void); |
| 66 | +#ifdef __cplusplus |
| 67 | +} |
| 68 | +#endif |
0 commit comments