PAPIConnection* allocConnection( PAPIConnectionListener	inConnectionListener,
								 void *					inUserData,
								 PAPIListener			inInternalListener,
								 void *					inInternalListenerData,
								 PAPISocket				inSocket,
								 PAPIStatus *			outStatus  )
{
	PAPIConnection * theConnection =
		( PAPIConnection * )malloc( sizeof( PAPIConnection ) );
	if ( theConnection != 0 )
	{
		theConnection->mFD						= inSocket;
		theConnection->mFDPollTimeout			= getTransactionTimeout();
		theConnection->mListeners				= 0;
		theConnection->mSavedMessage			= 0;
		theConnection->mListenerThreadStatus	= NOT_RUNNING;
		theConnection->mConnectionListener		= inConnectionListener;
		theConnection->mUserData				= inUserData;
		theConnection->mListenersMutex			= newMutex();
		theConnection->mSavedMessageMutex		= newMutex();
		theConnection->mListenerThreadStatusMutex= newMutex();
		theConnection->mConnectionStateChangeMutex= newMutex();
		theConnection->mInternalListener		= inInternalListener;
		theConnection->mInternalListenerData	= inInternalListenerData;
		theConnection->mAuthHandler				= 0;
		theConnection->mAuthHandlerUserData		=
			( PAPIAuthHandlerData * )malloc( sizeof( PAPIAuthHandlerData ) );
		*outStatus = PAPISuccess;
	}
	else
	{
		*outStatus = PAPIOutOfMemoryFailure;
	}
	return theConnection;
}
Exemplo n.º 2
0
Channel::Channel()
	: named(false)
	, sent(0)
	, received(0)
{
	mutex = newMutex();
	cond = newConditional();
}
Exemplo n.º 3
0
Channel::Channel(const std::string &name)
	: named(true)
	, name(name)
	, sent(0)
	, received(0)
{
	mutex = newMutex();
	cond = newConditional();
}
ArchCond
ArchMultithreadWindows::newCondVar()
{
    ArchCondImpl* cond                       = new ArchCondImpl;
    cond->m_events[ArchCondImpl::kSignal]    = CreateEvent(NULL,
                                                    FALSE, FALSE, NULL);
    cond->m_events[ArchCondImpl::kBroadcast] = CreateEvent(NULL,
                                                    TRUE,  FALSE, NULL);
    cond->m_waitCountMutex                    = newMutex();
    cond->m_waitCount                         = 0;
    return cond;
}
Exemplo n.º 5
0
Channel *Channel::getChannel(const std::string &name)
{
	if (!namedChannelMutex)
		namedChannelMutex = newMutex();

	Lock l(namedChannelMutex);
	if (!namedChannels.count(name))
		namedChannels[name] = new Channel(name);
	else
		namedChannels[name]->retain();

	return namedChannels[name];
}
Exemplo n.º 6
0
ArchMultithreadPosix::ArchMultithreadPosix() :
	m_newThreadCalled(false),
	m_nextID(0)
{
	assert(s_instance == NULL);

	s_instance = this;

	// no signal handlers
	for (size_t i = 0; i < kNUM_SIGNALS; ++i) {
		m_signalFunc[i]     = NULL;
		m_signalUserData[i] = NULL;
	}

	// create mutex for thread list
	m_threadMutex = newMutex();

	// create thread for calling (main) thread and add it to our
	// list.  no need to lock the mutex since we're the only thread.
	m_mainThread           = new ArchThreadImpl;
	m_mainThread->m_thread = pthread_self();
	insert(m_mainThread);

	// install SIGWAKEUP handler.  this causes SIGWAKEUP to interrupt
	// system calls.  we use that when cancelling a thread to force it
	// to wake up immediately if it's blocked in a system call.  we
	// won't need this until another thread is created but it's fine
	// to install it now.
	struct sigaction act;
	sigemptyset(&act.sa_mask);
# if defined(SA_INTERRUPT)
	act.sa_flags   = SA_INTERRUPT;
# else
	act.sa_flags   = 0;
# endif
	act.sa_handler = &threadCancel;
	sigaction(SIGWAKEUP, &act, NULL);

	// set desired signal dispositions.  let SIGWAKEUP through but
	// ignore SIGPIPE (we'll handle EPIPE).
	sigset_t sigset;
	sigemptyset(&sigset);
	sigaddset(&sigset, SIGWAKEUP);
	pthread_sigmask(SIG_UNBLOCK, &sigset, NULL);
	sigemptyset(&sigset);
	sigaddset(&sigset, SIGPIPE);
	pthread_sigmask(SIG_BLOCK, &sigset, NULL);
}
ArchMultithreadWindows::ArchMultithreadWindows()
{
    assert(s_instance == NULL);
    s_instance = this;

    // no signal handlers
    for (size_t i = 0; i < kNUM_SIGNALS; ++i) {
        m_signalFunc[i]     = NULL;
        m_signalUserData[i] = NULL;
    }

    // create mutex for thread list
    m_threadMutex = newMutex();

    // create thread for calling (main) thread and add it to our
    // list.  no need to lock the mutex since we're the only thread.
    m_mainThread           = new ArchThreadImpl;
    m_mainThread->m_thread = NULL;
    m_mainThread->m_id     = GetCurrentThreadId();
    insert(m_mainThread);
}