Example #1
0
// remove the entry from the database and then destroy the cacheentry
void InternalCCache::remove(const char* key)
{
  log->debug("removing cache entry with key (%s)", key);

  // lock the cache for writing, which means we know nobody is sitting in find()
  lock->wrlock();

  // grab the entry from the database.
  ISessionCacheEntry* entry = findi(key);

  if (!entry) {
    lock->unlock();
    return;
  }

  // ok, remove the entry and lock it
  m_hashtable.erase(key);
  dynamic_cast<InternalCCacheEntry*>(entry)->lock();
  lock->unlock();

  // we can release the entry lock because we know we're not in the cache anymore
  entry->unlock();

  // Now delete the entry
  delete entry;
}
Example #2
0
void InternalCCache::insert(
    const char* key,
    const IApplication* application,
    const char* client_addr,
    ShibProfile profile,
    const char* providerId,
    SAMLAuthenticationStatement* s,
    SAMLResponse* r,
    const IRoleDescriptor* source,
    time_t created,
    time_t accessed
    )
{
  log->debug("caching new entry for application %s: \"%s\"", application->getId(), key);

  InternalCCacheEntry* entry = new InternalCCacheEntry(
    this,
    key,
    application,
    client_addr,
    profile,
    providerId,
    s,
    r,
    source,
    created,
    accessed
    );

  lock->wrlock();
  m_hashtable[key]=entry;
  lock->unlock();
}
Example #3
0
void quitar_partes_barco(list<Casillero>& barco_actual, vector<vector<char> >& tablero_cliente, RWLock& tablero_cliente_rwlock) {
    tablero_cliente_rwlock.wlock();
    for (list<Casillero>::const_iterator casillero = barco_actual.begin(); casillero != barco_actual.end(); casillero++) {
        tablero_cliente[casillero->fila][casillero->columna] = VACIO;
    }
    tablero_cliente_rwlock.wunlock();
    barco_actual.clear();
}
Example #4
0
Client::Client()
{
  client_no_rw.write_lock();
  number = ++client_no;
  cerr_rw.write_lock();
  cerr<<"Client "<<number<<" created"<<endl;
  cerr_rw.write_unlock();
  client_no_rw.write_unlock();
}
Example #5
0
void 
Read()
{
	locker.Lock(RWLock::R);
	int index = rand() % globalVector.size();
	cout << "Reading random index " << index << " value = " <<
		globalVector[index] << endl;
	locker.UnLock(RWLock::R);
}
Example #6
0
void 
Write()
{
	locker.Lock(RWLock::W);
	int index = globalVector.size();
	cout << "Writing index " << index << " value = " <<
		index << endl;
	globalVector.push_back(index);
	locker.UnLock(RWLock::W);
}
Example #7
0
void reader(int id) {
    rwLock.readLock();
    int i = rand() % buffer.size();
    int data = buffer[i];
    {
        lock_guard<mutex> lock(outputLock);
        cout << "reader " << id << " reads buffer[" << i << "] = " << data << endl;
    }
    rwLock.readUnLock();
}
Example #8
0
s32 sys_rwlock_tryrlock(u32 rw_lock_id)
{
	sys_rwlock.Log("sys_rwlock_tryrlock(rw_lock_id=%d)", rw_lock_id);

	RWLock* rw;
	if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH;

	if (!rw->rlock_trylock(GetCurrentPPUThread().GetId())) return CELL_EBUSY;

	return CELL_OK;
}
Example #9
0
int sys_rwlock_wunlock(u32 rw_lock_id)
{
	sys_rwlock.Log("sys_rwlock_wunlock(rw_lock_id=%d)", rw_lock_id);

	RWLock* rw;
	if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH;

	if (!rw->wlock_unlock(GetCurrentPPUThread().GetId())) return CELL_EPERM;

	return CELL_OK;
}
Example #10
0
void *lector(void *p_minumero) {
    int minumero = *((int *) p_minumero);
    
    printf("LECTOR %d QUIERE LEER\n", minumero);
    lock.rlock();
    printf("LECTOR %d LEYENDO\n", minumero);
    sleep(SLEEP_LECTORES);
    lock.runlock();
    printf("LECTOR %d HA LEIDO\n", minumero);
    return NULL;
}
Example #11
0
void writer(int id) {
    rwLock.writeLock();
    int i = rand() % buffer.size();
    int data = rand();
    buffer[i] = data;
    {
        lock_guard<mutex> lock(outputLock);
        cout << "writer " << id << " writes buffer[" << i << "] = " << data << endl;
    }
    rwLock.writeUnLock();
}
Example #12
0
void *escritor(void *p_minumero) {
    int minumero = *((int *) p_minumero);
    
    printf("ESCRITOR %d QUIERE ESCRBIR\n", minumero);
    lock.wlock();
    printf("ESCRITOR %d ESCRIBIENDO\n", minumero);
    sleep(SLEEP_ESCRITORES);
    lock.wunlock();
    printf("ESCRITOR %d HA ESCRITO\n", minumero);
    return NULL;
}
Example #13
0
void *read(void *p_args) {
    int* args = (int*) p_args;
    if(args[0] == -1)
        sleep(args[1]);

    lock.rlock();
    sleep(2);
    printf("Compartida: %d\n", compartida);
    lock.runlock();

    pthread_exit(NULL);
}
Example #14
0
void *write(void *p_args) {
    int* args = (int*) p_args;
    if(args[0] == -1)
        sleep(args[1]);

    lock.wlock();
    sleep(5);
    compartida = args[2];
    lock.wunlock();

    pthread_exit(NULL);
}
Example #15
0
OSTHREAD_FUNC lock_thread(void *parm){
  //int i = (int)(long long) parm;
  int j;
  int r;
  for (j=0; j < LOCK_OPS; ++j){
    lock_l.lock();
    r = lock_n.next() % 2;
    lock_counter1 = lock_counter1 ^ r;
    lock_counter2 = lock_counter2 ^ r;
    lock_counter3 = lock_counter3 + 1;
    lock_l.unlock();
  }
  return 0;
}
Example #16
0
void ClearWarnings(u64 category) {
	WarningsRWL.LockExclusive();
	Array<u64> RemoveList;

	for (auto kv : WarningsIssued) {
		if (kv.value == category) {
			PushBack(RemoveList, kv.key);
		}
	}
	for (auto k : RemoveList) {
		Remove(WarningsIssued, k);
	}
	WarningsRWL.UnlockExclusive();
}
Example #17
0
s32 sys_rwlock_trywlock(u32 rw_lock_id)
{
	sys_rwlock.Log("sys_rwlock_trywlock(rw_lock_id=%d)", rw_lock_id);

	RWLock* rw;
	if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH;
	const u32 tid = GetCurrentPPUThread().GetId();

	if (!rw->wlock_check(tid)) return CELL_EDEADLK;

	if (!rw->wlock_trylock(tid, false)) return CELL_EBUSY;

	return CELL_OK;
}
Example #18
0
    /*
     * Update repository information and return thre repoId, otherwise empty 
     * string.
     */
    void updateRepo(const string &path) {
        RepoControl repo = RepoControl(path);
        RepoInfo info;

        try {
            repo.open();
        } catch (SystemException &e) {
            WARNING("Failed to open repository %s: %s", path.c_str(), e.what());
            return;
        }

        RWKey::sp key = infoLock.writeLock();
        if (myInfo.hasRepo(repo.getUUID())) {
            info = myInfo.getRepo(repo.getUUID());
        } else {
            info = RepoInfo(repo.getUUID(), repo.getPath());
        }
        info.updateHead(repo.getHead());
        myInfo.updateRepo(repo.getUUID(), info);

        LOG("Checked %s: %s %s", path.c_str(), repo.getHead().c_str(), repo.getUUID().c_str());
        
        repo.close();

        return;
    }
