コード例 #1
0
ファイル: test12.mutatee.c プロジェクト: vishalmistry/imitate
void *thread_main8(void *arg)
{
  /*  The mutator will patch in messaging primitives to signal events at mutex creation,
      deletion, locking and unlocking.  Thus far, we are only considering reporting of events
      so actual contention is meaningless */
  Lock_t newmutex;
  if (!createLock(&newmutex)) {
     fprintf(stderr, "%s[%d]:  createLock failed\n", __FILE__, __LINE__);
     return NULL;
  }
  sleep_ms(100);
  if (!lockLock(&newmutex)) {
     fprintf(stderr, "%s[%d]:  lockLock failed\n", __FILE__, __LINE__);
     return NULL;
  }
  sleep_ms(100);
  if (!unlockLock(&newmutex)) {
     fprintf(stderr, "%s[%d]:  unlockLock failed\n", __FILE__, __LINE__);
     return NULL;
  }
  sleep_ms(100); 
  if (!destroyLock(&newmutex)) {
     fprintf(stderr, "%s[%d]:  destroyLock failed\n", __FILE__, __LINE__);
     return NULL;
  }

  sleep(1);
  return NULL;
}
コード例 #2
0
ファイル: test12.mutatee.c プロジェクト: vishalmistry/imitate
void func6_1()
{
#if defined(os_none)
  createLock(&test6lock);
  lockLock(&test6lock); 
  assert (NULL != createThreads(TEST6_THREADS, thread_main6, test6_threads));

  unlockLock(&test6lock); 
  mutateeIdle = 1;
  while (mutateeIdle) {}
#else
#endif
}
コード例 #3
0
ファイル: test12.mutatee.c プロジェクト: vishalmistry/imitate
void *thread_main6(void *arg)
{
  int x, i;
  lockLock(&test6lock); 
  x = 0;
  for (i = 0; i < 0xf; ++i) {
    x = x + i;
  }

  unlockLock(&test6lock); 
  dprintf("%s[%d]:  %lu exiting...\n", __FILE__, __LINE__, (unsigned long) pthread_self());
  return (void *) x;
}
コード例 #4
0
ファイル: test12.mutatee.c プロジェクト: vishalmistry/imitate
void func5_1()
{
#if defined(os_none)
  createLock(&test5lock);
  lockLock(&test5lock); 
  assert (NULL != createThreads(TEST5_THREADS, thread_main5, test5_threads));

  sleep_ms(999);
  unlockLock(&test5lock); 
  mutateeIdle = 1;
  while (mutateeIdle) {}
#else
#endif
}
コード例 #5
0
void commandContainerCleanup(CommandContainer commandContainer){
	CommandContainerInternal* internal=(CommandContainerInternal*)commandContainer;
        lockLock(internal->lock);
        time_t currentTime;       // Stores seconds elapsed since 01-01-1970
        time(&currentTime);
        // Cleanup atomic commands
        if(linkedListSize(internal->atomicCommands)>0){
            int length=linkedListSize(internal->atomicCommands);
            Command atomicCommand;
            while(length>0){
                 linkedListGetFirst(internal->atomicCommands,(Object*)&atomicCommand);
                 int commandTime=commandGetInt(atomicCommand,SERVER_HANDLING_TIME);
                 int distributed=commandGetInt(atomicCommand,DISTRIBUTED);
                 if((currentTime-commandTime>MAX_TIME_TO_HOLD_COMMAND&&distributed==TRUE)||(currentTime-commandTime>MAX_TIME_TO_HOLD_UNCLEANED_COMMAND)){
                   commandFree(atomicCommand);
                   linkedListRemoveFirst(internal->atomicCommands);
                 }else{
                     break;
                 }
                 length=linkedListSize(internal->atomicCommands);
            }
        }
        
        // Cleanup commands
        int length=linkedListSize(internal->versions);
        int i;
        int* intBuffer;
        while(length>0){
            linkedListGetFirst(internal->versions,(Object*)&intBuffer);
            Command temp;
            hashmapGet(internal->versionMap,*intBuffer,(Object*)&temp);
            int commandTime=commandGetInt(temp,SERVER_HANDLING_TIME);            
            int persisted=commandGetInt(temp,PERSISTED);
            int distributed=commandGetInt(temp,DISTRIBUTED);
            if((currentTime-commandTime>MAX_TIME_TO_HOLD_COMMAND&&persisted==TRUE&&distributed==TRUE)||(currentTime-commandTime>MAX_TIME_TO_HOLD_UNCLEANED_COMMAND)){
                linkedListRemoveFirst(internal->versions);
                hashmapRemove(internal->versionMap,*intBuffer);
                memoryFree(intBuffer);
                commandFree(temp);
            }else{
                break;
            }
            length=linkedListSize(internal->versions);
        }
        lockUnlock(internal->lock);
        
        

}
コード例 #6
0
void commandContainerRevertCommand(CommandContainer commandContainer,int lastVersion){
    CommandContainerInternal* internal=(CommandContainerInternal*)commandContainer;
    lockLock(internal->lock);
    int* intBuffer=NULL;
    linkedListGetLast(internal->versions,(Object*)&intBuffer);
    while(intBuffer!=NULL&&lastVersion<=*intBuffer){
        linkedListRemoveLast(internal->versions);
        Command temp;
        hashmapGet(internal->versionMap,*intBuffer,(Object*)&temp);
        hashmapRemove(internal->versionMap,*intBuffer);
        linkedListGetLast(internal->versions,(Object*)&intBuffer);
    }
    lockUnlock(internal->lock);
   
}
コード例 #7
0
ファイル: test12.mutatee.c プロジェクト: vishalmistry/imitate
void *thread_main3(void *arg)
{
  int x, i;
  lockLock(&test3lock);
  x = 0;

  for (i = 0; i < 0xffff; ++i) {
    x = x + i;
  }
  /*fprintf(stderr, "%s[%d]:  PTHREAD_DESTROY\n", __FILE__, __LINE__); */

  unlockLock(&test3lock);
  dprintf("%s[%d]:  %lu exiting...\n", __FILE__, __LINE__, (unsigned long) pthread_self());
  return (void *) x;
}
コード例 #8
0
ファイル: test12.mutatee.c プロジェクト: vishalmistry/imitate
void func3_1()
{

  createLock(&test3lock);
  mutateeIdle = 1;

  lockLock(&test3lock);
  assert (NULL != createThreads(TEST3_THREADS, thread_main3, test3_threads));

  sleep_ms(999);
  unlockLock(&test3lock);
  dprintf("%s[%d]:  func3_1\n", __FILE__, __LINE__);
  while (mutateeIdle) {}

  dprintf("%s[%d]:  leaving func3_1\n", __FILE__, __LINE__);
}
コード例 #9
0
ファイル: commandExecuter.c プロジェクト: gidish/PlanckDB
int commandExecutorProduce(CommandExecuter commandExecuter,Command command){
    CommandExecuterInternal * internal=(CommandExecuterInternal*)commandExecuter;
    int type=commandGetInt(command,COMMAND_TYPE);
     if(IS_MODEL_COMMAND(type)==TRUE){
            //noinspection SynchronizationOnLocalVariableOrMethodParameter
            Lock lock=lockCreate();
            lockLock(lock);
            coreConsume(internal->core,command);
            int status = commandGetInt(command,COMMAND_STATUS);
            if( status=VALID){
               return status;
            }
            environmentWaitObject(command,lock);
        }else{
            coreConsume(internal->core,command);
            int status = commandGetInt(command,COMMAND_STATUS);
            if( status=VALID){
               return status;
            }
        }
    return VALID;
}
コード例 #10
0
void commandContainerPushCommand(CommandContainer commandContainer,Command command){
	CommandContainerInternal* internal=(CommandContainerInternal*)commandContainer;
        lockLock(internal->lock);
        time_t currentTime;       // Stores seconds elapsed since 01-01-1970
        time(&currentTime);
        int type=commandGetInt(command,COMMAND_TYPE);
        if(type==ATOMIC_MODEL_COMMAND){
            commandPush(command,SERVER_HANDLING_TIME,INTEGER,&currentTime);
            linkedListAddLast(internal->atomicCommands,command);
        }else{
            int version=commandGetInt(command,VERSION);
            int* intBuffer=memoryAlloc(SIZE_OF_INT);
            memcpy(intBuffer,&version,SIZE_OF_INT);
            commandPush(command,SERVER_HANDLING_TIME,INTEGER,&currentTime);
            // Update version Map;
            hashmapPut(internal->versionMap,version,command);
            // Update version list
            linkedListAddLast(internal->versions,intBuffer);
        }
        
        lockUnlock(internal->lock);
}
コード例 #11
0
ファイル: test12.mutatee.c プロジェクト: vishalmistry/imitate
void func4_1()
{
/*
#if defined(os_linux) && defined(arch_x86)
#else
*/
  dprintf("%s[%d]:  welcome to func4_1\n", __FILE__, __LINE__);
  createLock(&test4lock);


  lockLock(&test4lock); 
   
  assert (NULL != createThreads(TEST3_THREADS, thread_main4, test4_threads));

  unlockLock(&test4lock); 
  mutateeIdle = 1;
  while (mutateeIdle) {}
/*
#endif
*/

}