182 lines
4.7 KiB
C++
182 lines
4.7 KiB
C++
|
/***********************************************************************
|
||
|
*
|
||
|
* Copyright (C) 2006 Novell, Inc. All Rights Reserved.
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; version 2.1
|
||
|
* of the License.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with this library; if not, Novell, Inc.
|
||
|
*
|
||
|
* To contact Novell about this file by physical or electronic mail,
|
||
|
* you may find current contact information at www.novell.com.
|
||
|
*
|
||
|
* Author: Juan Carlos Luciani <jluciani@novell.com>
|
||
|
*
|
||
|
***********************************************************************/
|
||
|
|
||
|
|
||
|
//===[ Include files ]=====================================================
|
||
|
|
||
|
#include "ipcint.h"
|
||
|
#include "serverthread.h"
|
||
|
#include <assert.h> // Ensure that NDEBUG is defined for release builds!
|
||
|
|
||
|
//===[ External data ]=====================================================
|
||
|
|
||
|
//===[ External prototypes ]===============================================
|
||
|
|
||
|
//===[ Manifest constants ]================================================
|
||
|
|
||
|
#define SERVER_THREAD_SIGNATURE 0x54525653 // SVRT
|
||
|
|
||
|
//===[ Type definitions ]==================================================
|
||
|
|
||
|
//===[ Function prototypes ]===============================================
|
||
|
|
||
|
//===[ Global variables ]==================================================
|
||
|
|
||
|
//===[ Type definitions ]==================================================
|
||
|
|
||
|
//===[ Function prototypes ]===============================================
|
||
|
|
||
|
//===[ Global variables ]==================================================
|
||
|
|
||
|
//
|
||
|
// Object Counters
|
||
|
//
|
||
|
unsigned long numServerThreadObjects = 0;
|
||
|
|
||
|
|
||
|
//++=======================================================================
|
||
|
ServerThread::ServerThread(void) :
|
||
|
|
||
|
m_signature (SERVER_THREAD_SIGNATURE)
|
||
|
//
|
||
|
// Arguments:
|
||
|
//
|
||
|
// Returns:
|
||
|
//
|
||
|
// Abstract:
|
||
|
//
|
||
|
// Notes:
|
||
|
//
|
||
|
// L2
|
||
|
//=======================================================================--
|
||
|
{
|
||
|
DbgTrace(1, "ServerThread::ServerThread- Start, Obj = %08X\n", this);
|
||
|
|
||
|
// Initialize the condition
|
||
|
if (pthread_cond_init(&m_condition, NULL) != 0)
|
||
|
{
|
||
|
DbgTrace(0, "ServerThread::ServerThread- Condition initialization failed\n", 0);
|
||
|
|
||
|
// Throw exception
|
||
|
throw bad_alloc();
|
||
|
}
|
||
|
|
||
|
// Increment the object count
|
||
|
InterlockedIncrement(&numServerThreadObjects);
|
||
|
|
||
|
DbgTrace(1, "ServerThread::ServerThread- End\n", 0);
|
||
|
|
||
|
} /*-- ServerThread::ServerThread() --*/
|
||
|
|
||
|
|
||
|
//++=======================================================================
|
||
|
ServerThread::~ServerThread(void)
|
||
|
//
|
||
|
// Arguments:
|
||
|
//
|
||
|
// Returns:
|
||
|
//
|
||
|
// Abstract:
|
||
|
//
|
||
|
// Notes:
|
||
|
//
|
||
|
// L2
|
||
|
//=======================================================================--
|
||
|
{
|
||
|
DbgTrace(1, "ServerThread::~ServerThread- Start, Obj = %08X\n", this);
|
||
|
|
||
|
// Cleanup resources allocated for the object
|
||
|
pthread_cond_destroy(&m_condition);
|
||
|
|
||
|
// Decrement the object count
|
||
|
InterlockedDecrement(&numServerThreadObjects);
|
||
|
|
||
|
DbgTrace(1, "ServerThread::~ServerThread- End\n", 0);
|
||
|
|
||
|
} /*-- ServerThread::~ServerThread() --*/
|
||
|
|
||
|
|
||
|
//++=======================================================================
|
||
|
void
|
||
|
ServerThread::awaken(void)
|
||
|
//
|
||
|
// Arguments:
|
||
|
//
|
||
|
// Returns:
|
||
|
//
|
||
|
// Abstract:
|
||
|
//
|
||
|
// Notes:
|
||
|
//
|
||
|
// L2
|
||
|
//=======================================================================--
|
||
|
{
|
||
|
DbgTrace(1, "ServerThread::awaken- Start, Obj = %08X\n", this);
|
||
|
|
||
|
#if DEBUG
|
||
|
assert(m_signature == SERVER_THREAD_SIGNATURE);
|
||
|
#endif
|
||
|
|
||
|
// Signal ourselves to wake up
|
||
|
pthread_cond_signal(&m_condition);
|
||
|
|
||
|
DbgTrace(1, "ServerThread::awaken- End\n", 0);
|
||
|
|
||
|
} /*-- ServerThread::awaken() --*/
|
||
|
|
||
|
|
||
|
//++=======================================================================
|
||
|
void
|
||
|
ServerThread::suspend(
|
||
|
pthread_mutex_t *pMutex)
|
||
|
//
|
||
|
// Arguments:
|
||
|
//
|
||
|
// Returns:
|
||
|
//
|
||
|
// Abstract:
|
||
|
//
|
||
|
// Notes:
|
||
|
//
|
||
|
// L2
|
||
|
//=======================================================================--
|
||
|
{
|
||
|
DbgTrace(1, "ServerThread::suspend- Start, Obj = %08X\n", this);
|
||
|
|
||
|
#if DEBUG
|
||
|
assert(m_signature == SERVER_THREAD_SIGNATURE);
|
||
|
#endif
|
||
|
|
||
|
// Wait until signaled to awaken
|
||
|
pthread_cond_wait(&m_condition, pMutex);
|
||
|
|
||
|
DbgTrace(1, "ServerThread::suspend- End\n", 0);
|
||
|
|
||
|
} /*-- ServerThread::suspend() --*/
|
||
|
|
||
|
|
||
|
//=========================================================================
|
||
|
//=========================================================================
|
||
|
|