5
Last change
on this file since 77fbbd6 was
c090db7,
checked in by Sebastian Huber <sebastian.huber@…>, on 09/12/17 at 06:09:16
|
posix: Implement self-contained POSIX semaphores
For semaphore object pointer and object validation see
POSIX_SEMAPHORE_VALIDATE_OBJECT().
Destruction or close of a busy semaphore returns an error status. The
object is not flushed.
POSIX semaphores are now available in all configurations and no longer
depend on --enable-posix.
Update #2514.
Update #3116.
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Close a Named Semaphore |
---|
5 | * @ingroup POSIX_SEMAPHORE |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/posix/semaphoreimpl.h> |
---|
22 | |
---|
23 | int sem_close( sem_t *sem ) |
---|
24 | { |
---|
25 | POSIX_Semaphore_Control *the_semaphore; |
---|
26 | uint32_t open_count; |
---|
27 | |
---|
28 | POSIX_SEMAPHORE_VALIDATE_OBJECT( sem ); |
---|
29 | |
---|
30 | if ( !_POSIX_Semaphore_Is_named( sem ) ) { |
---|
31 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
32 | } |
---|
33 | |
---|
34 | the_semaphore = _POSIX_Semaphore_Get( sem ); |
---|
35 | |
---|
36 | _Objects_Allocator_lock(); |
---|
37 | |
---|
38 | open_count = the_semaphore->open_count; |
---|
39 | |
---|
40 | if ( open_count == 0 ) { |
---|
41 | _Objects_Allocator_unlock(); |
---|
42 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
43 | } |
---|
44 | |
---|
45 | if ( open_count == 1 && _POSIX_Semaphore_Is_busy( sem ) ) { |
---|
46 | _Objects_Allocator_unlock(); |
---|
47 | rtems_set_errno_and_return_minus_one( EBUSY ); |
---|
48 | } |
---|
49 | |
---|
50 | the_semaphore->open_count = open_count - 1; |
---|
51 | _POSIX_Semaphore_Delete( the_semaphore ); |
---|
52 | _Objects_Allocator_unlock(); |
---|
53 | return 0; |
---|
54 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.