static inline void sem_add(const DString &name, const sem_data_t &data) { sem_map_t &map = sem_map(); sem_map_t::iterator it = map.find(name); if (it == map.end()) { assert(data.sem); map.insert(std::pair<DString, sem_data_t>(name, data)); } }
static inline sem_data_t &sem_get_data(const DString &name, EnvT *e) { sem_map_t &map = sem_map(); sem_map_t::iterator it = map.find(name); if (it == map.end()) { e->Throw("Unknown semaphore name provided: " + name + "."); } return it->second; }
// executed in gdlexit() void sem_onexit() { // remove semaphores created by this gdl process sem_map_t &map = sem_map(); for (sem_map_t::iterator it = map.begin(); it != map.end(); ++it) { if (sem_is_deletable(it->second)) { #if defined(_WIN32) && !defined(__CYGWIN__) CloseHandle(it->second.sem); #else sem_unlink(it->first.c_str()); #endif } } // don't bother with invalid semaphores because we're exiting }
static inline void sem_remove(const DString &name) { sem_map().erase(name); }