Example #1
0
void CRWMutex::lockRead()
{
#ifndef ANDROID
   pthread_rwlock_rdlock(&mMutex);
#else
   reader_lock(&mMutex);
#endif //ANDROID
}
Example #2
0
/* READER THREAD reads from shared memory and does some busy work */
void *Reader( void * num)
{
    time_t now;    
    int i;
    pid_t tid;
    tid = syscall(SYS_gettid);      
    time(&now);  /* grabs system time and stuff it into struct time_t now*/ 
    if (DEBUG)
        fprintf(stderr,"create reader thread pid: %d tid: %d  %s\n",getpid(), tid,
                ctime(&now));

    fib(5);   /* do some busy work */ 

    /* reader thread simply reads three times */
    for (i=1; i<= 3; i++){
        fib(24);   /* do some busy work */ 

        int n_writers_waiting = semctl(semid, READER, GETZCNT);

        if(!n_writers_waiting)
        {
            reader_lock(semid);
        //if(!n_writers_waiting)
        //{


            /* construct a string for the reader to spit out */
            fib(30);
            char str[5];
            char buf[80] = "reader ";
            strcat(buf,(char*)num); 
            strcat(buf," reads: "); 

            /* grab shared mem and display it */
            sprintf(str,"%d",*shared);
            strcat(buf, str); 
            strcat(buf, "\n"); 
            write(1,buf,strlen(buf)); 
            fsync(1);

            reader_unlock(semid);
        }
    }
    pthread_exit(0);
}
Example #3
0
/*  Reader function reads from shared memory */
void *Reader( void * num)
{
  int i;
  pid_t tid;
  tid = syscall(SYS_gettid);      
  printf("create reader thread pid: %d tid: %d \n",getpid(), tid);

  /* should make loop random when you have multiple threads-fixed at 3 now */
  for (i=1; i<= 3; i++){
     int zsems = semctl(semid, WRITER, GETZCNT);
     
     if(zsems > 0){
        reader_lock( semid );
        fib(20);
        printf("reader #%s  %s", (char *)num, mem_ptr); 
        reader_unlock( semid );
     }
  }
  pthread_exit(0);
}
 hsa_status_t Validate(uint32_t *result) {
   amd::hsa::common::ReaderLockGuard<amd::hsa::common::ReaderWriterLock> reader_lock(rw_lock_);
   assert(result);
   *result = 0;
   return HSA_STATUS_SUCCESS;
 }