Exemple #1
0
Looper::Looper( const char *name, int port )
: Thread( name ), m_port(port)
{
   SetAutoDelete( true );

   int ok = smk_create_port( m_port, tid() );

   if ( ok != 0 ) 
   {
   	ok = smk_new_port( tid() );
	m_port = ok;
   }
   
}
/*--------------------------------------------------
 * Stops the thread
 *-------------------------------------------------*/
PMThread& PMThread::stop()
{
  if( is_alive() && tid() != -1 )
  {
    APIRET rc = DosKillThread( tid());

    if( rc != NO_ERROR && rc != ERROR_INVALID_THREADID )
      PM_THROW_OS2ERROR(rc);

    run_alive = FALSE;
    run_id    = -1;
  }
  return *this;
}
Exemple #3
0
/** When constructing a Looper using this constructor, you can specify
 * which IPC port the Looper should listen to. If it is unable to 
 * acquire the specified port, then the first available port is used
 * instead.
 *
 * During construction, the auto-delete feature of the derived Thread
 * class is set to true.
 *
 * The default name for a Looper Thread is "_looper".
 */
Looper::Looper( int port )
: Thread( "_looper" ), m_port(port)
{
   SetAutoDelete( true );
  
   int ok = smk_create_port( m_port, tid() );

   if ( ok != 0 ) 
   {
   	ok = smk_new_port( tid() );
	m_port = ok;
   }

}
Exemple #4
0
void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp, bool is_old)
{
	// replace % to %% to not interfere with chat color codes
	std::string smessage = message;
	utils::text::replace_all(&smessage, "%", "%%");

	ptrT tid(mir_a2t(id));
	ptrT tnick(mir_a2t_cp(name, CP_UTF8));
	ptrT ttext(mir_a2t_cp(smessage.c_str(), CP_UTF8));
	ptrT tchat_id(mir_a2t(chat_id));

	GCDEST gcd = { m_szModuleName, tchat_id, GC_EVENT_MESSAGE };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.ptszText = ttext;
	gce.time = timestamp ? timestamp : ::time(NULL);
	if (id != NULL)
		gce.bIsMe = !mir_strcmp(id, facy.self_.user_id.c_str());
	gce.dwFlags |= GCEF_ADDTOLOG;
	if (is_old) {
		gce.dwFlags |= GCEF_NOTNOTIFY;
		gce.dwFlags &= ~GCEF_ADDTOLOG;
	}
	gce.ptszNick = tnick;
	gce.ptszUID = tid;
	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));

	facy.erase_reader(ChatIDToHContact(chat_id));
}
Exemple #5
0
void FacebookProto::AddChatContact(const char *chat_id, const char *id, const char *name)
{
	if (IsChatContact(chat_id, id))
		return;

	ptrT tchat_id(mir_a2t(chat_id));
	ptrT tnick(mir_a2t_cp(name, CP_UTF8));
	ptrT tid(mir_a2t(id));

	GCDEST gcd = { m_szModuleName, tchat_id, GC_EVENT_JOIN };
	GCEVENT gce = { sizeof(gce), &gcd };
	gce.pDest = &gcd;
	gce.dwFlags = GCEF_ADDTOLOG;
	gce.ptszNick = tnick;
	gce.ptszUID = tid;
	gce.time = ::time(NULL);
	gce.bIsMe = !mir_strcmp(id, facy.self_.user_id.c_str());

	if (gce.bIsMe) {
		gce.ptszStatus = TranslateT("Myself");
	}
	else {
		MCONTACT hContact = ContactIDToHContact(id);
		if (hContact == NULL || getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE) != CONTACT_FRIEND)
			gce.ptszStatus = TranslateT("User");
		else {
			gce.ptszStatus = TranslateT("Friend");
		}
	}

	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
}
PingResult TransportObjectFactory::ping(
    TcpTransport& tcpTransport)
{
    Topology tid(-1);
    PingOperation po(codec, tid, tcpTransport);
    return po.execute();
}
PingResult TransportObjectFactory::ping(
    TcpTransport& tcpTransport)
{
	IntWrapper tid(std::numeric_limits<uint32_t>::max());
    PingOperation po(codec, tid, tcpTransport);
    return po.execute();
}
Exemple #8
0
int TCPSocket::send(const char* data, std::size_t len, const net::Address& /* peerAddress */, int /* flags */) 
{
    //assert(len <= net::MAX_TCP_PACKET_SIZE); // libuv handles this for us
    
    TraceLS(this) << "Send: " << len << endl;    
    assert(Thread::currentID() == tid());
    
#if 0
    if (len < 300)
        TraceLS(this) << "Send: " << len << ": " << std::string(data, len) << endl;
    else {
        std::string str(data, len);
        TraceLS(this) << "Send: START: " << len << ": " << str.substr(0, 100) << endl;
        TraceLS(this) << "Send: END: " << len << ": " << str.substr(str.length() - 100, str.length()) << endl;
    }
#endif

    if (!Stream::write(data, len)) {
        WarnL << "Send error" << endl;    
        return -1;
    }

    // R is -1 on error, otherwise return len
    // TODO: Return native error code?
    return len;
}
Exemple #9
0
inline typename boost::enable_if<boost::mpl::and_<is_array<T>, boost::is_same<typename T::value_type, char const*> >, void>::type
write_attribute(H5::H5Object const& object, std::string const& name, T const& value)
{
    enum { size = T::static_size };

    hsize_t dim[1] = { size };
    H5::DataSpace ds(1, dim);
    size_t max_len = 0;
    for (size_t i = 0; i < size; ++i) {
        max_len = std::max(max_len, strlen(value[i]));
    }
    H5::StrType tid(H5::PredType::C_S1, max_len);
    // remove attribute if it exists
    try {
        H5XX_NO_AUTO_PRINT(H5::AttributeIException);
        object.removeAttr(name);
    }
    catch (H5::AttributeIException const&) {}
    H5::Attribute attr = object.createAttribute(name, tid, ds);
    std::vector<char> data(max_len * size);
    for (size_t i = 0; i < size; ++i) {
        strncpy(&*data.begin() + i * max_len, value[i], max_len);
    }
    attr.write(tid, &*data.begin());
}
Exemple #10
0
/*
Set the threads Id in the library vector
parameters: none
return: none
*/
void mai_set_thread_id_posix()
{
  pthread_mutex_lock(&(mai_mutex)); 
  thread_id[nThreads] = tid();
  nThreads++; 
  pthread_mutex_unlock(&(mai_mutex)); 
}
Exemple #11
0
list<tIndexDist> ClsTopologySparse::getCellsForArborization(double fXCenter, double fYCenter, ClsBaseArborization *clsBaseArborization) {
#ifdef DEBUG_CLSTOPOLOGYSPARSE
    cout << "ClsTopologySparse::getCellsForArborization(double fXCenter, double fYCenter, ClsBaseArborization *clsBaseArborization)" << endl;
#endif
    list<tIndexDist> lst;
    list<pair<int, int> > lstPointsLocal;

    lstPointsLocal = ClsBaseTopology::getCellsForArborizationRect(fXCenter, fYCenter, clsBaseArborization);

    /* calculate distance */
    int iGroupHeight = 0;
    list<tiPoint >::iterator it;
    for(it=lstPoints.begin(); it!=lstPoints.end();it++){
	int iY = (*it).second;
	iGroupHeight = (iY > iGroupHeight ? iY : iGroupHeight);
    }

    for(it=lstPointsLocal.begin();it!=lstPointsLocal.end();it++){
	int iX = (*it).first;
	int iY = (*it).second;
	/* only use points within the group boundaries */
	if(isValidCell(iX, iY) && iX>0 && iX<=iGroupWidth && iY>0 && iY<=iGroupHeight){
	    double fDist = calculateDistance(fXCenter, fYCenter, iX, iY);
	    int iIndex = pos2index(iX, iY);
	    tIndexDist tid(iIndex, fDist);
	    lst.push_back(tid);
	}
    }
    return lst;
}
Exemple #12
0
inline typename boost::enable_if<boost::mpl::and_<
    is_vector<T>
  , boost::is_same<typename T::value_type, std::string>