int enviar_tablero(int socket_fd) {
    char buf[MENSAJE_MAXIMO+1];
    sprintf(buf, "STATUS ");
    int pos = 7;
    escribiendo.rlock();
    for (unsigned int fila = 0; fila < alto; ++fila) {
        for (unsigned int col = 0; col < ancho; ++col) {
            char letra = tablero_palabras[fila][col];
            buf[pos] = (letra == VACIO)? '-' : letra;
            pos++;
        }
    }
    escribiendo.runlock();
    buf[pos] = 0; //end of buffer

    return enviar(socket_fd, buf);
}
Example #20
0
int main(int argc, char **argv)
{
	uint32_t which_lock;  // 1-5
	uint32_t which_side;  // 0 or 1
	uint32_t lock_unlock;  // 0 or 1
	RWLock *rwlock;

	name = argv[0];

	if (argc != 4)
		usage();
	if (strlen(argv[1]) != 1 || strlen(argv[2]) != 1 || strlen(argv[3]) != 1)
		usage();

	which_lock = atoi(argv[1]);
	if (which_lock < 1 || which_lock > 5)
		usage();

	if (argv[2][0] == 'r')
		which_side = 0;
	else if (argv[2][0] == 'w')
		which_side = 1;
	else
		usage();

	if (argv[3][0] == 'l')
		lock_unlock = 0;
	else if (argv[3][0] == 'u')
		lock_unlock = 1;
	else
		usage();

	rwlock = new RWLock(0x10000 * which_lock);
	if (which_side == 0)
		if (lock_unlock == 0)
			rwlock->read_lock();
		else
			rwlock->read_unlock();
	else
		if (lock_unlock == 0)
			rwlock->write_lock();
		else
			rwlock->write_unlock();

	return 0;
}
    int get(int key) {
        // this will do
        // shared_lock<shared_mutex> lk(s_mtx);
        rw_lock.ReadLock();

        int hash_key = hash(key);

        int ret = -1;
        for(auto it = m_map[hash_key].begin(); it != m_map[hash_key].end(); it++) {
            if((*it).first == key) {
                ret = (*it).second;
                break;
            }
        }

        rw_lock.ReadUnLock();
        return ret;
    }
