Change pid to tid only
This commit is contained in:
parent
393be6fc71
commit
a0fc970dbc
2
ab.c
2
ab.c
|
@ -206,7 +206,7 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
wyebclient(argv[0]);
|
wyebclient(argv[0]);
|
||||||
}
|
}
|
||||||
else if (g_str_has_prefix(argv[1], WYEBPREFIX))
|
else if (!strcmp(argv[1], WYEBPREFIX))
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
wyebsvr(argc, argv, datafunc);
|
wyebsvr(argc, argv, datafunc);
|
||||||
|
|
19
wyebrun.c
19
wyebrun.c
|
@ -18,9 +18,8 @@ along with wyebrun. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//getpid
|
//gettid
|
||||||
#include <sys/types.h>
|
#include <sys/syscall.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
//flock
|
//flock
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
@ -213,12 +212,12 @@ static gboolean svrinit(char *caller)
|
||||||
|
|
||||||
bool wyebsvr(int argc, char **argv, wyebdataf func)
|
bool wyebsvr(int argc, char **argv, wyebdataf func)
|
||||||
{
|
{
|
||||||
if (argc < 2 || !g_str_has_prefix(argv[1], PREFIX)) return false;
|
if (argc < 3 || strcmp(argv[1], PREFIX)) return false;
|
||||||
|
|
||||||
svrexe = argv[0];
|
svrexe = argv[0];
|
||||||
dataf = func;
|
dataf = func;
|
||||||
sloop = g_main_loop_new(NULL, false);
|
sloop = g_main_loop_new(NULL, false);
|
||||||
g_idle_add((GSourceFunc)svrinit, argv[1]);
|
g_idle_add((GSourceFunc)svrinit, argv[2]);
|
||||||
g_main_loop_run(sloop);
|
g_main_loop_run(sloop);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -276,8 +275,7 @@ static Client *makecli()
|
||||||
{
|
{
|
||||||
Client *cli = g_new0(Client, 1);
|
Client *cli = g_new0(Client, 1);
|
||||||
g_mutex_init(&cli->retm);
|
g_mutex_init(&cli->retm);
|
||||||
cli->pid = g_strdup_printf(PREFIX"%d-%d",
|
cli->pid = g_strdup_printf("%d", (pid_t)syscall(SYS_gettid));
|
||||||
getpid(), GPOINTER_TO_INT(g_thread_self()));
|
|
||||||
|
|
||||||
cli->wctx = g_main_context_new();
|
cli->wctx = g_main_context_new();
|
||||||
cli->loop = g_main_loop_new(cli->wctx, true);
|
cli->loop = g_main_loop_new(cli->wctx, true);
|
||||||
|
@ -387,9 +385,10 @@ static char *request(char *exe, Com type, bool caller, char *data)
|
||||||
g_source_attach(tout, cli->wctx);
|
g_source_attach(tout, cli->wctx);
|
||||||
|
|
||||||
|
|
||||||
char **argv = g_new0(char*, 3);
|
char **argv = g_new0(char*, 4);
|
||||||
argv[0] = exe;
|
argv[0] = exe;
|
||||||
argv[1] = cli->pid;
|
argv[1] = PREFIX;
|
||||||
|
argv[2] = cli->pid;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
|
if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
|
||||||
NULL, NULL, NULL, &err))
|
NULL, NULL, NULL, &err))
|
||||||
|
@ -494,7 +493,7 @@ static gboolean tcinputcb(GIOChannel *ch, GIOCondition c, char *exe)
|
||||||
GThreadPool *pool = g_thread_pool_new(testget, exe, 44, false, NULL);
|
GThreadPool *pool = g_thread_pool_new(testget, exe, 44, false, NULL);
|
||||||
|
|
||||||
start = g_get_monotonic_time();
|
start = g_get_monotonic_time();
|
||||||
for (int i = 0; i < 10000; i++)
|
for (int i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
char *is = g_strdup_printf("l%d", i);
|
char *is = g_strdup_printf("l%d", i);
|
||||||
//g_print("loop %d ret %s\n", i, wyebget(exe, is));
|
//g_print("loop %d ret %s\n", i, wyebget(exe, is));
|
||||||
|
|
|
@ -23,7 +23,7 @@ along with wyebrun. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
|
|
||||||
#define WYEBPREFIX "-wyeb"
|
#define WYEBPREFIX "--wyebrun"
|
||||||
#define WYEBKEEPSEC 3
|
#define WYEBKEEPSEC 3
|
||||||
|
|
||||||
//client
|
//client
|
||||||
|
@ -43,7 +43,8 @@ typedef char *(*wyebdataf)(char *data);
|
||||||
bool wyebsvr(int argc, char **argv, wyebdataf func);
|
bool wyebsvr(int argc, char **argv, wyebdataf func);
|
||||||
//or if there is own GMainLoop
|
//or if there is own GMainLoop
|
||||||
void wyebwatch(char *exe, char *caller, wyebdataf func);
|
void wyebwatch(char *exe, char *caller, wyebdataf func);
|
||||||
//the caller is used to send the res meaning we are ready.
|
//the caller is sent as 'exe --wyebrun 9999' and
|
||||||
|
//used to send the res meaning we are ready.
|
||||||
//3 sec left or client will die
|
//3 sec left or client will die
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user