int daemon_GetNewFileID(T_FILE_ID *id, int flg){ struct timeval t; //ID取得 if ( semLock(SEM_LOCK_IDXO003, G_ConfTbl->enospc_retry, G_ConfTbl->enospc_retrans) < 0 ){ id->id.tv_sec=(time_t)999999999; id->id.tv_usec=(suseconds_t)999999; id->ver.tv_sec=(time_t)999999999; id->ver.tv_usec=(suseconds_t)999999; return -1; } gettimeofday(&t,NULL); if ( semUnLock(SEM_LOCK_IDXO003,G_ConfTbl->enospc_retry, G_ConfTbl->enospc_retrans) < 0 ){ id->id.tv_sec=(time_t)999999999; id->id.tv_usec=(suseconds_t)999999; id->ver.tv_sec=(time_t)999999999; id->ver.tv_usec=(suseconds_t)999999; return -2; } //新規ID if ( flg==1 && id->id.tv_sec != 0 ){ id->ver.tv_sec=(time_t)t.tv_sec; id->ver.tv_usec=(suseconds_t)t.tv_usec; }else{ id->id.tv_sec=(time_t)t.tv_sec; id->id.tv_usec=(suseconds_t)t.tv_usec; id->ver.tv_sec=(time_t)t.tv_sec; id->ver.tv_usec=(suseconds_t)t.tv_usec; } return 0; }
void Thread::stop() { //-- Increment stop sync point MutexLocker semLock(&(this->sync_stop_mutex)); sem_post(&(this->sync_stop)); }
PRBool MemMapSessionManager::deleteSession ( const char *id ) { SemLock semLock(_lockMgr, _lockId); _sessionblock sessionEntry; PRUintn sessionlocation = _getSessionBlock(id, sessionEntry); if (sessionlocation < _sessionFile->getMaxBlocks()) { // found. continue // run thru all session items and delete them. _deleteSessionFromLocation(sessionlocation, sessionEntry); return PR_TRUE; } return PR_FALSE; }
PRBool MemMapSessionManager::deleteSessionAtLocation ( PRUintn location ) { SemLock semLock(_lockMgr, _lockId); _sessionblock sessionEntry; // get the session block at the specified location. PRUintn sessionLocation = _getSessionBlockAtLocation (location,sessionEntry); // has this been cleaned up already? if so, nothing to do. if (sessionLocation >= _sessionFile->getMaxBlocks()) return PR_FALSE; // Cannot delete a valid session! if (_isSessionEntryValid(sessionLocation, sessionEntry)) return PR_FALSE; _deleteSessionFromLocation(sessionLocation, sessionEntry); return PR_TRUE; }
int MemMapSessionManager::reaper() { SemLock semLock(_lockMgr, _lockId); return _reapExpiredSessions(); }
static void handleGame(int shm_id, char *shm_addr, int sem_id, int queue_size, \ int *p_job_number, int *p_rel_prio, int *p_real_prio) { const char SEPERATOR[] = ":"; char accept_flag = 0; unsigned int game_counter = 0; char old_image[SHM_SIZE_IN_BYTES] = {0}; char current_image[SHM_SIZE_IN_BYTES] = {0}; char *p_element = NULL; while(1) { const char REJECT[] = "reject"; const char ACCEPT[] = "accept"; semLock(sem_id, shm_id); // Read the shared memory data. memcpy((void *)current_image, (void *)shm_addr, SHM_SIZE_IN_BYTES); // If there's nothing new, continue. if(0 == memcmp((void *)current_image, (void *)old_image, SHM_SIZE_IN_BYTES)) { semUnlock(sem_id, shm_id); continue; } printf("current: %s\n", current_image); if(accept_flag) { // Points to 'real_priority:' strtok(current_image, SEPERATOR); // Points to the real priority value. *p_real_prio = atoi(strtok(NULL, SEPERATOR)); printf("real prio: %d\n", *p_real_prio); semUnlock(sem_id, shm_id); break; } game_counter++; if(decideToAccept() || game_counter >= queue_size) { *p_job_number = atoi(strtok(current_image, SEPERATOR)); *p_rel_prio = atoi(strtok(NULL, SEPERATOR)); printf("Chose! job number: %d relative prio: %d\n", *p_job_number, *p_rel_prio); memcpy(current_image, ACCEPT, sizeof(ACCEPT)); accept_flag = 1; } else { memcpy(current_image, REJECT, sizeof(REJECT)); } // write the image to memory memcpy((void *)shm_addr, (void *)current_image, SHM_SIZE_IN_BYTES); semUnlock(sem_id, shm_id); // Update the old image. memcpy((void *)old_image, (void *)shm_addr, SHM_SIZE_IN_BYTES); } }
bool Thread::stopRequested() { MutexLocker semLock(&(this->sync_stop_mutex)); return sem_trywait(&(this->sync_stop))==-1 && errno == EAGAIN ? false : true; }