void *runPC() { waitSemaphore(&siA); waitSemaphore(&siB); while (1) { waitSemaphore(&siiC); waitSemaphore(&siii); produce('C'); signalSemaphore(&siiB); } }
//>>=========================================================================== bool RELATIONSHIP_CLASS::commit(string sopClassUid, string sopInstanceUid, LOG_CLASS * logger_ptr) // DESCRIPTION : Commit the storage if the sop instance can be found. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { STORED_SOP_INSTANCE_CLASS* storedSopInstance_ptr; bool result = false; // wait for access to warehouse waitSemaphore(); // check if the sop is stored storedSopInstance_ptr = storedSopListM.search(sopClassUid, sopInstanceUid, logger_ptr); if (storedSopInstance_ptr) { // commit the storage storedSopInstance_ptr->commit(); // return success result = true; } // release access to warehouse postSemaphore(); // return result return result; }
void decreaseTimerNode(long arg0, long arg1, long arg2, long arg3, long arg4, \ long arg5, long arg6, long arg7, long arg8, long arg9) { TimerNodePtr tmp_node; TimerItemPtr tmp_item; while (g_timer_switcher == 1) { waitSemaphore(g_timer_tick_sem); lockTimerGlobalInfo(); if (g_timer_chain == NULL) { timer_debug("decreaseTimerNode: g_timer_chain is empty"); unlockTimerGlobalInfo(); continue; } tmp_node = g_timer_chain; timer_debug("decreaseTimerNode: before tick_num %d", tmp_node->tick_number); tmp_node->tick_number --; if (tmp_node->tick_number == 0) { timer_debug("decreaseTimerNode: activate timers"); while (tmp_node->item_head != NULL) { tmp_item = tmp_node->item_head; tmp_node->item_head = tmp_item->next; activateTimerItem(tmp_item); my_free(tmp_item); } timer_debug("decreaseTimerNode: after activate"); g_timer_chain = tmp_node->next; my_free(tmp_node); } timer_debug("decreaseTimerNode: end of"); unlockTimerGlobalInfo(); } timer_debug("decreaseTimerNode: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); postSemaphore(g_timer_end_sem); }
//>>=========================================================================== UINT16 RELATIONSHIP_CLASS::analyseStorageDataset(DCM_DATASET_CLASS *dataset_ptr, string& msg, LOG_CLASS *logger_ptr, bool isAcceptDuplicateImage) // DESCRIPTION : Analyse the Storage Dataset. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { // wait for access to warehouse waitSemaphore(); UINT16 status = DCM_STATUS_PROCESSING_FAILURE; // analyse the Storage Dataset for the patient relationship patientListM.analyseStorageDataset(dataset_ptr, logger_ptr); // analyse the Storage Dataset for the stored sop status = storedSopListM.analyseStorageDataset(dataset_ptr, msg, logger_ptr, isAcceptDuplicateImage); // release access to warehouse postSemaphore(); return status; }
bool OBJECT_WAREHOUSE_CLASS::update(string identifier, BASE_WAREHOUSE_ITEM_DATA_CLASS *updateData_ptr) // DESCRIPTION : Update the data in the warehouse. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { bool result = false; UINT index; // check for valid data if (updateData_ptr == NULL) return false; // wait for access to warehouse waitSemaphore(); // find the item to update if (search(identifier, updateData_ptr->getWidType(), &index)) { // update the matching item BASE_WAREHOUSE_ITEM_DATA_CLASS *item_ptr = itemM[index].getItemData(); result = item_ptr->updateWid(updateData_ptr); } // release access to warehouse postSemaphore(); // return result return result; }
bool OBJECT_WAREHOUSE_CLASS::remove(string identifier, WID_ENUM type) // DESCRIPTION : Remove data from the warehouse. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { bool result = false; UINT index; // wait for access to warehouse waitSemaphore(); // search for item to remove if (search(identifier, type, &index)) { // remove item BASE_WAREHOUSE_ITEM_DATA_CLASS *item_ptr = itemM[index].getItemData(); delete item_ptr; itemM.removeAt(index); result = true; } // release access to warehouse postSemaphore(); // return result return result; }
bool OBJECT_WAREHOUSE_CLASS::store(string identifier, BASE_WAREHOUSE_ITEM_DATA_CLASS* data_ptr) // DESCRIPTION : Store given data in the warehouse. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { UINT index; // check for valid data if (data_ptr == NULL) return false; // wait for access to warehouse waitSemaphore(); // first check if the same identifier has already been used if (search(identifier, data_ptr->getWidType(), &index)) { // remove existing item - the new data will simply replace the old itemM.removeAt(index); } // store the new data WAREHOUSE_ITEM_CLASS newData(identifier, data_ptr); itemM.add(newData); // release access to warehouse postSemaphore(); // return result return true; }
void OBJECT_WAREHOUSE_CLASS::empty() // DESCRIPTION : Empty the warehouse of all stored items. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { // wait for access to warehouse waitSemaphore(); // destructor activities while (itemM.getSize()) { // remove warehouse item itemM.removeAt(0); } // reset the reference tag referenceTagM = TAG_UNDEFINED; // release access to warehouse postSemaphore(); }
void produce(char ch) { pthread_mutex_lock(&mutexP); waitSemaphore(&sP); buf[wi++] = ch; wi %= BUF_SIZE; signalSemaphore(&sC); pthread_mutex_unlock(&mutexP); }
void *runC() { while (1) { waitSemaphore(&sC); putchar(buf[ri++]); ri %= BUF_SIZE; signalSemaphore(&sP); } }
void deinitTimer() { TimerNodePtr tmp_node; TimerItemPtr tmp_item; timer_debug("deinitTimer: "); g_timer_switcher = 0; waitSemaphore(g_timer_end_sem); destroySemaphore(g_timer_end_sem); sysClkDisable(); destroySemaphore(g_timer_tick_sem); while (g_timer_chain != NULL) { tmp_node = g_timer_chain; g_timer_chain = tmp_node->next; removeTimerNode(tmp_node); } g_timer_chain = NULL; deinitCallbackInfo(); timer_loginfo("deinit g_timer_chain success"); }
//>>=========================================================================== void RELATIONSHIP_CLASS::logObjectRelationshipAnalysis(LOG_CLASS *logger_ptr) // DESCRIPTION : Log the Object Relationship Analysis. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { // wait for access to warehouse waitSemaphore(); // log the patient list patientListM.log(logger_ptr); // log the stored sop list storedSopListM.log(logger_ptr); // release access to warehouse postSemaphore(); }
//>>=========================================================================== void RELATIONSHIP_CLASS::cleanup() // DESCRIPTION : Cleanup the relationship data. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { // wait for access to warehouse waitSemaphore(); // cleanup the patient list - instantiate it again patientListM.cleanup(); // cleanup the stored sop list - instantiate it again storedSopListM.cleanup(); // release access to warehouse postSemaphore(); }
static void slow_gatherer_windowsNT( void (*add)(const void*, size_t, int), int requester ) { static int is_initialized = 0; static NETSTATISTICSGET pNetStatisticsGet = NULL; static NETAPIBUFFERSIZE pNetApiBufferSize = NULL; static NETAPIBUFFERFREE pNetApiBufferFree = NULL; static int is_workstation = 1; static int cbPerfData = PERFORMANCE_BUFFER_SIZE; PERF_DATA_BLOCK *pPerfData; HANDLE hDevice, hNetAPI32 = NULL; DWORD dwSize, status; int nDrive; if ( !is_initialized ) { HKEY hKey; if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: init toolkit\n" ); /* Find out whether this is an NT server or workstation if necessary */ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_READ, &hKey) == ERROR_SUCCESS) { BYTE szValue[32]; dwSize = sizeof (szValue); if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: check product options\n" ); status = RegQueryValueEx (hKey, "ProductType", 0, NULL, szValue, &dwSize); if (status == ERROR_SUCCESS && stricmp (szValue, "WinNT")) { /* Note: There are (at least) three cases for ProductType: * WinNT = NT Workstation, ServerNT = NT Server, LanmanNT = * NT Server acting as a Domain Controller */ is_workstation = 0; if ( debug_me ) log_debug ("rndw32: this is a NT server\n"); } RegCloseKey (hKey); } /* Initialize the NetAPI32 function pointers if necessary */ if ( (hNetAPI32 = LoadLibrary ("NETAPI32.DLL")) ) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: netapi32 loaded\n" ); pNetStatisticsGet = (NETSTATISTICSGET) GetProcAddress (hNetAPI32, "NetStatisticsGet"); pNetApiBufferSize = (NETAPIBUFFERSIZE) GetProcAddress (hNetAPI32, "NetApiBufferSize"); pNetApiBufferFree = (NETAPIBUFFERFREE) GetProcAddress (hNetAPI32, "NetApiBufferFree"); if ( !pNetStatisticsGet || !pNetApiBufferSize || !pNetApiBufferFree ) { FreeLibrary (hNetAPI32); hNetAPI32 = NULL; log_debug ("rndw32: No NETAPI found\n" ); } } is_initialized = 1; } /* Get network statistics. Note: Both NT Workstation and NT Server by * default will be running both the workstation and server services. The * heuristic below is probably useful though on the assumption that the * majority of the network traffic will be via the appropriate service. * In any case the network statistics return almost no randomness */ { LPBYTE lpBuffer; if (hNetAPI32 && !pNetStatisticsGet (NULL, is_workstation ? L"LanmanWorkstation" : L"LanmanServer", 0, 0, &lpBuffer) ) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: get netstats\n" ); pNetApiBufferSize (lpBuffer, &dwSize); (*add) ( lpBuffer, dwSize,requester ); pNetApiBufferFree (lpBuffer); } } /* Get disk I/O statistics for all the hard drives */ for (nDrive = 0;; nDrive++) { char diskPerformance[SIZEOF_DISK_PERFORMANCE_STRUCT]; char szDevice[50]; /* Check whether we can access this device */ sprintf (szDevice, "\\\\.\\PhysicalDrive%d", nDrive); hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDevice == INVALID_HANDLE_VALUE) break; /* Note: This only works if you have turned on the disk performance * counters with 'diskperf -y'. These counters are off by default */ if (DeviceIoControl (hDevice, IOCTL_DISK_PERFORMANCE, NULL, 0, diskPerformance, SIZEOF_DISK_PERFORMANCE_STRUCT, &dwSize, NULL)) { if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: iostats drive %d\n", nDrive ); (*add) (diskPerformance, dwSize, requester ); } else { log_info ("NOTE: you should run 'diskperf -y' " "to enable the disk statistics\n"); } CloseHandle (hDevice); } #if 0 /* we don't need this in GnuPG */ /* Wait for any async keyset driver binding to complete. You may be * wondering what this call is doing here... the reason it's necessary is * because RegQueryValueEx() will hang indefinitely if the async driver * bind is in progress. The problem occurs in the dynamic loading and * linking of driver DLL's, which work as follows: * * hDriver = LoadLibrary( DRIVERNAME ); * pFunction1 = ( TYPE_FUNC1 ) GetProcAddress( hDriver, NAME_FUNC1 ); * pFunction2 = ( TYPE_FUNC1 ) GetProcAddress( hDriver, NAME_FUNC2 ); * * If RegQueryValueEx() is called while the GetProcAddress()'s are in * progress, it will hang indefinitely. This is probably due to some * synchronisation problem in the NT kernel where the GetProcAddress() * calls affect something like a module reference count or function * reference count while RegQueryValueEx() is trying to take a snapshot * of the statistics, which include the reference counts. Because of * this, we have to wait until any async driver bind has completed * before we can call RegQueryValueEx() */ waitSemaphore (SEMAPHORE_DRIVERBIND); #endif /* Get information from the system performance counters. This can take * a few seconds to do. In some environments the call to * RegQueryValueEx() can produce an access violation at some random time * in the future, adding a short delay after the following code block * makes the problem go away. This problem is extremely difficult to * reproduce, I haven't been able to get it to occur despite running it * on a number of machines. The best explanation for the problem is that * on the machine where it did occur, it was caused by an external driver * or other program which adds its own values under the * HKEY_PERFORMANCE_DATA key. The NT kernel calls the required external * modules to map in the data, if there's a synchronisation problem the * external module would write its data at an inappropriate moment, * causing the access violation. A low-level memory checker indicated * that ExpandEnvironmentStrings() in KERNEL32.DLL, called an * interminable number of calls down inside RegQueryValueEx(), was * overwriting memory (it wrote twice the allocated size of a buffer to a * buffer allocated by the NT kernel). This may be what's causing the * problem, but since it's in the kernel there isn't much which can be * done. * * In addition to these problems the code in RegQueryValueEx() which * estimates the amount of memory required to return the performance * counter information isn't very accurate, since it always returns a * worst-case estimate which is usually nowhere near the actual amount * required. For example it may report that 128K of memory is required, * but only return 64K of data */ { pPerfData = gcry_xmalloc (cbPerfData); for (;;) { dwSize = cbPerfData; if ( debug_me ) log_debug ("rndw32#slow_gatherer_nt: get perf data\n" ); status = RegQueryValueEx (HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, (LPBYTE) pPerfData, &dwSize); if (status == ERROR_SUCCESS) { if (!memcmp (pPerfData->Signature, L"PERF", 8)) { (*add) ( pPerfData, dwSize, requester ); } else log_debug ( "rndw32: no PERF signature\n"); break; } else if (status == ERROR_MORE_DATA) { cbPerfData += PERFORMANCE_BUFFER_STEP; pPerfData = gcry_realloc (pPerfData, cbPerfData); } else { log_debug ( "rndw32: get performance data problem\n"); break; } } gcry_free (pPerfData); } /* Although this isn't documented in the Win32 API docs, it's necessary to explicitly close the HKEY_PERFORMANCE_DATA key after use (it's implicitly opened on the first call to RegQueryValueEx()). If this isn't done then any system components which provide performance data can't be removed or changed while the handle remains active */ RegCloseKey (HKEY_PERFORMANCE_DATA); }
void lockTimerGlobalInfo() { waitSemaphore(g_timer_global_info_sem); }