JIHUNYOON / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Patch: Add Thread Enter/Exit Events #345

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
To make it easier to do database connection pooling in my app, I've created 
this patch to expand the callback functions so that they provide calls when 
each worker thread starts and stops. This should not cause any added overhead 
since the number of worker threads is static.

The comments in the mongoose.h should be self-explanatory.

Events added: MG_ENTER_THREAD, MG_EXIT_THREAD (These events receive unusual 2nd 
and 3rd parameters. Since there is no socket connection when they are called, 
the 2nd parameter is replaced by the void *user_data originally passed to 
mg_start().)

Structures modified: mg_request_info -> added void* thread_ctx

Functions modified: worker_thread()

Tested only on Windows, with Visual Studio 6.

Original issue reported on code.google.com by jmucchie...@gmail.com on 17 Apr 2012 at 5:34

Attachments:

GoogleCodeExporter commented 8 years ago
This could actually also be used to set the priorities of the worker threads to 
a value that is appropriate for the individual system - together with a similar 
event for the master thread.

Original comment by bel2...@gmail.com on 24 Apr 2012 at 3:59

GoogleCodeExporter commented 8 years ago
I considered adding a master thread hook when I was making the patch but I 
don't have a need for it and I try to follow the "You Won't Need It" principle 
whenever possible. Now if there is a need, I could add it. Probably would use 
MG_ENTER_MASTER and MG_EXIT_MASTER as the event IDs to make things simple.

Original comment by jmucchie...@gmail.com on 24 Apr 2012 at 4:15