@@ -22,7 +22,7 @@ Semaphore(name, value; perms=0o600, volatile=true) -> sem
22
22
creates a new named semaphore identified by the string `name` of the form
23
23
`"/somename"` and initial value set to `value`. An instance of
24
24
`Semaphore{String}` is returned. Keyword `perms` can be used to specify access
25
- permissions. The permissions settings are masked against the process `umask`.
25
+ permissions.
26
26
Keyword `volatile` specifies whether the semaphore should be unlinked when the
27
27
returned object is finalized.
28
28
@@ -52,8 +52,9 @@ open(Semaphore, name, flags, mode, value, volatile) -> sem
52
52
where `flags` may have the bits `IPC.O_CREAT` and `IPC.O_EXCL` set, `mode`
53
53
specifies the granted access permissions, `value` is the initial semaphore
54
54
value and `volatile` is a boolean indicating whether the semaphore should be
55
- unlinked when the returned object `sem` is finalized. The values of `mode` and
56
- `value` are ignored if an existing named semaphore is open.
55
+ unlinked when the returned object `sem` is finalized. The values of `mode` and
56
+ `value` are ignored if an existing named semaphore is open. The permissions
57
+ settings in `mode` are masked against the process `umask`.
57
58
58
59
59
60
## Anonymous Semaphores
@@ -68,7 +69,7 @@ Semaphore(mem, value; offset=0, volatile=true) -> sem
68
69
initializes an anonymous semaphore backed by memory object `mem` with initial
69
70
value set to `value` and returns an instance of `Semaphore{typeof(mem)}`.
70
71
Keyword `offset` can be used to specify the address (in bytes) of the semaphore
71
- data relative to `pointer(mem)`. Keyword `volatile` specify whether the
72
+ data relative to `pointer(mem)`. Keyword `volatile` specify whether the
72
73
semaphore should be destroyed when the returned object is finalized.
73
74
74
75
```julia
@@ -81,7 +82,7 @@ position (in bytes) specified by keyword `offset`.
81
82
82
83
The number of bytes needed to store an anonymous semaphore is given by
83
84
`sizeof(Semaphore)` and anonymous semaphore must be aligned in memory at
84
- multiples of the word size (that is `Sys.WORD_SIZE >> 3` in bytes). Memory
85
+ multiples of the word size (that is `Sys.WORD_SIZE >> 3` in bytes). Memory
85
86
objects used to store an anonymous semaphore must implement two methods:
86
87
`pointer(mem)` and `sizeof(mem)` to yield respectively the base address and the
87
88
size (in bytes) of the associated memory.
@@ -96,7 +97,12 @@ function Semaphore(name::AbstractString, value::Integer;
96
97
val = _check_semaphore_value (value)
97
98
mode = maskmode (perms)
98
99
flags = O_CREAT | O_EXCL
99
- return open (Semaphore, name, flags, mode, val, volatile)
100
+ old_mask = umask (0 ) # clear file mode creation mask remembering previous settings
101
+ try
102
+ return open (Semaphore, name, flags, mode, val, volatile)
103
+ finally
104
+ umask (old_mask) # restore file mode creation mask
105
+ end
100
106
end
101
107
102
108
function Semaphore (name:: AbstractString )
@@ -112,7 +118,7 @@ function Base.open(::Type{Semaphore}, name::AbstractString, flags::Integer,
112
118
systemerror (" sem_open" , ptr == SEM_FAILED)
113
119
sem = Semaphore {String} (ptr, name)
114
120
if volatile
115
- finalizer (_close_and_unlink, sem, )
121
+ finalizer (_close_and_unlink, sem)
116
122
else
117
123
finalizer (_close, sem)
118
124
end
@@ -125,8 +131,7 @@ function Semaphore(mem::M, value::Integer;
125
131
volatile:: Bool = true ) where {M}
126
132
val = _check_semaphore_value (value)
127
133
ptr = _get_semaphore_address (mem, offset)
128
- systemerror (" sem_init" ,
129
- _sem_init (ptr, true , val) != SUCCESS)
134
+ systemerror (" sem_init" , _sem_init (ptr, true , val) != SUCCESS)
130
135
sem = Semaphore {M} (ptr, mem)
131
136
if volatile
132
137
finalizer (_destroy, sem)
0 commit comments