@@ -61,25 +61,29 @@ class GRPDPLUpdatedTask
6161 // (the user enables this via O2_USEGRP_SEMA environment)
6262 bool use_sema = false ;
6363 boost::interprocess::named_semaphore* sem = nullptr ;
64- if (auto semaname = getenv (" O2_USEGRP_SEMA" )) {
65- try {
66- const auto semname = std::filesystem::current_path ().string () + mGRPFileName ;
67- std::hash<std::string> hasher;
68- const auto semhashedstring = " alice_grp_" + std::to_string (hasher (semname));
69- sem = new boost::interprocess::named_semaphore (boost::interprocess::open_or_create_t {}, semhashedstring.c_str (), 1 );
70- } catch (std::exception e) {
71- LOG (WARN ) << " Exception occurred during GRP semaphore setup; Continuing without" ;
72- sem = nullptr ;
73- }
64+ std::string semhashedstring;
65+ try {
66+ const auto semname = std::filesystem::current_path ().string () + mGRPFileName ;
67+ std::hash<std::string> hasher;
68+ semhashedstring = " alice_grp_" + std::to_string (hasher (semname)).substr (0 , 16 );
69+ sem = new boost::interprocess::named_semaphore (boost::interprocess::open_or_create_t {}, semhashedstring.c_str (), 1 );
70+ } catch (std::exception e) {
71+ LOG (WARN ) << " Could not setup GRP semaphore; Continuing without" ;
72+ sem = nullptr ;
7473 }
7574 try {
7675 if (sem) {
7776 sem->wait (); // wait until we can enter (no one else there)
7877 }
7978
80- auto postSem = [sem] {
79+ auto postSem = [sem, &semhashedstring ] {
8180 if (sem) {
8281 sem->post ();
82+ if (sem->try_wait ()) {
83+ // if nobody else is waiting remove the semaphore resource
84+ sem->post ();
85+ boost::interprocess::named_semaphore::remove (semhashedstring.c_str ());
86+ }
8387 delete sem;
8488 }
8589 };
0 commit comments