return buf;
}
+int WorkList::initialize() {
+ hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ return 0;
+ }
+
+int WorkList::cleanup() {
+ CloseHandle(hEvent);
+ hEvent = INVALID_HANDLE_VALUE;
+ return 0;
+ }
+
+void WorkList::wait() {
+ WaitForSingleObject(hEvent, INFINITE);
+ }
+
int WorkList::add(WorkItem* item) {
EnterCriticalSection(&cs);
wl.push_front(item);
LeaveCriticalSection(&cs);
+ SetEvent(hEvent);
return 1;
}
* or implied warranty.
*/
+#include "WorkQueue.h"
extern "C" {
#include "cci_debugging.h"
}
WorkList worklist;
+EXTERN_C int worklist_initialize() {
+ return worklist.initialize();
+ }
+
+EXTERN_C int worklist_cleanup() {
+ return worklist.cleanup();
+ }
+
+EXTERN_C void worklist_wait() {
+ worklist.wait();
+ }
+
/* C interfaces: */
-EXTERN_C bool worklist_isEmpty() {
- return worklist.isEmpty();
+EXTERN_C BOOL worklist_isEmpty() {
+ return worklist.isEmpty() ? TRUE : FALSE;
}
EXTERN_C int worklist_add( const long rpcmsg,
#include "windows.h"
#include "ccs_pipe.h"
+EXTERN_C int worklist_initialize();
+
+EXTERN_C int worklist_cleanup();
+
+/* Wait for work to be added to the list (via worklist_add) from another thread */
+EXTERN_C void worklist_wait();
+
EXTERN_C BOOL worklist_isEmpty();
-EXTERN_C void worklist_add( const long rpcmsg,
+EXTERN_C int worklist_add( const long rpcmsg,
const ccs_pipe_t pipe,
const k5_ipc_stream stream,
const time_t serverStartTime);
// status = startup_server(opts);
// }
+ if (!err) {
+ err = worklist_initialize();
+ }
+
if (err) {
Init::Cleanup();
fprintf( stderr, "An error occured while %s the server (%u)\n",
cci_debug_printf("%s for user <%s> shutting down.", argv[0], argv[1]);
+ worklist_cleanup();
+
return cci_check_error (err);
}
cc_int32 ccs_os_server_listen_loop (int argc, const char *argv[]) {
cc_int32 err = 0;
uintptr_t threadStatus;
- unsigned int loopCounter = 0;
ParseOpts::Opts opts = { 0 };
ParseOpts PO;
queue. */
rpcargs.sessID = (unsigned char*)sessID;
rpcargs.opts = &opts;
+ /// TODO: check for NULL handle, error, etc. probably move to initialize func...
threadStatus = _beginthread(receiveLoop, 0, (void*)&rpcargs);
/* We handle the queue entries here. Work loop: */
while (TRUE) {
- loopCounter++;
- if (worklist_isEmpty() & 1) {
- SleepEx(1000, TRUE);
- }
- else if (TRUE) { // Take next WorkItem from the queue:
+ worklist_wait();
+ while (!worklist_isEmpty()) {
k5_ipc_stream buf = NULL;
long rpcmsg = CCMSG_INVALID;
time_t serverStartTime = 0xDEADDEAD;
else {cci_debug_printf("Huh? Queue not empty but no item to remove.");}
}
}
-
return cci_check_error (err);
}
private:
std::list <WorkItem*> wl;
CRITICAL_SECTION cs;
+ HANDLE hEvent;
public:
WorkList();
~WorkList();
+ int initialize();
+ int cleanup();
+ void wait();
int add(WorkItem*);
int remove(WorkItem**);
bool isEmpty() {return wl.empty();}