>, void>::type
write_attribute(H5::H5Object const& object, std::string const& name, T const& value)
{
    size_t size = value.size();

    // size of longest string
    size_t str_len = 0;
    for (size_t i = 0; i < size; ++i) {
        str_len = std::max(str_len, value[i].size());
    }

    // remove attribute if it exists and re-create with proper String datatype
    // and simple dataspace
    if (exists_attribute(object, name)) {
        object.removeAttr(name);
    }

    hsize_t dim[1] = { size };
    H5::DataSpace ds(1, dim);
    H5::StrType tid(H5::PredType::C_S1, str_len);
    H5::Attribute attr = object.createAttribute(name, tid, ds);

    // copy strings to contiguous buffer
    std::vector<char> buffer(size * str_len);
    for (size_t i = 0; i < size; ++i) {
        value[i].copy(buffer.data() + i * str_len, str_len);
    }

    attr.write(tid, &*buffer.begin());
}
Exemple #13
0
QString Fingering::accessibleInfo() const
      {
      QString rez = Element::accessibleInfo();
      if (tid() == Tid::STRING_NUMBER)
            rez += " " + QObject::tr("String number");
      return QString("%1: %2").arg(rez).arg(plainText());
      }
Exemple #14
0
/** popper **/
void popper() {
   int count;
   char *word;
   int myid;

   /* Hokie and unreliable way to generate a unique id between 0 and 9 */
   tsnooze(1);
   for (myid=0; myid<10; myid++) {
       if (tid() == id[myid]) break;
   }
   assert(myid < 10);

   /* Pop data from the stack */
   parm[myid].popcount = 0;
   for (count=0; count<parm[myid].numWords; count++) {
      word=pop(parm[myid].stack);
      /* Count number of successful pops */
      if (word != NULL) {
         free(word);
         parm[myid].popcount++;
      }
   }

   printf("Popper Thread %d done\n", myid);
   texit();
}
Exemple #15
0
/*
Set the threads OMP Id in the library vector
parameters: none
return: none
*/
void set_thread_id_omp()
{
  pthread_mutex_lock(&(mai_mutex)); 
  thread_id[omp_get_thread_num()] = tid();
  nThreads++;
  pthread_mutex_unlock(&(mai_mutex)); 
}
Exemple #16
0
void CSkypeProto::RemoveChatContact(const TCHAR *tchat_id, const char *id, const char *name, bool isKick, const char *initiator)
{
	if (IsMe(id))
		return;

	ptrT tnick(mir_a2t_cp(name, CP_UTF8));
	ptrT tid(mir_a2t(id));
	ptrT tinitiator(mir_a2t(initiator));

	GCDEST gcd = { m_szModuleName, tchat_id, isKick ? GC_EVENT_KICK : GC_EVENT_PART };
	GCEVENT gce = { sizeof(gce), &gcd };
	if (isKick)
	{
		gce.ptszUID = tid;
		gce.ptszNick = tnick;
		gce.ptszStatus = tinitiator;
		gce.time = time(NULL);
	}
	else
	{
		gce.dwFlags = GCEF_ADDTOLOG;
		gce.ptszNick = tnick;
		gce.ptszUID = tid;
		gce.time = time(NULL);
		gce.bIsMe = IsMe(id);
	}

	CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
}
Exemple #17
0
/** "idle"  thread code 
    This thread initiated in startThreadSystem() ensures that there will
    always be something on the readyList.  This eliminates a special
    case in the dispatcher of having to deal with an empty readyList.

    The thread runs at lowest priority so that it doesn't compete with
    useful threads.
**/
void idle() {
printf("\"idle\" thread starting tid=%p\n", tid()); fflush(stdout);
   tsetrange(LEVELS-1, LEVELS-1);
   /* "Do nothing" loop just so there is always something to dispatch */
   while (1) {
      tyield();
   }
}
Exemple #18
0
ServerClient::
ServerClient(std::string i, int p):
    ip(i), port(p)
{
    /* 初始化socket */
    bzero(&server, sizeof(server));
    server.sin_family = AF_INET;
    server.sin_port = htons(port);
    inet_pton(AF_INET, ip.c_str(), &server.sin_addr);

    loadServer_fd = socket(AF_INET, SOCK_STREAM, 0);
    if(loadServer_fd < 0)
    {
        perror("create loadServer socket fd error\n");
        exit(1);
    }
    int con_ret = connect(loadServer_fd, (struct sockaddr*)&server, sizeof(server));
    if(con_ret == -1)
    {
        perror("load Serverconnect error\n");
        exit(1);
    }

    /*  
    std::thread tid([&](){
            // 设置定时器,并初始化 
            signal(SIGALRM, signalHandler);
            new_value.it_value.tv_sec = 0;
            new_value.it_value.tv_usec = 1;
            new_value.it_interval.tv_sec = 5;
            new_value.it_interval.tv_usec = 0;
            setitimer(ITIMER_REAL, &new_value, &old_value);
            // 获得带宽信息 
            while(1);
        }
    );
    */
    char buffer[16];
    std::thread tid([&](){
                while(1)
                {
                    std::string getinfo;
                    recv(loadServer_fd, buffer, 16, 0);
                    getinfo += info.getInfo(cpuInfo);
                    getinfo += "\0\n";
                    getinfo += info.getInfo(memInfo);
                    getinfo += "\0\n";
                    getinfo += info.getInfo(netInfo);
                    getinfo += "\0\n";
                    getinfo += info.getInfo(diskInfo);
                    getinfo += "\0\n";
                    std::cout << getinfo << std::endl;
                    send(loadServer_fd, getinfo.c_str(), getinfo.size(), 0);
                    //sleep(4);
                }
            });
    tid.detach();
}
EXPORT_C void RMemSpySession::GetProcessIdByThreadId( TProcessId& aPID, TThreadId aTID )
	{	
	TPckgBuf<TProcessId> pid(aPID);
	TPckgBuf<TThreadId> tid(aTID);
	
	TIpcArgs args( &pid, &tid );
	User::LeaveIfError( SendReceive( EMemSpyClientServerOpGetProcessIdByThreadId, args ) );
	aPID = pid();
	}