Example #22
0
    void dumpHosts() {
        RWKey::sp key = hostsLock.readLock();
        map<string, HostInfo *>::iterator it;

        cout << "=== Begin Hosts ===" << endl;
        for (it = hosts.begin(); it != hosts.end(); it++) {
            cout << it->second->getHost() << endl;
        }
        cout << "==== End Hosts ====" << endl << endl;
    }
    void put(int key, int val) {
        // this will do
        // unique_lock<shared_mutex> lk(s_mtx);
        int hash_key = hash(key);

        rw_lock.WriteLock();
        for(auto it = m_map[hash_key].begin(); it != m_map[hash_key].end(); it++) {
            if((*it).first == key) {
                (*it).first = key;
                (*it).second = val;

                rw_lock.WriteUnLock();
                return;
            }
        }
        // new key, insert
        m_map[hash_key].push_front({key, val});
        rw_lock.WriteUnLock();
    }
Example #24
0
void* lector(void * arg){
	//++++++++++++++ACA CREAMOS UNA BARRERA PARA QUE TODOS LOS THREADS ESPEREN A QUE SEAN TODOS CREADOS
	pthread_mutex_lock(&mut);
	while(!todos_creados){
		pthread_cond_wait(&barrera, &mut);
		}

	pthread_mutex_unlock(&mut);
	//++++++++++++++++++++++++++++
	
	int yo = (int)(long)arg;
	lock_valor.rlock();
	printf ("mi tid---->%d leo valor:%d\n", yo, valor );
	lock_valor.runlock();
	
		
	pthread_exit(NULL);
	return NULL;
}
Example #25
0
namespace Essence {

void ConsolePrint(const char* str) {
	OutputDebugStringA(str);
}

Hashmap<u64, u64>	WarningsIssued;
RWLock				WarningsRWL;

void FreeWarningsMemory() {
	FreeMemory(WarningsIssued);
}

void ClearWarnings(u64 category) {
	WarningsRWL.LockExclusive();
	Array<u64> RemoveList;

	for (auto kv : WarningsIssued) {
		if (kv.value == category) {
			PushBack(RemoveList, kv.key);
		}
	}
	for (auto k : RemoveList) {
		Remove(WarningsIssued, k);
	}
	WarningsRWL.UnlockExclusive();
}

void Warning(const char* message, bool one_time, u64 category) {
	auto hash = Hash::MurmurHash2_64(message, strlen(message), 0);

	bool print = !one_time;

	if (one_time) {
		WarningsRWL.LockShared();
		if (!Contains(WarningsIssued, hash)) {
			print = true;
			WarningsRWL.UnlockShared();
			WarningsRWL.LockExclusive();
			WarningsIssued[hash] = category;
			WarningsRWL.UnlockExclusive();
		}
		else {
			WarningsRWL.UnlockShared();
		}
	}

	if (print) {
		ConsolePrint("WARNING: ");
		ConsolePrint(message);
	}
}


}
Example #26
0
    void updateHost(KVSerializer &kv, const string &srcIp) {
        RWKey::sp key = hostsLock.writeLock();
        map<string, HostInfo *>::iterator it;
        string hostId = kv.getStr("hostId");
 
        // Update
        it = hosts.find(hostId);
        if (it == hosts.end()) {
            hosts[hostId] = new HostInfo(hostId, kv.getStr("cluster"));
        }
        hosts[hostId]->update(kv);
        hosts[hostId]->setPreferredIp(srcIp);
    }
