Exemplo n.º 1
0
 protected static function _initClockSeq()
 {
     $shmId = shm_attach(self::$_shmKey);
     self::$_clockSeq = shm_get_var($shmId, self::$_clockSeqKey);
     if (self::$_clockSeq === false) {
         $semId = sem_get(self::$_semKey);
         sem_acquire($semId);
         //blocking
         if (shm_has_var($shmId, self::$_clockSeqKey)) {
             self::$_clockSeq = shm_get_var($shmId, self::$_clockSeqKey);
         } else {
             // 0x8000 variant (2 bits)
             // clock sequence (14 bits)
             self::$_clockSeq = 0x8000 | mt_rand(0, (1 << 14) - 1);
             shm_put_var($shmId, self::$_clockSeqKey, self::$_clockSeq);
         }
         sem_release($semId);
     }
     shm_detach($shmId);
 }
Exemplo n.º 2
0
 protected static function _initClockSeq()
 {
     if (isset(self::$_clockSeq)) {
         // Already initialized
         return;
     }
     $shmId = shm_attach(self::$_shmKey);
     if (shm_has_var($shmId, self::$_clockSeqKey)) {
         self::$_clockSeq = shm_get_var($shmId, self::$_clockSeqKey);
     } else {
         $semId = sem_get(self::$_semKey);
         sem_acquire($semId);
         // Start blocking
         // 0x8000 variant (2 bits)
         // clock sequence (14 bits)
         self::$_clockSeq = 0x8000 | mt_rand(0, (1 << 14) - 1);
         shm_put_var($shmId, self::$_clockSeqKey, self::$_clockSeq);
         sem_release($semId);
         // Stop blocking
     }
     shm_detach($shmId);
 }