Exemple #20
0
bool Resource::query(const Resource::Id& id, Resource* outThumb) {
	const bool		ans = query(id);
	if (ans && mThumbnailId > 0 && outThumb) {
		ds::Resource::Id	tid(mDbId);
		tid.mValue = mThumbnailId;
		outThumb->query(tid);
	}
	return ans;
}
Exemple #21
0
void* generic_adapter::get(std::type_info const& ti)
{
    type_info_wrapper tid(ti);
    adapter_map_t::const_iterator i = adapters.find(tid);
    if( i == adapters.end() ) 
        return 0;
    else
        return i->second;
}
Exemple #22
0
ElementType Fingering::layoutType()
      {
      switch (tid()) {
            case Tid::FINGERING:
            case Tid::RH_GUITAR_FINGERING:
            case Tid::STRING_NUMBER:
                  return ElementType::CHORD;
            default:
                  return ElementType::NOTE;
            }
      }
/*--------------------------------------------------
 * Wraps initialized GUI
 *--------------------------------------------------*/
PMGUI::PMGUI( HAB hab )
{
  TID cur_tid = tid();

  if( cur_tid > PM_MAX_THREADS )
    PM_THROW_ERROR( 0, "Too many threads" );

  gui_hab[cur_tid] = hab;
  gui_hmq[cur_tid] = HMQ_CURRENT;
  gui_wrapped      = TRUE;
}
Exemple #24
0
void kill_cli(int epfd, struct fdinfo *fdinfo) {
	char buf[100];
	int fd = fdinfo->fd;
	free(fdinfo);

	inet_ntop(AF_INET, &fdinfo->sin.sin_addr, buf, sizeof fdinfo->sin);

	printf("%i: Chau %s!\n", tid(), buf);

	epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
	close(fd);
}
Exemple #25
0
Fichier : ts.c Projet : liuhuac/OS
/* sub4: this thread also voluntarily releases the CPU with a
   tyield() call.
*/
void sub4() {
  int delay;
  while (tactive() > 2) {
      printf("sub4: tid=%p\n", tid());
      for (delay=0; delay<5000000; delay++) /*Do nothing delay loop */;
      for (delay=0; delay<5000000; delay++) /*Do nothing delay loop */;
      for (delay=0; delay<5000000; delay++) /*Do nothing delay loop */;
      for (delay=0; delay<5000000; delay++) /*Do nothing delay loop */;
      tyield();
  }
  printf(">>>sub 4 ending\n");
  texit();
}
/*--------------------------------------------------
 * Terminates GUI
 *--------------------------------------------------*/
