extern void MT_InitThreads(void) { #if !GLIB_CHECK_VERSION (2,32,0) if (!g_thread_supported()) g_thread_init(NULL); g_assert(g_thread_supported()); #endif td.tasks = NULL; td.doneTasks = td.addedTasks = 0; td.totalTasks = -1; InitManualEvent(&td.activity); TLSCreate(&td.tlsItem); TLSSetValue(td.tlsItem, 0); /* Main thread shares id 0 */ #if defined(DEBUG_MULTITHREADED) && defined(WIN32) mainThreadID = GetCurrentThreadId(); #endif InitMutex(&td.multiLock); InitMutex(&td.queueLock); InitManualEvent(&td.syncStart); InitManualEvent(&td.syncEnd); #if defined(GLIB_THREADS) && !GLIB_CHECK_VERSION (2,32,0) if (condMutex == NULL) condMutex = g_mutex_new(); #endif td.numThreads = 0; }
static void Imo2sproxy_Loop(IMO2SPROXY *hInst) { struct sockaddr_in sock; int socklen; SOCKET new_fd; TYP_LIST *hConns = List_Init(32); CONNINST *pInst; IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst; fd_set fdListen; if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog) fprintf (hProxy->pCfg->fpLog, "Socksproxy:Loop(Start)\n"); hProxy->iRunning = 1; LockMutex(hProxy->loopmutex); while (hProxy->iRunning) { FD_ZERO(&fdListen); FD_SET(hProxy->listen_fd, &fdListen); socklen = sizeof(sock); if (select (0, &fdListen, NULL, NULL, NULL) != SOCKET_ERROR && FD_ISSET(hProxy->listen_fd, &fdListen)) { new_fd = accept(hProxy->listen_fd, (struct sockaddr *) &sock, &socklen); if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog) { fprintf (hProxy->pCfg->fpLog, "Connection from %s:%d -> Connection: %d\n", inet_ntoa(sock.sin_addr), ntohs(sock.sin_port), new_fd); fflush (hProxy->pCfg->fpLog); } if (new_fd != INVALID_SOCKET && (pInst = calloc (1, sizeof(CONNINST)))) { CleanConnections (hConns); List_Push(hConns, pInst); pInst->hSock = new_fd; pInst->hProxy = hProxy; InitMutex(pInst->connected); LockMutex(pInst->connected); InitMutex(pInst->sendmutex); Dispatcher_Start(pInst); } } } if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog) fprintf (hProxy->pCfg->fpLog, "Socksproxy:Loop(End)\n"); CleanConnections (hConns); while (pInst=List_Pop(hConns)) { Dispatcher_Stop(pInst); FreeConnection(pInst); free (pInst); } List_Exit(hConns); UnlockMutex(hProxy->loopmutex); }
/* Initialize CRL members */ int InitCRL(WOLFSSL_CRL* crl, WOLFSSL_CERT_MANAGER* cm) { WOLFSSL_ENTER("InitCRL"); crl->heap = cm->heap; crl->cm = cm; crl->crlList = NULL; crl->monitors[0].path = NULL; crl->monitors[1].path = NULL; #ifdef HAVE_CRL_MONITOR crl->tid = 0; crl->mfd = -1; /* mfd for bsd is kqueue fd, eventfd for linux */ crl->setup = 0; /* thread setup done predicate */ if (pthread_cond_init(&crl->cond, 0) != 0) { WOLFSSL_MSG("Pthread condition init failed"); return BAD_COND_E; } #endif if (InitMutex(&crl->crlLock) != 0) { WOLFSSL_MSG("Init Mutex failed"); return BAD_MUTEX_E; } return 0; }
CrossProcessMutex::CrossProcessMutex(CrossProcessMutexHandle aHandle) : mMutex(nullptr) , mCount(nullptr) { if (!ipc::SharedMemoryBasic::IsHandleValid(aHandle)) { MOZ_CRASH(); } mSharedBuffer = new ipc::SharedMemoryBasic(aHandle); if (!mSharedBuffer->Map(sizeof(MutexData))) { MOZ_CRASH(); } MutexData* data = static_cast<MutexData*>(mSharedBuffer->memory()); if (!data) { MOZ_CRASH(); } mMutex = &(data->mMutex); mCount = &(data->mCount); int32_t count = (*mCount)++; if (count == 0) { // The other side has already let go of their CrossProcessMutex, so now // mMutex is garbage. We need to re-initialize it. InitMutex(mMutex); } MOZ_COUNT_CTOR(CrossProcessMutex); }
// ------------------------------------------------------------------------------------------------- LOG_HANDLE* PsLogOpen(const char* prefix) { LOG_HANDLE *hHandle = (LOG_HANDLE*)malloc(sizeof(LOG_HANDLE)); InitMutex(&hHandle->g_log_mutex); hHandle->g_bytes = 0; hHandle->g_cur_file = NULL; assert(prefix); if (prefix == NULL) { return NULL; } else { const char bad_char[] = "/\\:*?\"<>|"; // 不能用于文件名的字符 int prefix_len = (int)strlen(prefix); int i = 0; memset(hHandle->g_fname_prefix, 0, sizeof(hHandle->g_fname_prefix)); for (; i < prefix_len && i < (int)sizeof(hHandle->g_fname_prefix) - 1; i++) { const char c = prefix[i]; if (strchr(bad_char, c)) hHandle->g_fname_prefix[i] = '#'; else hHandle->g_fname_prefix[i] = c; } } switch_file(hHandle, 0); PsLogAdd_msg(hHandle, "%s.log start", prefix); return hHandle; }
/** * @brief Implements common layer setup functionality. * * @param bottom the preshaped input blobs * @param top * the allocated but unshaped output blobs, to be shaped by Reshape * * Checks that the number of bottom and top blobs is correct. * Calls LayerSetUp to do special layer setup for individual layer types, * followed by Reshape to set up sizes of top blobs and internal buffers. * Sets up the loss weight multiplier blobs for any non-zero loss weights. * This method may not be overridden. */ void SetUp(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { InitMutex(); CheckBlobCounts(bottom, top); LayerSetUp(bottom, top); Reshape(bottom, top); SetLossWeights(top); }
CSysParams::CSysParams() { m_hMutex = NULL; m_lQryInterval = DEFAULT_QRY_INTERVAL; m_bEnableLog = DEFAULT_LOG_FLAG; m_bKeepDbConnection = DEFAULT_KEEP_DB_CONNECT; InitMutex(); }
int InitOCSP(CYASSL_OCSP* ocsp, CYASSL_CERT_MANAGER* cm) { CYASSL_ENTER("InitOCSP"); XMEMSET(ocsp, 0, sizeof(*ocsp)); ocsp->cm = cm; if (InitMutex(&ocsp->ocspLock) != 0) return BAD_MUTEX_E; return 0; }
int wolfSSL_CryptHwMutexInit(void) { int ret = 0; if(wcCryptHwMutexInit == 0) { ret = InitMutex(&wcCryptHwMutex); if(ret == 0) { wcCryptHwMutexInit = 1; } } return ret; }
/********* SHEULL MAIN LOOP ***********************************/ void shell_main(void) { int i ; func_args args ; int bf_flg ; i = BackGround ; /* Dummy for avoiding warning: BackGround is defined but not used. */ #if defined(HAVE_KEIL_RTX) InitMutex(&command_mutex) ; #endif time_main(NULL) ; printf("Starting Shell\n") ; while(1) { if(getline(line, LINESIZE, &args, &bf_flg) > 0) { for(i=0; commandTable[i].func != NULL; i++) { if(strcmp(commandTable[i].command, args.argv[0]) == 0) { args.argv[0] = (char *) commandTable[i].func ; if(bf_flg == FORGROUND) { #ifdef HAVE_KEIL_RTX UnLockMutex((CyaSSL_Mutex *)&command_mutex) ; os_tsk_create_user_ex( (void(*)(void *))&command_invoke, 7, command_stack, COMMAND_STACK_SIZE, &args) ; #else command_invoke(&args) ; #endif #ifdef HAVE_KEIL_RTX LockMutex((CyaSSL_Mutex *)&command_mutex) ; #endif } else { #if (!defined(NO_SIMPLE_SERVER) && \ !defined(NO_ECHOSERVER)) && \ defined(HAVE_KEIL_RTX) if(BackGround != 0) { printf("Multiple background servers not supported.\n") ; } else { printf("\"%s\" is running with the background mode.\n", commandTable[i].command) ; os_tsk_create_user_ex( (void(*)(void *))&bg_job_invoke, 6, bg_job_stack, BG_JOB_STACK_SIZE, &args) ; } #else printf("Invalid Command: no background job\n") ; #endif } break ; } } if(commandTable[i].func == NULL) printf("Command not found\n") ; } } }
/** * @brief Implements common layer setup functionality. * * @param bottom the preshaped input blobs * @param top * the allocated but unshaped output blobs, to be shaped by Reshape * * Checks that the number of bottom and top blobs is correct. * Calls LayerSetUp to do special layer setup for individual layer types, * followed by Reshape to set up sizes of top blobs and internal buffers. * Sets up the loss weight multiplier blobs for any non-zero loss weights. * This method may not be overridden. */ void SetUp(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { InitMutex(); CheckBlobCounts(bottom, top); LayerSetUp(bottom, top); Reshape(bottom, top); SetLossWeights(top); #ifdef USE_MLSL MultinodeSetUp(bottom, top); #endif }
IMO2SPROXY *W32SkypeEmu_Init (IMO2SPROXY_CFG *pCfg, W32SKYPEEMU_CFG *pMyCfg) { IMO2SPROXY_INST *pstInst = calloc(sizeof(IMO2SPROXY_INST), 1); pstInst->vtbl.Open = Imo2sproxy_Open; pstInst->vtbl.Loop = Imo2sproxy_Loop; pstInst->vtbl.Exit = Imo2sproxy_Exit; pstInst->pCfg = pCfg; pstInst->pMyCfg = pMyCfg; InitMutex(pstInst->loopmutex); return (IMO2SPROXY*)pstInst; }
IMO2SPROXY *SocksProxy_Init (IMO2SPROXY_CFG *pCfg, SOCKSPROXY_CFG *pMyCfg) { IMO2SPROXY_INST *pstInst = calloc(sizeof(IMO2SPROXY_INST), 1); pstInst->vtbl.Open = Imo2sproxy_Open; pstInst->vtbl.Loop = Imo2sproxy_Loop; pstInst->vtbl.Exit = Imo2sproxy_Exit; pstInst->pCfg = pCfg; pstInst->pMyCfg = pMyCfg; InitMutex(pstInst->loopmutex); return (IMO2SPROXY*)pstInst; }
int InitOCSP(WOLFSSL_OCSP* ocsp, WOLFSSL_CERT_MANAGER* cm) { WOLFSSL_ENTER("InitOCSP"); ForceZero(ocsp, sizeof(WOLFSSL_OCSP)); if (InitMutex(&ocsp->ocspLock) != 0) return BAD_MUTEX_E; ocsp->cm = cm; return 0; }
/*** * 功能: 窗体FrmWiFi的绘制函数,绘制整个窗体 * 参数: 1.void *pWndObj: 指向当前窗体对象 * 返回: 成功返回零,失败返回非零值 * 备注: ***/ int FrmWiFiPaint(void *pWndObj) { //错误标志、返回值定义 int iReturn = 0; int i = 0; //得到当前窗体对象 pFrmWiFi = (GUIWINDOW *) pWndObj; //显示桌面背景图片 DisplayPicture(pWiFiBtnLeftBg); //显示菜单 DisplayPicture(pWiFiMenuBg); for(i = 0; i < 5; i++) { DisplayPicture(pWiFiMenu[i]); DisplayLabel(pWiFiLblMenu[i]); } //显示状态栏上的图片 DisplayPicture(pWiFiBtnOnOffBg); //显示窗体左上角窗体Label DisplayLabel(pWiFiLblFrmName); DisplayLabel(pWiFiLblOnOffInfo); //DisplayLabel(pWiFiLblConnecting);//victor SetPictureBitmap(BmpFileDirectory"btn_wifi_on_unpress.bmp", pWiFiBtnREnableOn); SetPictureBitmap(BmpFileDirectory"btn_wifi_off_press.bmp", pWiFiBtnREnableOff); SetPictureBitmap(BmpFileDirectory"btn_wifi_ssid_press.bmp", pWiFiBtnConnect);//victor DisplayPicture(pWiFiBtnREnableOn); DisplayPicture(pWiFiBtnREnableOff); DisplayPicture(pWiFiBtnConnect);//victor DisplayLabel(pWiFiLblConnecting);//victor for(i = 0; i < WIFIITEM; i++) { DisplayPicture(pWiFiItem[i]); DisplayLabel(pWiFiLblItem[i]); } //初始化wifi,创建wifi线程 InitMutex(&pWifiMutex, NULL); InitWifiQueue(10); ThreadCreate(&thdWifi, NULL, DefaultWifiThread, NULL); return iReturn; }
void mutex_init(mutex* lock, const char *name) { lock->name = name; lock->waiters = NULL; #if KDEBUG lock->holder = -1; #else lock->count = 0; lock->ignore_unlock_count = 0; #endif lock->flags = 0; T_SCHEDULING_ANALYSIS(InitMutex(lock, name)); NotifyWaitObjectListeners(&WaitObjectListener::MutexInitialized, lock); }
void mutex_init_etc(mutex* lock, const char *name, uint32 flags) { lock->name = (flags & MUTEX_FLAG_CLONE_NAME) != 0 ? strdup(name) : name; lock->waiters = NULL; #if KDEBUG lock->holder = -1; #else lock->count = 0; lock->ignore_unlock_count = 0; #endif lock->flags = flags & MUTEX_FLAG_CLONE_NAME; T_SCHEDULING_ANALYSIS(InitMutex(lock, name)); NotifyWaitObjectListeners(&WaitObjectListener::MutexInitialized, lock); }
/* Initialze CRL members */ int InitCRL(CYASSL_CRL* crl, CYASSL_CERT_MANAGER* cm) { CYASSL_ENTER("InitCRL"); crl->cm = cm; crl->crlList = NULL; crl->monitors[0].path = NULL; crl->monitors[1].path = NULL; #ifdef HAVE_CRL_MONITOR crl->tid = 0; #endif if (InitMutex(&crl->crlLock) != 0) return BAD_MUTEX_ERROR; return 0; }
/* Initialze CRL members */ int InitCRL(CYASSL_CRL* crl, CYASSL_CERT_MANAGER* cm) { CYASSL_ENTER("InitCRL"); crl->cm = cm; crl->crlList = NULL; crl->monitors[0].path = NULL; crl->monitors[1].path = NULL; #ifdef HAVE_CRL_MONITOR crl->tid = 0; crl->mfd = -1; /* mfd for bsd is kqueue fd, eventfd for linux */ #endif if (InitMutex(&crl->crlLock) != 0) return BAD_MUTEX_E; return 0; }
int wolfSSL_init_memory_heap(WOLFSSL_HEAP* heap) { word32 wc_MemSz[WOLFMEM_DEF_BUCKETS] = { WOLFMEM_BUCKETS }; word32 wc_Dist[WOLFMEM_DEF_BUCKETS] = { WOLFMEM_DIST }; if (heap == NULL) { return BAD_FUNC_ARG; } XMEMSET(heap, 0, sizeof(WOLFSSL_HEAP)); XMEMCPY(heap->sizeList, wc_MemSz, sizeof(wc_MemSz)); XMEMCPY(heap->distList, wc_Dist, sizeof(wc_Dist)); if (InitMutex(&(heap->memory_mutex)) != 0) { WOLFSSL_MSG("Error creating heap memory mutex"); return BAD_MUTEX_E; } return 0; }
CrossProcessMutex::CrossProcessMutex(const char*) : mMutex(nullptr) , mCount(nullptr) { #ifdef OS_MACOSX if (!nsCocoaFeatures::OnLionOrLater()) { // Don't allow using the cross-process mutex before OS X 10.7 because it // probably doesn't work very well. See discussion in bug 1072093 for more // details. MOZ_CRASH(); } #endif mSharedBuffer = new ipc::SharedMemoryBasic; if (!mSharedBuffer->Create(sizeof(MutexData))) { MOZ_CRASH(); } if (!mSharedBuffer->Map(sizeof(MutexData))) { MOZ_CRASH(); } MutexData* data = static_cast<MutexData*>(mSharedBuffer->memory()); if (!data) { MOZ_CRASH(); } mMutex = &(data->mMutex); mCount = &(data->mCount); *mCount = 1; InitMutex(mMutex); MOZ_COUNT_CTOR(CrossProcessMutex); }
bool wolfSSL_TI_CCMInit(void) { if(ccm_init)return true ; ccm_init = true ; SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); if(!ROM_SysCtlPeripheralPresent(SYSCTL_PERIPH_CCM0)) return false ; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_CCM0); WAIT(ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0)) ; ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_CCM0); WAIT(ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0)) ; #ifndef SINGLE_THREADED InitMutex(&TI_CCM_Mutex) ; #endif return true ; }
/*** * 功能: 依据指定的信息创建触摸屏对象 * 参数: 1.char *strDevName: 需要创建触摸屏对象的设备的名称 2.int iFbType: 触摸屏缓冲设备类型,1标准、2自定义 3.unsigned int uiHorRes: 触摸屏水平分辨率 4.unsigned int uiVerRes: 触摸屏垂直分辨率 5.THREADFUNC fnTouchThread: 回调函数,用于创建帧缓冲的线程 * 返回: 成功返回有效指针,失败返回NULL * 备注: ***/ GUITOUCH* CreateTouch(char *strDevName, int iDevType, unsigned int uiHorRes, unsigned int uiVerRes, THREADFUNC fnTouchThread) { //错误标志、返回值定义 int iErr = 0; GUITOUCH *pTouchObj = NULL; if (!iErr) { //判断strDevName, fnTouchThread是否为有效指针 if (NULL == strDevName || NULL == fnTouchThread) { iErr = -1; } //判断触摸屏分辨率是否有效 if (uiHorRes > 0xFFFF || uiVerRes > 0xFFFF) { iErr = -1; } } if (!iErr) { //申请内存资源 pTouchObj = (GUITOUCH *) malloc(sizeof(GUITOUCH)); if (NULL == pTouchObj) { iErr = -2; } } #if (GUI_OS_ENV == LINUX_OS) //OS相关:open() if (!iErr) { //尝试打开设备文件 pTouchObj->iDevFd = open(strDevName, O_RDWR|O_NONBLOCK); if (-1 == pTouchObj->iDevFd) { iErr = -3; } //设置新建触摸屏对象的iDevType pTouchObj->iDevType = iDevType; } #else #error "Unknown GUI_OS_ENV, not supported current GUI_OS_ENV!" #endif //GUI_OS_ENV == LINUX_OS if (!iErr) { //设置新建触摸屏对象的分辨率 pTouchObj->uiHorRes = uiHorRes; pTouchObj->uiVerRes = uiVerRes; pTouchObj->uiCursX = 0; pTouchObj->uiCursY = 0; //设置新建触摸屏对象的fnTouchThread,并尝试初始化Mutex pTouchObj->fnTouchThread = fnTouchThread; if (InitMutex(&(pTouchObj->Mutex), NULL)) { iErr = -4; } } #if (GUI_OS_ENV == LINUX_OS) //OS相关:close() //错误处理 switch (iErr) { case -4: close(pTouchObj->iDevType); //no break case -3: free(pTouchObj); //no break case -2: case -1: pTouchObj = NULL; //no break default: break; } #else #error "Unknown GUI_OS_ENV, not supported current GUI_OS_ENV!" #endif //GUI_OS_ENV == LINUX_OS return pTouchObj; }
ByteBuffer::ByteBuffer(int init_size):_capacity(init_size),_used(0){ InitMutex(); _buffer = new char[init_size]; }
ByteBuffer::ByteBuffer():_capacity(1024),_used(0){ InitMutex(); _buffer = new char[1024]; }
/* * initialize sets up the memory allocation arena and the run-time * configuration information. */ static void initialize(void) { size_t size = MEMORY_CREATION_SIZE; size_t slack; char * string; Slot * slot; EF_Print(version); #ifdef __linux__ { struct rlimit nolimit = { RLIM_INFINITY, RLIM_INFINITY }; int rc = setrlimit( RLIMIT_AS, &nolimit); } #endif lock(); /* * Import the user's environment specification of the default * alignment for malloc(). We want that alignment to be under * user control, since smaller alignment lets us catch more bugs, * however some software will break if malloc() returns a buffer * that is not word-aligned. * * I would like * alignment to be zero so that we could catch all one-byte * overruns, however if malloc() is asked to allocate an odd-size * buffer and returns an address that is not word-aligned, or whose * size is not a multiple of the word size, software breaks. * This was the case with the Sun string-handling routines, * which can do word fetches up to three bytes beyond the end of a * string. I handle this problem in part by providing * byte-reference-only versions of the string library functions, but * there are other functions that break, too. Some in X Windows, one * in Sam Leffler's TIFF library, and doubtless many others. */ if ( EF_ALIGNMENT == -1 ) { if ( (string = getenv("EF_ALIGNMENT")) != 0 ) EF_ALIGNMENT = (size_t)atoi(string); else EF_ALIGNMENT = sizeof(int); } /* * See if the user wants to protect the address space below a buffer, * rather than that above a buffer. */ if ( EF_PROTECT_BELOW == -1 ) { if ( (string = getenv("EF_PROTECT_BELOW")) != 0 ) EF_PROTECT_BELOW = (atoi(string) != 0); else EF_PROTECT_BELOW = 0; } /* * See if the user wants to protect memory that has been freed until * the program exits, rather than until it is re-allocated. */ if ( EF_PROTECT_FREE == -1 ) { if ( (string = getenv("EF_PROTECT_FREE")) != 0 ) EF_PROTECT_FREE = (atoi(string) != 0); else EF_PROTECT_FREE = 0; } /* * See if the user wants to allow malloc(0). */ if ( EF_ALLOW_MALLOC_0 == -1 ) { if ( (string = getenv("EF_ALLOW_MALLOC_0")) != 0 ) EF_ALLOW_MALLOC_0 = (atoi(string) != 0); else EF_ALLOW_MALLOC_0 = 0; } /* * Check if we should be filling new memory with a value. */ if ( EF_FILL == -1 ) { if ( (string = getenv("EF_FILL")) != 0) EF_FILL = (unsigned char) atoi(string); } /* * Get the run-time configuration of the virtual memory page size. */ bytesPerPage = Page_Size(); /* * Figure out how many Slot structures to allocate at one time. */ slotCount = slotsPerPage = bytesPerPage / sizeof(Slot); allocationListSize = bytesPerPage; if ( allocationListSize > size ) size = allocationListSize; if ( (slack = size % bytesPerPage) != 0 ) size += bytesPerPage - slack; /* * Allocate memory, and break it up into two malloc buffers. The * first buffer will be used for Slot structures, the second will * be marked free. */ slot = allocationList = (Slot *)Page_Create(size); memset((char *)allocationList, 0, allocationListSize); slot[0].internalSize = slot[0].userSize = allocationListSize; slot[0].internalAddress = slot[0].userAddress = allocationList; slot[0].mode = INTERNAL_USE; if ( size > allocationListSize ) { slot[1].internalAddress = slot[1].userAddress = ((char *)slot[0].internalAddress) + slot[0].internalSize; slot[1].internalSize = slot[1].userSize = size - slot[0].internalSize; slot[1].mode = FREE; } /* * Deny access to the free page, so that we will detect any software * that treads upon free memory. */ Page_DenyAccess(slot[1].internalAddress, slot[1].internalSize); /* * Account for the two slot structures that we've used. */ unUsedSlots = slotCount - 2; /* if (slotCount > 1) DpsSort(allocationList, slotCount, sizeof(Slot), (qsort_cmp)cmp_Slot);*/ release(); #ifdef HAVE_PTHREAD if (!semEnabled) { semEnabled = 1; #if USE_DPS_MUTEX InitMutex(&ef_mutex); #else if (sem_init(&EF_sem, 0, 1) < 0) { semEnabled = 0; } #endif } #endif }
static LONG APIENTRY WndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam) { switch (message) { case WM_CREATE: { LPCREATESTRUCT lpCr = (LPCREATESTRUCT)lParam; SetWindowLongPtr (hWnd, GWLP_USERDATA, (LONG_PTR)lpCr->lpCreateParams); SetTimer (hWnd, 0, 60000, NULL); break; } case WM_COPYDATA: { PCOPYDATASTRUCT pCopyData = (PCOPYDATASTRUCT)lParam; CONNINST *pInst; IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (pInst = FindClient (hProxy, (HWND)wParam)) { if (pInst->hProxy->pMyCfg->bDelayLogin && pInst->iConnectionStat < 1) { char *pszError; if ((pInst->iConnectionStat = Imo2S_Login (pInst->hInst, hProxy->pCfg->pszUser, hProxy->pCfg->pszPass, &pszError)) != 1) { pInst->hProxy->pCfg->logerror (stderr, "Connection %08X: Cannot login with (%s/****): %s\n", pInst->hWnd, hProxy->pCfg->pszUser, pszError); FreeConnection(pInst); free (List_Pop(hProxy->hClients)); PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_REFUSED); return 0; } } LockMutex(pInst->sendmutex); if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog) { fprintf (pInst->hProxy->pCfg->fpLog, "%08X< [%s]\n", pInst->hWnd, pCopyData->lpData); fflush (pInst->hProxy->pCfg->fpLog); } Imo2S_Send (pInst->hInst, pCopyData->lpData); UnlockMutex(pInst->sendmutex); } return 1; } case WM_TIMER: // Housekeeping timer CleanConnections (((IMO2SPROXY_INST*)GetWindowLongPtr(hWnd, GWLP_USERDATA))->hClients); break; case WM_DESTROY: KillTimer (hWnd, 0); break; default: if (message == m_ControlAPIDiscover) { CONNINST *pInst; IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)GetWindowLongPtr(hWnd, GWLP_USERDATA); char *pszError; if (!(pInst = FindClient (hProxy, (HWND)wParam))) { pInst = (CONNINST*)calloc (1, sizeof(CONNINST)); if (!pInst) break; List_Push(hProxy->hClients, pInst); pInst->hProxy = hProxy; pInst->hWnd = (HWND)wParam; if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog) fprintf (hProxy->pCfg->fpLog, "Imo2sproxy::SkypeControlAPIDiscover\n"); if (!(pInst->hInst = Imo2S_Init(EventHandler, pInst, hProxy->pCfg->iFlags))) { hProxy->pCfg->logerror (stderr, "Connection %08X: Cannot start Imo2Skype instance.\n", pInst->hWnd); free (List_Pop(hProxy->hClients)); PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_REFUSED); return 0; } // FIXME: We should enable logging dependent on a loglevel rather than just enabling it if (hProxy->pCfg->bVerbose) Imo2S_SetLog (pInst->hInst, hProxy->pCfg->fpLog); InitMutex(pInst->sendmutex); if (!pInst->hProxy->pMyCfg->bDelayLogin) { PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE); if ((pInst->iConnectionStat = Imo2S_Login (pInst->hInst, hProxy->pCfg->pszUser, hProxy->pCfg->pszPass, &pszError)) != 1) { pInst->hProxy->pCfg->logerror (stderr, "Connection %08X: Cannot login with (%s/****): %s\n", pInst->hWnd, hProxy->pCfg->pszUser, pszError); FreeConnection(pInst); free (List_Pop(hProxy->hClients)); PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_REFUSED); return 0; } PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_API_AVAILABLE); } else { SendMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_SUCCESS); } return 0; } else SendMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_SUCCESS); return 0; } break; } return (DefWindowProc(hWnd, message, wParam, lParam)); }
CWMutex::CWMutex() { InitMutex(); }