Example #27
0
    string generate() {
        RWKey::sp key = infoLock.readLock();
        char buf[32];
        string msg;

        // First 31 bytes of cluster with null
        memset(buf, 0, 32);
        strncpy(buf, rc.getCluster().c_str(), 31);
        msg.assign(buf, 32);
        msg.append(OriCrypt_Encrypt(myInfo.getBlob(), rc.getKey()));

        return msg;
    }
Example #28
0
int sys_rwlock_wlock(u32 rw_lock_id, u64 timeout)
{
	sys_rwlock.Log("sys_rwlock_wlock(rw_lock_id=%d, timeout=%lld)", rw_lock_id, timeout);

	RWLock* rw;
	if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH;
	const u32 tid = GetCurrentPPUThread().GetId();

	if (!rw->wlock_check(tid)) return CELL_EDEADLK;

	if (rw->wlock_trylock(tid, true)) return CELL_OK;

	u32 counter = 0;
	const u32 max_counter = timeout ? (timeout / 1000) : 20000;
	do
	{
		if (Emu.IsStopped())
		{
			ConLog.Warning("sys_rwlock_wlock(rw_lock_id=%d, ...) aborted", rw_lock_id);
			return CELL_ETIMEDOUT;
		}
		Sleep(1);

		if (rw->wlock_trylock(tid, true)) return CELL_OK;

		if (counter++ > max_counter)
		{
			if (!timeout) 
			{
				counter = 0;
			}
			else
			{
				return CELL_ETIMEDOUT;
			}
		}		
	} while (true);
}
Example #29
0
s32 sys_rwlock_wlock(u32 rw_lock_id, u64 timeout)
{
	sys_rwlock.Log("sys_rwlock_wlock(rw_lock_id=%d, timeout=%lld)", rw_lock_id, timeout);

	RWLock* rw;
	if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH;
	const u32 tid = GetCurrentPPUThread().GetId();

	if (!rw->wlock_check(tid)) return CELL_EDEADLK;

	if (rw->wlock_trylock(tid, true)) return CELL_OK;

	u32 counter = 0;
	const u32 max_counter = timeout ? (timeout / 1000) : 20000;
	do
	{
		if (Emu.IsStopped())
		{
			LOG_WARNING(HLE, "sys_rwlock_wlock(rw_lock_id=%d, ...) aborted", rw_lock_id);
			return CELL_ETIMEDOUT;
		}
		std::this_thread::sleep_for(std::chrono::milliseconds(1));

		if (rw->wlock_trylock(tid, true)) return CELL_OK;

		if (counter++ > max_counter)
		{
			if (!timeout) 
			{
				counter = 0;
			}
			else
			{
				return CELL_ETIMEDOUT;
			}
		}		
	} while (true);
}
Example #30
0
void* escritor(void * arg){
	//++++++++++++++++++++++++++++BARRERA
	pthread_mutex_lock(&mut);
	while(!todos_creados){
		pthread_cond_wait(&barrera, &mut);
		}
	pthread_mutex_unlock(&mut);
	//++++++++++++++++++++++++++++
	lock_valor.wlock();
	
	int yo = (int)(long)arg;
	printf("mi tid---->%d Cambio valor\n", yo);
	valor++;
	
	
	nanosleep(&timW, NULL);
	lock_valor.wunlock();
			
	
	
	pthread_exit(NULL);
	return NULL;
}