本文整理汇总了C++中CreateMutex函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateMutex函数的具体用法?C++ CreateMutex怎么用?C++ CreateMutex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateMutex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateMutex
/*----------------------------------------------------------------------
| NPT_Win32Mutex::NPT_Win32Mutex
+---------------------------------------------------------------------*/
NPT_Win32Mutex::NPT_Win32Mutex()
{
m_Handle = CreateMutex(NULL, FALSE, NULL);
}
示例2: CreateMutex
#include "CornerTurnConst.h"
#include "OrderHistoryData.h"
#include "OpenOrderData.h"
#include "PositionUpdate.h"
#include "AccountData.h"
#include "PurchaseData.h"
#include "PurchaseManager.h"
#include "SymbolData.h"
#include "SymbolDataList.h"
#include "PositionMonitorManager.h"
#include "TimeZone.h"
PositionManager * PositionManager::instance_ = 0;
HANDLE mutex_ = CreateMutex (NULL, // no security attributes
FALSE, // initially not owned
"MutexToProtectCriticalSection"); // name of mutex
PositionManager * PositionManager::instance()
{
if(0 == instance_)
{
instance_ = new PositionManager();
}
return instance_;
}
PositionManager::PositionManager()
{
}
示例3: init_resolve_thread
/*
* init_resolve_thread() starts a new thread that performs the actual
* resolve. This function returns before the resolve is done.
*
* Returns FALSE in case of failure, otherwise TRUE.
*/
static bool init_resolve_thread (struct connectdata *conn,
const char *hostname, int port,
const struct addrinfo *hints)
{
struct thread_data *td = calloc(sizeof(*td), 1);
HANDLE thread_and_event[2] = {0};
if (!td)
{
SET_ERRNO(ENOMEM);
return FALSE;
}
Curl_safefree(conn->async.hostname);
conn->async.hostname = strdup(hostname);
if (!conn->async.hostname)
{
free(td);
SET_ERRNO(ENOMEM);
return FALSE;
}
conn->async.port = port;
conn->async.done = FALSE;
conn->async.status = 0;
conn->async.dns = NULL;
conn->async.os_specific = (void*) td;
td->dummy_sock = CURL_SOCKET_BAD;
/* Create the mutex used to inform the resolver thread that we're
* still waiting, and take initial ownership.
*/
td->mutex_waiting = CreateMutex(NULL, TRUE, NULL);
if (td->mutex_waiting == NULL)
{
Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN);
return FALSE;
}
/* Create the event that the thread uses to inform us that it's
* done resolving. Do not signal it.
*/
td->event_resolved = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_resolved == NULL)
{
Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN);
return FALSE;
}
/* Create the mutex used to serialize access to event_terminated
* between us and resolver thread.
*/
td->mutex_terminate = CreateMutex(NULL, FALSE, NULL);
if (td->mutex_terminate == NULL)
{
Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN);
return FALSE;
}
/* Create the event used to signal thread that it should terminate.
*/
td->event_terminate = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_terminate == NULL)
{
Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN);
return FALSE;
}
/* Create the event used by thread to inform it has initialized its own data.
*/
td->event_thread_started = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_thread_started == NULL)
{
Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN);
return FALSE;
}
#ifdef _WIN32_WCE
td->thread_hnd = (HANDLE) CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE) THREAD_FUNC,
conn, 0, &td->thread_id);
#else
td->thread_hnd = (HANDLE) _beginthreadex(NULL, 0, THREAD_FUNC,
conn, 0, &td->thread_id);
#endif
#ifdef CURLRES_IPV6
DEBUGASSERT(hints);
td->hints = *hints;
#else
(void) hints;
#endif
//.........这里部分代码省略.........
示例4: main
//Main program
int main() {
int i,n=0,j=0;
float diff;
FMOD_SYSTEM *fmod = 0;
FMOD_RESULT result;
//establish COM communication
if(serial_start(TEXT("COM7")) != 0) {
printf("Error while establishing COM connection!\n");
system("PAUSE");
exit(1);
}
Sleep(1000);//sleep so that uC can clear LEDs' status
//FMOD
result = FMOD_System_Create(&fmod);
if(result != FMOD_OK) {
printf("FMOD Error");
exit(1);
}
//Mutex
stopAppMutex = CreateMutex(NULL,NULL,NULL);
_stopApp = FALSE;
spectrumMutex = CreateMutex(NULL,NULL,NULL);
for(i = 0;i<8;i++) {
analyzedSpectrum[i] = 0;
}
//FMOD listening thread
_beginthread(getSpectrum, 0, fmod);
//Network thread
//_beginthread(notifyLightshow, 0, NULL);
//control LEDs
n=0;
while(1) {
//clear
for(i = 0;i<25;i++){
buf[0+i*3]=0x00;
buf[1+i*3]=0x00;
buf[2+i*3]=0x00;
}
WaitForSingleObject(spectrumMutex, INFINITE);
for( i =0;i<5;i++) {
diff = abs((analyzedSpectrum[i]/10-previousAnalyzedSpectrum[i]/10)*10);
switch(i) {
case 0:
barsToLEDMapping(0,diff);
break;
case 1:
barsToLEDMapping(1,diff);
break;
case 2:
barsToLEDMapping(2,diff);
break;
case 3:
barsToLEDMapping(3,diff);
break;
case 4:
barsToLEDMapping(4,diff);
break;
}
previousAnalyzedSpectrum[i]=analyzedSpectrum[i];
}
ReleaseMutex(spectrumMutex);
serial_write(buf, 3*25);
}
//cleanup
CloseHandle(comPort);
system("PAUSE");
return 0;
}
示例5: InitGui
void __cdecl InitGui(void *param)
{
HWND hparentwnd;
HANDLE hinst;
WNDCLASSEX wndclass;
char szFile[80];
hinst = GetModuleHandle(NULL);
GetModuleFileName (hinst, szFile, sizeof(szFile));
#ifdef DEBUG
printf ("hinst = %x\n", hinst);
printf ("File = %s\n", szFile);
#endif
/* Fill in window class structure with parameters that describe
the main window. */
/* CS_OWNDC : un DC pour chaque fenêtre de la classe */
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndclass.lpfnWndProc = (WNDPROC)WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hinst;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName = szFile;
wndclass.lpszMenuName = NULL;
if (!RegisterClassEx(&wndclass))
Win32Error("Register class");
hparentwnd = GetFocus();
my_window = CreateWindow(szFile, szTitle,
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
CW_USEDEFAULT, 0,
CW_USEDEFAULT, 0,
/* screenwidth, screendepth, */
hparentwnd, NULL, hinst, NULL);
if (!my_window) {
Win32Error("Create window");
}
#ifdef DEBUG
fprintf(stderr, "my_window = %x\n", my_window);
#endif
#ifdef LOOPMSG
/* Acknowledge for UpdateWindow() (WM_PAINT message generated) */
hMutex = CreateMutex(NULL, FALSE, "DrawingMutex");
my_dc = GetDC(my_window);
/* Device context for drawing and the associated bitmap. */
drawing_dc = CreateCompatibleDC(my_dc);
hbm = CreateCompatibleBitmap(my_dc, screenwidth, screendepth);
SelectObject(drawing_dc, hbm);
/* Blank the bitmap */
SelectObject(drawing_dc, GetStockObject(WHITE_BRUSH));
PatBlt(drawing_dc, 0, 0, screenwidth, screendepth, PATCOPY);
hAccelTable = LoadAccelerators (hinst, szTitle);
ShowWindow(my_window, SW_SHOWNORMAL);
UpdateWindow(my_window);
/* Running the message loop */
while (GetMessage(&msg, my_window, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
#else
drawing_dc = my_dc = GetDC(my_window);
#endif
}
示例6: WinMain
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmd, int nCmdShow)
{
utox_mutex_handle = CreateMutex(NULL, 0, UTOX_TITLE);
if (!utox_mutex_handle) {
return 0;
}
if (GetLastError() == ERROR_ALREADY_EXISTS) {
HWND window = FindWindow(UTOX_TITLE, NULL);
/* uTox is running. */
if (window) {
SetForegroundWindow(window);
}
return 0;
}
MY_CMD_ARGS = cmd;
MY_HINSTANCE = hInstance;
TOX_UPDATER_PATH_LEN = GetModuleFileName(NULL, TOX_UPDATER_PATH, MAX_PATH);
TOX_UPDATER_PATH[TOX_UPDATER_PATH_LEN] = 0;
{
char path[MAX_PATH], *s;
memcpy(path, TOX_UPDATER_PATH, TOX_UPDATER_PATH_LEN + 1);
s = path + TOX_UPDATER_PATH_LEN;
while(*s != '\\') {
s--;
}
*s = 0;
SetCurrentDirectory(path);
}
LPWSTR *arglist;
int argc, i;
init_tox_version_name();
/* Convert PSTR command line args from windows to argc */
arglist = CommandLineToArgvW(GetCommandLineW(), &argc);
if( NULL != arglist ){
for (i = 0; i < argc; i++) {
if(wcscmp(arglist[i], L"--uninstall") == 0) {
if (is_tox_installed) {
uninstall_tox();
return 0;
}
}
}
}
LOG_FILE = fopen("tox_log.txt", "w");
/* initialize winsock */
WSADATA wsaData;
if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
LOG_TO_FILE("WSAStartup failed\n");
return 1;
}
if (IsWindowsVistaOrGreater()) {
/* check if we are on a 64-bit system */
_Bool iswow64 = 0;
_Bool (WINAPI *fnIsWow64Process)(HANDLE, _Bool*) = (void*)GetProcAddress(GetModuleHandleA("kernel32"),"IsWow64Process");
if(fnIsWow64Process) {
fnIsWow64Process(GetCurrentProcess(), &iswow64);
}
if(iswow64) {
/* replace the arch in the GET_NAME/TOX_VERSION_NAME strings (todo: not use constants for offsets) */
GET_NAME[3] = '6';
GET_NAME[4] = '4';
TOX_VERSION_NAME[0] = '6';
TOX_VERSION_NAME[1] = '4';
LOG_TO_FILE("detected 64bit system\n");
} else {
GET_NAME[3] = '3';
GET_NAME[4] = '2';
TOX_VERSION_NAME[0] = '3';
TOX_VERSION_NAME[1] = '2';
LOG_TO_FILE("detected 32bit system\n");
}
} else {
GET_NAME[3] = 'x';
GET_NAME[4] = 'p';
TOX_VERSION_NAME[0] = 'x';
TOX_VERSION_NAME[1] = 'p';
LOG_TO_FILE("detected XP system\n");
}
/* init common controls */
INITCOMMONCONTROLSEX InitCtrlEx;
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCtrlEx.dwICC = ICC_PROGRESS_CLASS;
InitCommonControlsEx(&InitCtrlEx);
//.........这里部分代码省略.........
示例7: WinMain
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR commandLine, INT )
{
// set up some xbmc specific relationships
XBMC::Context context;
//this can't be set from CAdvancedSettings::Initialize() because it will overwrite
//the loglevel set with the --debug flag
#ifdef _DEBUG
g_advancedSettings.m_logLevel = LOG_LEVEL_DEBUG;
g_advancedSettings.m_logLevelHint = LOG_LEVEL_DEBUG;
#else
g_advancedSettings.m_logLevel = LOG_LEVEL_NORMAL;
g_advancedSettings.m_logLevelHint = LOG_LEVEL_NORMAL;
#endif
CLog::SetLogLevel(g_advancedSettings.m_logLevel);
// Initializes CreateMiniDump to handle exceptions.
win32_exception::set_version(g_infoManager.GetVersion());
SetUnhandledExceptionFilter( CreateMiniDump );
// check if XBMC is already running
CreateMutex(NULL, FALSE, "XBMC Media Center");
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
HWND m_hwnd = FindWindow("XBMC","XBMC");
if(m_hwnd != NULL)
{
// switch to the running instance
ShowWindow(m_hwnd,SW_RESTORE);
SetForegroundWindow(m_hwnd);
}
return 0;
}
#ifndef HAS_DX
if(CWIN32Util::GetDesktopColorDepth() < 32)
{
//FIXME: replace it by a SDL window for all ports
MessageBox(NULL, "Desktop Color Depth isn't 32Bit", "XBMC: Fatal Error", MB_OK|MB_ICONERROR);
return 0;
}
#endif
if((g_cpuInfo.GetCPUFeatures() & CPU_FEATURE_SSE2) == 0)
{
MessageBox(NULL, "No SSE2 support detected", "XBMC: Fatal Error", MB_OK|MB_ICONERROR);
return 0;
}
//Initialize COM
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Handle numeric values using the default/POSIX standard
setlocale(LC_NUMERIC, "C");
// If the command line passed to WinMain, commandLine, is not "" we need
// to process the command line arguments.
// Note that commandLine does not include the program name and can be
// equal to "" if no arguments were supplied. By contrast GetCommandLineW()
// does include the program name and is never equal to "".
g_advancedSettings.Initialize();
if (strlen(commandLine) != 0)
{
int argc;
LPWSTR* argvW = CommandLineToArgvW(GetCommandLineW(), &argc);
std::vector<std::string> strargvA;
strargvA.resize(argc);
const char** argv = (const char**) LocalAlloc(LMEM_FIXED, argc*sizeof(char*));
for (int i = 0; i < argc; i++)
{
g_charsetConverter.wToUTF8(argvW[i], strargvA[i]);
argv[i] = strargvA[i].c_str();
}
// Parse the arguments
CAppParamParser appParamParser;
appParamParser.Parse(argv, argc);
// Clean up the storage we've used
LocalFree(argvW);
LocalFree(argv);
}
// Initialise Winsock
WSADATA wd;
WSAStartup(MAKEWORD(2,2), &wd);
// use 1 ms timer precision - like SDL initialization used to do
timeBeginPeriod(1);
#ifdef XBMC_TRACK_EXCEPTIONS
try
{
#endif
// Create and run the app
//.........这里部分代码省略.........
示例8: wWinMain
int WINAPI wWinMain(_In_ HINSTANCE Program, _In_opt_ HINSTANCE PreviousProgram, _In_ LPWSTR CommandLine, _In_ int ShowCommand)
{
UNREFERENCED_PARAMETER(PreviousProgram);
UNREFERENCED_PARAMETER(CommandLine);
UNREFERENCED_PARAMETER(ShowCommand);
#ifndef _XBOX
HRESULT hr = CoInitializeEx(nullptr, COINITBASE_MULTITHREADED);
if (FAILED(hr))
return 1;
#endif
// make sure this is the only instance of this game running on the computer if not then close application
const char szUniqueNamedMutex[] = "punchdrunksquirrelgames_bloodnoir";
HANDLE hHandle = CreateMutex(NULL, TRUE, szUniqueNamedMutex);
if (ERROR_ALREADY_EXISTS == GetLastError())
{
// Program already running somewhere
return(1); // Exit program
}
// create the game object
m_game = make_unique<Game>();
// initialize the window class
if (!InitWindowClass(Program))
return 1;
// display the window on the screen
ShowWindow(m_window, SW_MAXIMIZE);
SetWindowLongPtr(m_window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(m_game.get()));
GetClientRect(m_window, &rc);
// initialize the game
if (!m_game->GameInitialize(m_window, rc.right - rc.left, rc.bottom - rc.top))
return 0;
// enter the message loop only leaving it when the Quit message is received
MSG msg = { 0 };
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
m_game->GameRun();
}
}
// if loop exists then reset game object
m_game.reset();
// release things that need to be released and return control to windows
CoUninitialize();
ReleaseMutex(hHandle); // Explicitly release mutex
CloseHandle(hHandle); // close handle before terminating
return (int)msg.wParam;
}
示例9: __declspec
int __declspec(dllexport) DLL_Init()
{
if (!hMutex)
hMutex = CreateMutex(NULL,false,NULL);
return 0;
}
示例10: system_Configure
void system_Configure( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
{
#if !defined( UNDER_CE )
/* Raise default priority of the current process */
#ifndef ABOVE_NORMAL_PRIORITY_CLASS
# define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
#endif
if( config_GetInt( p_this, "high-priority" ) )
{
if( SetPriorityClass( GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS )
|| SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS ) )
{
msg_Dbg( p_this, "raised process priority" );
}
else
{
msg_Dbg( p_this, "could not raise process priority" );
}
}
if( config_GetInt( p_this, "one-instance" )
|| ( config_GetInt( p_this, "one-instance-when-started-from-file" )
&& config_GetInt( p_this, "started-from-file" ) ) )
{
HANDLE hmutex;
msg_Info( p_this, "one instance mode ENABLED");
/* Use a named mutex to check if another instance is already running */
if( !( hmutex = CreateMutex( 0, TRUE, L"VLC ipc "VERSION ) ) )
{
/* Failed for some reason. Just ignore the option and go on as
* normal. */
msg_Err( p_this, "one instance mode DISABLED "
"(mutex couldn't be created)" );
return;
}
if( GetLastError() != ERROR_ALREADY_EXISTS )
{
/* We are the 1st instance. */
static const char typename[] = "ipc helper";
p_helper =
vlc_custom_create( p_this, sizeof(vlc_object_t),
VLC_OBJECT_GENERIC, typename );
/* Run the helper thread */
hIPCHelperReady = CreateEvent( NULL, FALSE, FALSE, NULL );
hIPCHelper = _beginthreadex( NULL, 0, IPCHelperThread, p_helper,
0, NULL );
if( hIPCHelper )
WaitForSingleObject( hIPCHelperReady, INFINITE );
else
{
msg_Err( p_this, "one instance mode DISABLED "
"(IPC helper thread couldn't be created)" );
vlc_object_release (p_helper);
p_helper = NULL;
}
vlc_object_attach (p_helper, p_this);
CloseHandle( hIPCHelperReady );
/* Initialization done.
* Release the mutex to unblock other instances */
ReleaseMutex( hmutex );
}
else
{
示例11: CreateMutex
FacebookProto::FacebookProto(const char* proto_name,const TCHAR* username) :
PROTO<FacebookProto>(proto_name, username)
{
facy.parent = this;
signon_lock_ = CreateMutex(NULL, FALSE, NULL);
avatar_lock_ = CreateMutex(NULL, FALSE, NULL);
log_lock_ = CreateMutex(NULL, FALSE, NULL);
update_loop_lock_ = CreateEvent(NULL, FALSE, FALSE, NULL);
facy.buddies_lock_ = CreateMutex(NULL, FALSE, NULL);
facy.send_message_lock_ = CreateMutex(NULL, FALSE, NULL);
facy.fcb_conn_lock_ = CreateMutex(NULL, FALSE, NULL);
m_invisible = false;
CreateProtoService(PS_CREATEACCMGRUI, &FacebookProto::SvcCreateAccMgrUI);
CreateProtoService(PS_GETMYAWAYMSG, &FacebookProto::GetMyAwayMsg);
CreateProtoService(PS_GETMYAVATART, &FacebookProto::GetMyAvatar);
CreateProtoService(PS_GETAVATARINFOT, &FacebookProto::GetAvatarInfo);
CreateProtoService(PS_GETAVATARCAPS, &FacebookProto::GetAvatarCaps);
CreateProtoService(PS_GETUNREADEMAILCOUNT, &FacebookProto::GetNotificationsCount);
CreateProtoService(PS_JOINCHAT, &FacebookProto::OnJoinChat);
CreateProtoService(PS_LEAVECHAT, &FacebookProto::OnLeaveChat);
CreateProtoService("/Mind", &FacebookProto::OnMind);
CreateProtoService("/VisitProfile", &FacebookProto::VisitProfile);
CreateProtoService("/VisitNotifications", &FacebookProto::VisitNotifications);
HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &FacebookProto::OnBuildStatusMenu);
HookProtoEvent(ME_OPT_INITIALISE, &FacebookProto::OnOptionsInit);
HookProtoEvent(ME_IDLE_CHANGED, &FacebookProto::OnIdleChanged);
HookProtoEvent(ME_TTB_MODULELOADED, &FacebookProto::OnToolbarInit);
HookProtoEvent(ME_GC_EVENT, &FacebookProto::OnGCEvent);
HookProtoEvent(ME_GC_BUILDMENU, &FacebookProto::OnGCMenuHook);
HookProtoEvent(ME_DB_EVENT_MARKED_READ, &FacebookProto::OnDbEventRead);
HookProtoEvent(ME_MSG_WINDOWEVENT, &FacebookProto::OnProcessSrmmEvent);
db_set_resident(m_szModuleName, "Status");
db_set_resident(m_szModuleName, "IdleTS");
InitHotkeys();
InitPopups();
InitSounds();
// Create standard network connection
TCHAR descr[512];
NETLIBUSER nlu = {sizeof(nlu)};
nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
nlu.szSettingsModule = m_szModuleName;
mir_sntprintf(descr, SIZEOF(descr), TranslateT("%s server connection"), m_tszUserName);
nlu.ptszDescriptiveName = descr;
m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
if (m_hNetlibUser == NULL)
MessageBox(NULL, TranslateT("Unable to get Netlib connection for Facebook"), m_tszUserName, MB_OK);
facy.set_handle(m_hNetlibUser);
// Set all contacts offline -- in case we crashed
SetAllContactStatuses(ID_STATUS_OFFLINE);
}
示例12: WinMain
VOS_S32 __stdcall WinMain(HINSTANCE hInst,
HINSTANCE hPrevInst,
LPSTR cmdLine,
VOS_S32 show)
{
DCSP_USAGE_OPTIONS *options;
VOS_U16 ai_name_msg[] = {0,
34,
DCSP_HST_NME,
DCSP_HST_BRACKET_OPEN,
DCSP_HST_CHAR('h'),
DCSP_HST_CHAR('o'),
DCSP_HST_CHAR('l'),
DCSP_HST_CHAR('d'),
DCSP_HST_CHAR('b'),
DCSP_HST_CHAR('o'),
DCSP_HST_CHAR('t'),
DCSP_HST_BRACKET_CLOSE,
DCSP_HST_BRACKET_OPEN,
DCSP_HST_CHAR('0'),
DCSP_HST_CHAR('0'),
DCSP_HST_CHAR('.'),
DCSP_HST_CHAR('0'),
DCSP_HST_CHAR('1'),
DCSP_HST_BRACKET_CLOSE};
VOS_BOOL keep_going = TRUE;
HLDB_THREAD_DATA *thread_data = NULL;
HLDB_MSG *hldb_msg;
VOS_S32 wait_rc;
HLDB_LOCAL_DATA local;
VOS_CHAR *host = "localhost";
VOS_U8 host_type = DCSP_ADDR_FORMAT_HOST_NAME;
VOS_U16 port = 16713;
VOS_UNREFERENCED_PARAMETER(hInst);
VOS_UNREFERENCED_PARAMETER(hPrevInst);
VOS_UNREFERENCED_PARAMETER(show);
/***************************************************************************/
/* Set-up the message type for the NME message. */
/***************************************************************************/
*((VOS_U8 *)ai_name_msg) = DCSP_MSG_TYPE_DM;
/***************************************************************************/
/* Check and set the options from the command line. */
/***************************************************************************/
if (!hldb_set_parameters(cmdLine, &host, &host_type, &port))
{
MessageBox(
NULL,
"Syntax: holdbot [-nhost_name|-iip_address] [-pport]",
"Hold-bot",
0);
goto EXIT_LABEL;
}
/***************************************************************************/
/* Allocate thread-control objects. */
/***************************************************************************/
thread_data = malloc(sizeof(HLDB_THREAD_DATA));
if (thread_data == NULL)
{
MessageBox(NULL, "Out of memory", "Hold-bot", 0);
goto EXIT_LABEL;
}
thread_data->semaphore = CreateSemaphore(NULL, 0, VOS_MAX_PSINT, NULL);
thread_data->mutex = CreateMutex(NULL, FALSE, NULL);
if ((thread_data->semaphore == NULL) || (thread_data->mutex == NULL))
{
MessageBox(NULL, "Failed to allocate thread controls", "Hold-bot", 0);
goto EXIT_LABEL;
}
VOS_Q_INIT_ROOT(thread_data->msg_q);
/***************************************************************************/
/* Initialise the local data. */
/***************************************************************************/
local.power = 0;
local.num_scs = 0;
/***************************************************************************/
/* Set up the client options. For ease of use, the holdbot uses */
/* Host-Order messages. (Real AIs will probably wish to use network order */
/* to improve performance.) */
/***************************************************************************/
options = dcsp_configure("holdbot.cfg");
options->client = TRUE;
options->scheduling = DCSP_SCHEDULE_THREAD;
options->notification = DCSP_NOTIFICATION_CALLBACK;
options->representation = DCSP_REPRESENTATION_HOST_ORDER;
options->message_callback = hldb_receive_message;
options->message_callback_data = (VOS_VOID *)thread_data;
/***************************************************************************/
/* Initialise the DLL. */
/***************************************************************************/
if (!dcsp_start(options))
{
MessageBox(NULL, "Failed to initialise the DLL", "Hold-bot", 0);
//.........这里部分代码省略.........
示例13: _winpr_openssl_initialize_locking
static BOOL _winpr_openssl_initialize_locking(void)
{
int i, count;
/* OpenSSL static locking */
if (CRYPTO_get_locking_callback())
{
WLog_WARN(TAG, "OpenSSL static locking callback is already set");
}
else
{
if ((count = CRYPTO_num_locks()) > 0)
{
HANDLE* locks;
if (!(locks = calloc(count, sizeof(HANDLE))))
{
WLog_ERR(TAG, "error allocating lock table");
return FALSE;
}
for (i = 0; i < count; i++)
{
if (!(locks[i] = CreateMutex(NULL, FALSE, NULL)))
{
WLog_ERR(TAG, "error creating lock #%d", i);
while (i--)
{
if (locks[i])
CloseHandle(locks[i]);
}
free(locks);
return FALSE;
}
}
g_winpr_openssl_locks = locks;
g_winpr_openssl_num_locks = count;
CRYPTO_set_locking_callback(_winpr_openssl_locking);
}
}
/* OpenSSL dynamic locking */
if (CRYPTO_get_dynlock_create_callback() ||
CRYPTO_get_dynlock_lock_callback() ||
CRYPTO_get_dynlock_destroy_callback())
{
WLog_WARN(TAG, "dynamic locking callbacks are already set");
}
else
{
CRYPTO_set_dynlock_create_callback(_winpr_openssl_dynlock_create);
CRYPTO_set_dynlock_lock_callback(_winpr_openssl_dynlock_lock);
CRYPTO_set_dynlock_destroy_callback(_winpr_openssl_dynlock_destroy);
}
/* Use the deprecated CRYPTO_get_id_callback() if building against OpenSSL < 1.0.0 */
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
if (CRYPTO_get_id_callback())
{
WLog_WARN(TAG, "OpenSSL id_callback is already set");
}
else
{
CRYPTO_set_id_callback(_winpr_openssl_id);
}
#endif
return TRUE;
}
示例14: ngx_master_process_cycle
void
ngx_master_process_cycle(ngx_cycle_t *cycle)
{
u_long nev, ev, timeout;
ngx_err_t err;
ngx_int_t n;
ngx_msec_t timer;
ngx_uint_t live;
HANDLE events[MAXIMUM_WAIT_OBJECTS];
ngx_sprintf((u_char *) ngx_master_process_event_name,
"ngx_master_%s%Z", ngx_unique);
if (ngx_process == NGX_PROCESS_WORKER) {
ngx_worker_process_cycle(cycle, ngx_master_process_event_name);
return;
}
ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "master started");
ngx_console_init(cycle);
SetEnvironmentVariable("ngx_unique", ngx_unique);
ngx_master_process_event = CreateEvent(NULL, 1, 0,
ngx_master_process_event_name);
if (ngx_master_process_event == NULL) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"CreateEvent(\"%s\") failed",
ngx_master_process_event_name);
exit(2);
}
if (ngx_create_signal_events(cycle) != NGX_OK) {
exit(2);
}
ngx_sprintf((u_char *) ngx_cache_manager_mutex_name,
"ngx_cache_manager_mutex_%s%Z", ngx_unique);
ngx_cache_manager_mutex = CreateMutex(NULL, 0,
ngx_cache_manager_mutex_name);
if (ngx_cache_manager_mutex == NULL) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"CreateMutex(\"%s\") failed", ngx_cache_manager_mutex_name);
exit(2);
}
events[0] = ngx_stop_event;
events[1] = ngx_quit_event;
events[2] = ngx_reopen_event;
events[3] = ngx_reload_event;
ngx_close_listening_sockets(cycle);
if (ngx_start_worker_processes(cycle, NGX_PROCESS_RESPAWN) == 0) {
exit(2);
}
timer = 0;
timeout = INFINITE;
for ( ;; ) {
nev = 4;
for (n = 0; n < ngx_last_process; n++) {
if (ngx_processes[n].handle) {
events[nev++] = ngx_processes[n].handle;
}
}
if (timer) {
timeout = timer > ngx_current_msec ? timer - ngx_current_msec : 0;
}
ev = WaitForMultipleObjects(nev, events, 0, timeout);
err = ngx_errno;
ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"master WaitForMultipleObjects: %ul", ev);
if (ev == WAIT_OBJECT_0) {
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
if (ResetEvent(ngx_stop_event) == 0) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"ResetEvent(\"%s\") failed", ngx_stop_event_name);
}
if (timer == 0) {
timer = ngx_current_msec + 5000;
}
ngx_terminate = 1;
ngx_quit_worker_processes(cycle, 0);
continue;
//.........这里部分代码省略.........
示例15: CDialog
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
CurlBlastDlg::CurlBlastDlg(CWnd* pParent /*=NULL*/)
: CDialog(CurlBlastDlg::IDD, pParent)
, start(0)
, freq(0)
, firstIdleTime(0)
, firstKernelTime(0)
, firstUserTime(0)
, lastIdleTime(0)
, lastKernelTime(0)
, lastUserTime(0)
, logFile(_T(""))
, startupDelay(1000)
, computerName(_T(""))
, lastUpload(0)
, testID(0)
, configID(0)
, timeout(0)
, running(false)
, checkOpt(1)
, bDrWatson(false)
, accountBase(_T("user"))
, password(_T("2dialit"))
, browserWidth(1024)
, browserHeight(768)
, debug(0)
, urlManager(log)
, pipeIn(0)
, pipeOut(0)
, ec2(0)
, useCurrentAccount(0)
, hHookDll(NULL)
, keepDNS(0)
, worker(NULL)
, hRunningThread(NULL)
, hMustExit(NULL)
, lastAlive(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
hMustExit = CreateEvent(NULL, TRUE, FALSE, NULL);
testingMutex = CreateMutex(NULL, FALSE, _T("Global\\WebPagetest"));
InitializeCriticalSection(&cs);
// handle crash events
crashLog = &log;
SetUnhandledExceptionFilter(CrashFilter);
// create a NULL DACL we will re-use everywhere we do file access
ZeroMemory(&nullDacl, sizeof(nullDacl));
nullDacl.nLength = sizeof(nullDacl);
nullDacl.bInheritHandle = FALSE;
if( InitializeSecurityDescriptor(&SD, SECURITY_DESCRIPTOR_REVISION) )
if( SetSecurityDescriptorDacl(&SD, TRUE,(PACL)NULL, FALSE) )
nullDacl.lpSecurityDescriptor = &SD;
// randomize the random number generator
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
srand(ft.dwLowDateTime);
// get the computer name
TCHAR buff[MAX_COMPUTERNAME_LENGTH + 1];
DWORD len = _countof(buff);
if( GetComputerName(buff, &len) )
computerName = buff;
// let our process kill processes from other users
HANDLE hToken;
if( OpenProcessToken( GetCurrentProcess() , TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY , &hToken) )
{
TOKEN_PRIVILEGES tp;
if( LookupPrivilegeValue( NULL , SE_DEBUG_NAME, &tp.Privileges[0].Luid ) )
{
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken , FALSE , &tp , 0 , (PTOKEN_PRIVILEGES) 0 , 0 ) ;
}
CloseHandle(hToken);
}
}