[mv_findThread]

Description

Link: [mv_findThread]
Author: Marc Vos
Category: Threads
Version: 8.5.x
License: Public Domain
Posted: Aug. 27, 2010
Updated: Aug. 27, 2010
More by this author...
This tag either returns an array of maps with found thread data or simply true or false. This way you can check if a Lasso process is already running. It searches for the given string in the thread_name field.

Parameters

-name string, required Search string aka process name
-current string, optional What to do when the current thread is found
-signal string, optional Return a signal true if any thread with name is found

Sample Usage

[
mv_findThread('smtp', 'M', 'Y');'<hr>';
mv_findThread('smtp', 'X', 'Y');'<hr>';
mv_findThread('smtp', 'N', 'Y');'<hr>';

if (mv_findThread('/process', 'X', 'Y'));
 log_critical('Process X already running');
 abort;
/if;
]
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
define_tag('mv_findThread', -required='Name', -copy, -optional='current', -copy, -optional='signal', -copy);
/* current:
  M = Mark the array entry as being the calling thread.  X = eXclude the calling thread from the checks and the result list / signal.  any = Include calling thread in checks and result list without markings.
 signal:		
  Y = simply return true or false instead of a list with found threads.*/
 local(
  'tList' = array,
  'curID' = thread_getcurrentid,
  'insert'= false
 );

	// Set default value to M(ark)
 if(! local_defined('current'));
  local('current') = 'M';
 /if;

	// Set default value to N(o)
 if(! local_defined('signal'));
  local('signal') = 'N';
 /if;

 iterate(Thread_List, local('tmp'));
  #tmp = Thread_Info(#tmp);
  if (#tmp->find('name') >> #name);
   #insert=false;

   if(#tmp->find('id') >> #curID);
    if(#current == 'M');
     #tmp->insert('isMe'='Y');
     #insert=true;
    else(#current != 'X');
     #insert=true;
    /if;
   else;
    #insert=true;
   /if;

   if(#insert);
    if(#signal == 'Y');
     loop_abort;
    /if;
    #tList->insert(#tmp);
   /if;
  /if;
 /iterate;

 if(#signal == 'Y');
  return(#insert);
 else;
  return(#tList);
 /if;

/define_tag;

 

Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net