๐Ÿ“ฆ apache / nuttx

๐Ÿ“„ event_close.c ยท 100 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100/****************************************************************************
 * fs/event/event_close.c
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.  The
 * ASF licenses this file to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *
 ****************************************************************************/

/****************************************************************************
 * Included Files
 ****************************************************************************/

#include <nuttx/config.h>

#include <sched.h>
#include <assert.h>
#include <errno.h>

#include <nuttx/event.h>
#include <nuttx/fs/fs.h>

#include "inode/inode.h"
#include "vfs/vfs.h"

/****************************************************************************
 * Public Functions
 ****************************************************************************/

/****************************************************************************
 * Name:  nxevent_close
 *
 * Description:
 *   This function is called to indicate that the calling task is finished
 *   with the specified named event group. The event_close() deallocates
 *   any system resources allocated by the system for this named event.
 *
 * Input Parameters:
 *  event - event descriptor
 *
 * Returned Value:
 *  0 (OK), or negated errno if unsuccessful.
 *
 * Assumptions:
 *   - Care must be taken to avoid risking the deletion of a event that
 *     another calling task has already locked.
 *   - event_close must not be called for an un-named event
 *
 ****************************************************************************/

int nxevent_close(FAR nxevent_t *event)
{
  FAR struct nevent_inode_s *nevent;
  struct inode *inode;

  DEBUGASSERT(event);

  /* Upcast to get back to out internal representation */

  nevent = (FAR struct nevent_inode_s *)event;
  DEBUGASSERT(nevent->ne_inode);
  inode = nevent->ne_inode;

  /* If the event group was previously unlinked and the reference count has
   * decremented to zero, then release the event group and delete the inode
   * now.
   */

  if (atomic_fetch_sub(&inode->i_crefs, 1) <= 1)
    {
      nxevent_destroy(&nevent->ne_event);
      group_free(NULL, nevent);

      /* Release and free the inode container.  If it has been properly
       * unlinked, then the peer pointer should be NULL.
       */

#ifdef CONFIG_FS_NOTIFY
      notify_close2(inode);
#endif
      DEBUGASSERT(inode->i_peer == NULL);
      inode_free(inode);
    }

  return OK;
}