mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 01:21:08 +00:00
Fix globally unique string.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14245 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a6541762d3
commit
620ebe03a1
2 changed files with 21 additions and 11 deletions
|
@ -13,6 +13,8 @@
|
||||||
* Source/NSObject.m: Remove dealloc notifications hack ... the
|
* Source/NSObject.m: Remove dealloc notifications hack ... the
|
||||||
dealloc method can now safely be used to refrain from deallocating
|
dealloc method can now safely be used to refrain from deallocating
|
||||||
objects, so I don't think the hack is needed any more.
|
objects, so I don't think the hack is needed any more.
|
||||||
|
* Source/NSProcessInfo.m: ([-globallyUniqueString]) Update to ensure
|
||||||
|
uniqueness across all hosts, processes, and threads.
|
||||||
* Tools/gdomap.c: Tidyup patch by Matthias Klose
|
* Tools/gdomap.c: Tidyup patch by Matthias Klose
|
||||||
|
|
||||||
2002-07-29 Adam Fedor <fedor@gnu.org>
|
2002-07-29 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
|
@ -40,9 +40,8 @@
|
||||||
* purpose to override the autorelease, retain, and release methods.
|
* purpose to override the autorelease, retain, and release methods.
|
||||||
* To Do :
|
* To Do :
|
||||||
* 1) To test the class on more platforms;
|
* 1) To test the class on more platforms;
|
||||||
* 2) To change the format of the string renurned by globallyUniqueString;
|
|
||||||
* Bugs : Not known
|
* Bugs : Not known
|
||||||
* Last update: 22-jul-1999
|
* Last update: 07-aug-2002
|
||||||
* History : 06-aug-1995 - Birth and the first beta version (v. 0.5);
|
* History : 06-aug-1995 - Birth and the first beta version (v. 0.5);
|
||||||
* 08-aug-1995 - V. 0.6 (tested on NS, SunOS, Solaris, OSF/1
|
* 08-aug-1995 - V. 0.6 (tested on NS, SunOS, Solaris, OSF/1
|
||||||
* The use of the environ global var was changed to more
|
* The use of the environ global var was changed to more
|
||||||
|
@ -589,24 +588,33 @@ int main(int argc, char *argv[], char *env[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string which may be used as a unique identifier for the
|
* Returns a string which may be used as a globally unique identifier.<br />
|
||||||
* current process.
|
* The string contains the host name, the process ID, a timestamp and a
|
||||||
|
* counter (to ensure that multiple strings generated within the same
|
||||||
|
* process are unique).
|
||||||
*/
|
*/
|
||||||
- (NSString *) globallyUniqueString
|
- (NSString *) globallyUniqueString
|
||||||
{
|
{
|
||||||
int pid;
|
static int pid = 0;
|
||||||
|
static int counter = 0;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
if (pid == 0)
|
||||||
|
{
|
||||||
#if defined(__MINGW__)
|
#if defined(__MINGW__)
|
||||||
pid = (int)GetCurrentProcessId();
|
pid = (int)GetCurrentProcessId();
|
||||||
#else
|
#else
|
||||||
pid = (int)getpid();
|
pid = (int)getpid();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
[gnustep_global_lock lock];
|
||||||
|
count = counter++;
|
||||||
|
[gnustep_global_lock unlock];
|
||||||
|
|
||||||
// $$$ The format of the string is not specified by the OpenStep
|
// $$$ The format of the string is not specified by the OpenStep
|
||||||
// specification. It could be useful to change this format after
|
// specification.
|
||||||
// NeXTSTEP release 4.0 comes out.
|
return [NSString stringWithFormat: @"%@_%d_%lf_%d",
|
||||||
return [NSString stringWithFormat: @"%@:%d:[%@]",
|
[self hostName], pid, GSTimeNow(), count];
|
||||||
[self hostName], pid, [NSDate date]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue