Пример #1
0
void Memory::lock(MemoryLockType lock_type) {
    Lock &lock = getLock(lock_type);
    lock.lock();
}
Пример #2
0
void CompactIndex::addPostings(const char *term, byte *postings, int byteLength,
		int count, offset first, offset last) {
	assert(!readOnly);
	assert((count > 0) && (last >= first) && (term[0] != 0));

	// sorry; we do not allow any term that is right of the guardian term
	if (strcmp(term, (char*)CI_GUARDIAN) >= 0)
		return;

	// if we receive more postings than we can put into a list segment without
	// violating the MIN_SEGMENT_SIZE/MAX_SEGMENT_SIZE constraint, we need to
	// split the list into sub-lists of manageable size: decompress and pass
	// to the method that deals with uncompressed lists
	if ((count > MAX_SEGMENT_SIZE) ||
	    (extractCompressionModeFromList(postings) != indexCompressionMode)) {		
		int listLengthFromCompressor;
		offset *uncompressed =
			decompressList(postings, byteLength, &listLengthFromCompressor, NULL);
		assert(listLengthFromCompressor == count);
		addPostings(term, uncompressed, count);
		free(uncompressed);
		return;
	}

	bool mustReleaseLock = getLock();

	// check if the terms come in pre-sorted
	int comparison = strcmp(term, lastTermAdded);
	assert(comparison >= 0);
	if ((comparison != 0) || (tempSegmentCount == MAX_SEGMENTS_IN_MEMORY))
		copySegmentsToWriteCache();
	strcpy(lastTermAdded, term);
#if INDEX_MUST_BE_WORD_ALIGNED
	// pad the compressed postings in order to make everything word-aligned
	if (byteLength & 7)
		byteLength += 8 - (byteLength & 7);
#endif

	tempSegmentHeaders[tempSegmentCount].postingCount = count;
	tempSegmentHeaders[tempSegmentCount].byteLength = byteLength;
	tempSegmentHeaders[tempSegmentCount].firstElement = first;
	tempSegmentHeaders[tempSegmentCount].lastElement = last;
	tempSegmentData[tempSegmentCount++] =
		(byte*)memcpy((byte*)malloc(byteLength), postings, byteLength);
	totalSizeOfTempSegments += byteLength + sizeof(PostingListSegmentHeader);

	// make sure the current index block does not get too large; if it does,
	// insert new descriptor (in-memory dictionary entry)
	long long anticipatedFilePos =
		bytesWrittenToFile + cacheBytesUsed + tempSegmentCount * sizeof(PostingListSegmentHeader) + 64;
	if (anticipatedFilePos > startPosOfLastBlock + BYTES_PER_INDEX_BLOCK)
		if (comparison != 0)
			addDescriptor(term);

	// update member variables
	header.listCount++;
	if (comparison != 0)
		header.termCount++;
	header.postingCount += count;

	if (mustReleaseLock)
		releaseLock();
} // end of addPostings(char*, byte*, int, int, offset, offset)
Пример #3
0
void processData()
{
  std::unique_lock<std::mutex> lk(getLock());
  doSomething();
}
Пример #4
0
void KFontProperties::clearGlobalFontProperties() {
  auto lock = getLock();
  fontList.clear();
}
Пример #5
0
int main(int argc, char **argv)
{
  std::string file = "/dev/controller_sensor";
  UInt32 baudrate = 115200;
  SerialInterface usb("/dev/controller_sensor", baudrate);


  if (argc > 1)
  {
    file = argv[1];
    printf("%s info: Opening %s\n", argv[0], file.c_str());
  }

  if (pthread_mutex_init(&myMutex, NULL) != 0)
  {
    printf("Failed to get mutex: %s\n", strerror(errno));
    exit(-1);
  }

  name = argv[0];

  float temp[3] = {0.0};
  float pressure = 0.0;
  int motorKilled = 0, waterDetected, dropperLeft= 0, dropperRight= 0;
  float curVolt[2] = {0.0};
  int numVariables = 10;

  float ttemp[3] = {0.0};
  float tpressure = 0.0;
  int tmotorKilled = 0, twaterDetected= 0, tdropperLeft= 0, tdropperRight= 0;
  float tcurVolt[2] = {0.0};

  timer tempTimer, pressureTimer, motorTimer, currentTimer, waterTimer, dropperTimer;

  tempTimer.start(1, 0);
  pressureTimer.start(1, 0);
  motorTimer.start(1, 0);
  currentTimer.start(1, 0);
  waterTimer.start(1, 0);
  dropperTimer.start(1, 0);

  ros::init(argc, argv, "SubSensorController");
  ros::NodeHandle nh;

  ros::Publisher temperatuerPub = nh.advertise<std_msgs::Float32MultiArray>("Controller_Box_Temp", 1000);
  ros::Publisher pressurePub = nh.advertise<std_msgs::Float32>("Pressure_Data", 1000);
  ros::Publisher MotorPub = nh.advertise<std_msgs::UInt8>("Motor_State", 1000);
  ros::Publisher computerPub = nh.advertise<std_msgs::Float32MultiArray>("Computer_Cur_Volt", 1000);
  ros::Publisher waterPub = nh.advertise<std_msgs::UInt8>("Water_Detected", 1000);
  ros::Publisher dropperPub = nh.advertise<std_msgs::UInt8MultiArray>("Dropper_States", 1000);

  ros::Subscriber torpedoSub = nh.subscribe("Torpedo_Launch", 1000, torpedoCallback);
  ros::Subscriber dropperSub = nh.subscribe("Dropper_Activate", 1000, dropperCallback);

  ros::Rate loop_rate(1);

  while (ros::ok())
  {
    if (controllerState == STATE_WAITING_ON_FD)
    {
      if (checkLock() && getLock())
      {
        controllerState = STATE_WORKING;
        sleep(5);
        
        //fd = open(file.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
        // if (fd == -1)
        // {
        //   printf("%s Error: System failed to open %s: %s(%d)\n", argv[0], file.c_str(), strerror(errno), errno);
        //   sleep(1);
        // }
        // else
        // {
        //   if (setupTTY(fd) == 0) 
        //   {
        //     controllerState = STATE_WORKING;

        //     sleep(5); //wait for sensor to boot and stabilize
        //   }
        //   else
        //     close(fd);
        // }
        releaseLock();
      }
    }
    else if (controllerState == STATE_WORKING)
    {
      std::string line = "";
      if (checkLock() && getLock())
      {
        UInt8 aBuf[baudrate];
        usb.recv(aBuf,baudrate);
        std::string temp ((const char*)aBuf,baudrate);
        line = temp;
        //line = getTTYLine(fd);
        //printf("got line %s\n", line.c_str());
        releaseLock();
      }

      if (line != "")
      {
        //printf("line: %s\n", line.c_str());
        if (line.length() > 0 && goodLine(line, numVariables))
        {
          int scanfVal;

          if ((scanfVal = sscanf(line.c_str(), "S%f,%f,%f,%d,%f,%f,%f,%d,%d,%dE", &ttemp[0], &ttemp[1], &ttemp[2], &tmotorKilled,
              &tcurVolt[0], &tcurVolt[1], &tpressure, &twaterDetected, &tdropperLeft, &tdropperRight)) == numVariables)
          {
            if ((temp[0] != ttemp[0]) || (temp[1] != ttemp[1]) || (temp[2] != ttemp[2]) || tempTimer.isTimeout())
            {
              //temperature
              std_msgs::Float32MultiArray tempMsg;
              temp[0] = ttemp[0];
              temp[1] = ttemp[1];
              temp[2] = ttemp[2];
              tempMsg.data.push_back(temp[0]);
              tempMsg.data.push_back(temp[1]);
              tempMsg.data.push_back(temp[2]);
              temperatuerPub.publish(tempMsg);
              tempTimer.start(1, 0);
              ros::spinOnce();
            }

            if (motorKilled != tmotorKilled || motorTimer.isTimeout())
            {
              //motorkilled
              std_msgs::UInt8 motorMsg;
              motorKilled = tmotorKilled;
              motorMsg.data = motorKilled;
              MotorPub.publish(motorMsg);
              motorTimer.start(1, 0);
              ros::spinOnce();
            }

            if ((curVolt[0] != tcurVolt[0]) || (curVolt[1] != tcurVolt[1] || currentTimer.isTimeout()))
            {
              //curvolt
              std_msgs::Float32MultiArray curMsg;
              curVolt[0] = tcurVolt[0];
              curVolt[1] = tcurVolt[1];
              curMsg.data.push_back(curVolt[0]);
              curMsg.data.push_back(curVolt[1]);
              computerPub.publish(curMsg);
              currentTimer.start(1, 0);
              ros::spinOnce();
            }

            if (pressure != tpressure || pressureTimer.isTimeout())
            {
              //depth
              std_msgs::Float32 pressureMsg;
              pressure = tpressure;
              pressureMsg.data = pressure;
              pressurePub.publish(pressureMsg);
              pressureTimer.start(1, 0);
              ros::spinOnce();
            }

            if (waterDetected != twaterDetected || waterTimer.isTimeout())
            {
              //water detected
              std_msgs::UInt8 waterMsg;
              waterDetected = twaterDetected;
              waterMsg.data = waterDetected;
              waterPub.publish(waterMsg);
              waterTimer.start(1, 0);
              ros::spinOnce();
            }

            if (tdropperLeft != dropperLeft || tdropperRight != dropperRight || dropperTimer.isTimeout())
            {
              //water detected
              std_msgs::UInt8MultiArray dropperMsg;
              dropperLeft = tdropperLeft;
              dropperRight = tdropperRight;
              dropperMsg.data.push_back(dropperLeft);
              dropperMsg.data.push_back(dropperRight);
              dropperPub.publish(dropperMsg);
              dropperTimer.start(1, 0);
              ros::spinOnce();
            }

            if (VERBOSE)
              ROS_INFO("published");
          }
          else
          {
            printf("%s info: Throwing away %d:\"%s\"\n", argv[0], scanfVal, line.c_str());
            fflush(stdout);
          }
        }
      }
    }
  }

  pthread_mutex_destroy(&myMutex);
  close(fd);
  return 0;
}
Пример #6
0
HRESULT IDirect3DVertexBuffer9Managed::Lock(UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags)
{
  dbgf("IDirect3DVertexBuffer9Managed 0x%08X: lock: off %d, %d bytes, %s", this, OffsetToLock, SizeToLock, getLock(Flags));

  if(OffsetToLock+SizeToLock > bufSize)
    dbg("WARNING: Application attempted to lock too large vertexbuffer (%d > %d)", OffsetToLock+SizeToLock, bufSize);

  if(!bufSys || !buf)
    return D3DERR_INVALIDCALL;
  // Return handle to system memory buffer
  *ppbData = bufSys+OffsetToLock;

#ifdef RECREATE_ON_REUSE
  if(!fullDirty && lockSections.size() == 0)
  {
    // First lock
    if(ReCreate())
    {
      fullDirty = true;
    }
    //fullDirty = true;
  }
#endif

  if((OffsetToLock == 0 && SizeToLock == 0) || (OffsetToLock == 0 && SizeToLock == bufSize))
  {
    // Whole VB locked
    fullDirty = true;
  }
  else
  {
    LOCKSECTION l; // Dirty sections
    l.lockOffset = OffsetToLock;
    l.lockSize = SizeToLock;
    lockSections.push_back(l);
  }

  locks++;
  return D3D_OK;
}