PMGUI::~PMGUI()
{
  TID cur_tid = tid();

  if( !gui_wrapped )
  {
    if( gui_hmq[cur_tid] ) WinDestroyMsgQueue( gui_hmq[cur_tid] );
    if( gui_hab[cur_tid] ) WinTerminate      ( gui_hab[cur_tid] );

    gui_hab[cur_tid] = NULLHANDLE;
    gui_hmq[cur_tid] = NULLHANDLE;
  }
}
Exemple #27
0
inline typename boost::enable_if<boost::is_same<T, char const*>, void>::type
write_attribute(H5::H5Object const& object, std::string const& name, T value)
{
    H5::StrType tid(H5::PredType::C_S1, strlen(value));
    // remove attribute if it exists
    try {
        H5XX_NO_AUTO_PRINT(H5::AttributeIException);
        object.removeAttr(name);
    }
    catch (H5::AttributeIException const&) {}
    H5::Attribute attr = object.createAttribute(name, tid, H5S_SCALAR);
    attr.write(tid, value);
}
int main(int argc, char** argv)
{
  int i;
  const int n_threads = 10;
  std::vector<QThread*> tid(n_threads);

  s_iterations = argc > 1 ? atoi(argv[1]) : 1000;

  fprintf(stderr, "Start of test.\n");

  {
    // Stack-allocated mutex.
    QMutex M(QMutex::Recursive);
    M.lock();
    assert(M.tryLock());
    M.unlock();
    M.unlock();
  }
#if defined(HAVE_QTCORE_QMUTEX_TRYLOCK_INT)
  {
    QMutex M(QMutex::NonRecursive);
    assert(M.tryLock(1));
    assert(! M.tryLock(1));
    M.unlock();
  }
#endif

  pthread_barrier_init(&s_barrier, 0, n_threads);
  s_pMutex = new QMutex();
  for (i = 0; i < n_threads; i++)
  {
    tid[i] = new IncThread;
    tid[i]->start();
  }
  for (i = 0; i < n_threads; i++)
  {
    tid[i]->wait();
    delete tid[i];
  }
  delete s_pMutex;
  s_pMutex = 0;
  pthread_barrier_destroy(&s_barrier);

  if (s_counter == n_threads * s_iterations)
    fprintf(stderr, "Test successful.\n");
  else
    fprintf(stderr, "Test failed: counter = %d, should be %d\n",
            s_counter, n_threads * s_iterations);

  return 0;
}
std::vector<TileID> AnnotationManager::removeAnnotations(const AnnotationIDs& ids,
                                                         const MapData& data) {
    std::lock_guard<std::mutex> lock(mtx);

    std::vector<TileID> affectedTiles;

    std::vector<uint32_t> z2s;
    const uint8_t zoomCount = data.transform.getMaxZoom() + 1;
    z2s.reserve(zoomCount);
    for (uint8_t z = 0; z < zoomCount; ++z) {
        z2s.emplace_back(1<< z);
    }

    LatLng latLng;
    vec2<double> p;
    uint32_t x, y;

    // iterate annotation id's passed
    for (const auto& annotationID : ids) {
        // grab annotation object
        const auto& annotation_it = annotations.find(annotationID);
        if (annotation_it != annotations.end()) {
            const auto& annotation = annotation_it->second;
            // calculate annotation's affected tile for each zoom
            for (uint8_t z = 0; z < zoomCount; ++z) {
                latLng = annotation->getPoint();
                p = projectPoint(latLng);
                x = z2s[z] * p.x;
                y = z2s[z] * p.y;
                TileID tid(z, x, y, z);
                // erase annotation from tile's list
                auto& tileAnnotations = tiles[tid].first;
                tileAnnotations.erase(annotationID);
                // remove annotation's features from tile
                const auto& features_it = annotation->tileFeatures.find(tid);
                if (features_it != annotation->tileFeatures.end()) {
                    const auto& layer =
                        tiles[tid].second->getMutableLayer(layerID);
                    layer->removeFeature(features_it->second);
                    affectedTiles.push_back(tid);
                }
            }
            annotations.erase(annotationID);
        }
    }

    // TileIDs for tiles that need refreshed.
    return affectedTiles;
}
Exemple #30
0
bool Runner::waitForExit(int timeout)
{
    assert(Thread::currentID() != tid());
    int times = 0;
    int interval = 10;
    while (!cancelled() || running()) {
        scy::sleep(interval);
        times++;
        if (timeout && ((times * interval) > timeout)) {
            assert(0 && "deadlock; calling inside thread scope?");
            return false;
        }
    }
    return true;
}