Пример #1
0
    void remove_watch(const string& path)
    {
      int fd = descriptors_by_file_name[path];
      descriptors_by_file_name.erase(path);
      file_names_by_descriptor.erase(fd);
      file_modes.erase(fd);

      close(fd);
    }
Пример #2
0
    void remove_watch(int fd)
    {
      string name = file_names_by_descriptor[fd];
      file_names_by_descriptor.erase(fd);
      descriptors_by_file_name.erase(name);
      file_modes.erase(fd);

      close(fd);
    }
Пример #3
0
int fsw_destroy_session(const FSW_HANDLE handle)
{
  try
  {
#ifdef HAVE_CXX_MUTEX
    std::lock_guard<std::mutex> session_lock(session_mutex);
#endif
    FSW_SESSION * session = get_session(handle);

#ifdef HAVE_CXX_MUTEX
#  ifdef HAVE_CXX_UNIQUE_PTR
    const unique_ptr<mutex> & sm = session_mutexes[handle];
    lock_guard<mutex> sm_lock(*sm.get());
#  else
    mutex * sm = session_mutexes[handle];
    lock_guard<mutex> sm_lock(*sm);
#  endif
#endif

    if (session->monitor)
    {
      void * context = session->monitor->get_context();

      if (!context)
      {
        session->monitor->set_context(nullptr);
        delete static_cast<fsw_callback_context *> (context);
      }

      delete session->monitor;
    }

    sessions.erase(handle);
#ifdef HAVE_CXX_MUTEX
    session_mutexes.erase(handle);
#endif
  }
  catch (int error)
  {
    return fsw_set_last_error(error);
  }

  return fsw_set_last_error(FSW_OK);
}