soc.2009.vulture: 7f90cb53: Facility for synchronising with multiple...

gdick at soc.pidgin.im gdick at soc.pidgin.im
Mon Jun 1 19:15:45 EDT 2009


-----------------------------------------------------------------
Revision: 7f90cb53f8934f8c75f1ab5002540a935ee55e60
Ancestor: d3411106f6b0d049bb1e9a97a58de4081ef5576f
Author: gdick at soc.pidgin.im
Date: 2009-06-01T14:45:20
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/7f90cb53f8934f8c75f1ab5002540a935ee55e60

Modified files:
        vulture/Makefile.mingw vulture/purplequeue.c
        vulture/purplequeue.h vulture/vulture.c

ChangeLog: 

Facility for synchronising with multiple libpurple calls.

-------------- next part --------------
============================================================
--- vulture/Makefile.mingw	3eb22c0baec2a9c102f56fb7fc9f8eed0ce1af5e
+++ vulture/Makefile.mingw	9820fbe787c7eac7ce5868e797348dc9af13ca9b
@@ -69,7 +69,8 @@ VULTURE_LIBS =	\
 		-lglib-2.0 \
 		-lpurple \
 		-lwinmm \
-		-lcomctl32
+		-lcomctl32 \
+		-lgthread-2.0
 
 include $(PIDGIN_COMMON_RULES)
 
============================================================
--- vulture/purplequeue.c	6c545ceaa7b26d23fbd7c8753a55017416af3b20
+++ vulture/purplequeue.c	a78d220e90e5ccd1148a4d43df8ba79876b95b3f
@@ -323,3 +323,38 @@ GSource* VultureCreateSyncQueueSource(vo
 {
 	return &CreateQueueSource(g_lpgqSyncQueue, &g_csSyncQueue, g_heventSyncQueue, SYNC_QUEUE_PRIORITY)->gsource;
 }
+
+
+/**
+ * Waits for libpurple calls in a given context to complete, and then destroys
+ * the context.
+ *
+ * @param	lpgarrayWaitContext	Wait context.
+ */
+void VulturePurpleWait(GArray *lpgarrayWaitContext)
+{
+	int i;
+
+	WaitForMultipleObjects(lpgarrayWaitContext->len, (HANDLE*)lpgarrayWaitContext->data, TRUE, INFINITE);
+	
+	for(i = 0; i < lpgarrayWaitContext->len; i++)
+		CloseHandle(g_array_index(lpgarrayWaitContext, HANDLE, i));
+
+	g_array_free(lpgarrayWaitContext, TRUE);
+}
+
+
+/**
+ * Enqueues a synchronous call to libpurple, creating a handle for
+ * synchornisation and adding it to the given wait context.
+ *
+ * @param	iCallID			ID of the operation to perform.
+ * @param	lpvParam		Function-specific data.
+ * @param	lpgarrayWaitContext	Wait context for synchronisation.
+ */
+void VultureEnqueueMultiSyncPurpleCall(int iCallID, void *lpvParam, GArray *lpgarrayWaitContext)
+{
+	HANDLE hevent = CreateEvent(NULL, TRUE, FALSE, NULL);
+	g_array_append_val(lpgarrayWaitContext, hevent);
+	VultureEnqueueSyncPurpleCall(iCallID, lpvParam, hevent);
+}
============================================================
--- vulture/purplequeue.h	04e1c2fbd16adb662b8f251eccb4e56031b6ea08
+++ vulture/purplequeue.h	4fdefd735e45f077430d6ea3be7a9416153131e5
@@ -28,7 +28,9 @@
 #include <windows.h>
 #include <glib.h>
 
+#include "vulture.h"
 
+
 /** IDs of calls to libpurple. Used as values for iCallID member of
  * PURPLE_CALL.
  */
@@ -44,6 +46,18 @@ GSource* VultureCreateSyncQueueSource(vo
 void VultureEnqueueSyncPurpleCall(int iCallID, void *lpvParam, HANDLE heventSync);
 GSource* VultureCreateAsyncQueueSource(void);
 GSource* VultureCreateSyncQueueSource(void);
+void VulturePurpleWait(GArray *lpgarrayWaitContext);
+void VultureEnqueueMultiSyncPurpleCall(int iCallID, void *lpvParam, GArray *lpgarrayWaitContext);
 
 
+
+/**
+ * Allocates an object used to wait for several synchronous libpurple calls.
+ *
+ * @return Wait context. Pass this to VultureEnqueueMultiSyncPurpleCall and
+ * VulturePurpleWait.
+ */
+//static INLINE GArray* VultureAllocPurpleWaitContext(void) { return g_array_new(FALSE, FALSE, sizeof(HANDLE)); }
+
+
 #endif
============================================================
--- vulture/vulture.c	f15f179367d38665bfec041e6ffb79b625d4be89
+++ vulture/vulture.c	df1be7c4ec6af2d07b91f047323570de020123da
@@ -23,6 +23,7 @@
 
 #include <windows.h>
 #include <commctrl.h>
+#include <glib.h>
 
 #include "vulture.h"
 #include "resource.h"
@@ -61,6 +62,8 @@ int WINAPI WinMain(HINSTANCE hinst, HINS
 	iccx.dwICC = ICC_WIN95_CLASSES | ICC_USEREX_CLASSES;
 	InitCommonControlsEx(&iccx);
 
+	g_thread_init(NULL);
+
 	VultureParseCommandLine();
 
 	if(VultureCreateMainWindow(iCmdShow) != 0)


More information about the Commits mailing list