Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
b21e9e32
Commit
b21e9e32
authored
Feb 18, 2021
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
id queue
parent
58a8db42
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
327 additions
and
2 deletions
+327
-2
QtUtils.h
jlib/qt/QtUtils.h
+2
-2
id_queue.h
jlib/util/id_queue.h
+84
-0
process.h
jlib/win32/process.h
+3
-0
test.sln
test/test.sln
+16
-0
test_id_queue.cpp
test/test_id_queue/test_id_queue.cpp
+41
-0
test_id_queue.vcxproj
test/test_id_queue/test_id_queue.vcxproj
+150
-0
test_id_queue.vcxproj.filters
test/test_id_queue/test_id_queue.vcxproj.filters
+27
-0
test_id_queue.vcxproj.user
test/test_id_queue/test_id_queue.vcxproj.user
+4
-0
No files found.
jlib/qt/QtUtils.h
View file @
b21e9e32
...
...
@@ -109,7 +109,7 @@ inline void set_pos(QWidget * widget, QRect pos)
widget
->
move
(
pos
.
left
(),
pos
.
top
());
}
inline
void
set_image_bg
(
QWidget
*
widget
,
QPixmap
pixmap
)
inline
void
set_image_bg
(
QWidget
*
widget
,
const
QPixmap
&
pixmap
)
{
if
(
!
widget
||
pixmap
.
isNull
())
return
;
QPalette
palette
;
...
...
@@ -117,7 +117,7 @@ inline void set_image_bg(QWidget* widget, QPixmap pixmap)
widget
->
setPalette
(
palette
);
}
inline
void
set_image_bg
(
QWidget
*
widget
,
QString
icon_path
)
inline
void
set_image_bg
(
QWidget
*
widget
,
const
QString
&
icon_path
)
{
QPixmap
pixmap
;
if
(
!
LOAD_PIXMAP_EX
(
icon_path
))
{
return
;
}
...
...
jlib/util/id_queue.h
0 → 100644
View file @
b21e9e32
#pragma once
#include "../base/noncopyable.h"
#include <stdint.h>
#include <limits>
#include <queue>
#include <mutex>
namespace
jlib
{
// not thread safe
template
<
typename
T
>
class
IdQueue
:
noncopyable
{
public
:
using
value_type
=
T
;
explicit
IdQueue
(
T
min_val
=
0
,
T
max_val
=
std
::
numeric_limits
<
T
>::
max
(),
T
init_hot
=
50
)
:
minValue
(
min_val
)
,
maxValue
(
max_val
)
,
currentMax
(
init_hot
+
min_val
)
,
availableConnIds
()
{
for
(
T
i
=
0
;
i
<
init_hot
;
i
++
)
{
availableConnIds
.
push
(
i
+
minValue
);
}
}
virtual
T
aquire
()
{
if
(
!
availableConnIds
.
empty
())
{
auto
id
=
availableConnIds
.
front
();
availableConnIds
.
pop
();
return
id
;
}
else
if
(
currentMax
<
maxValue
)
{
return
currentMax
++
;
}
else
{
return
maxValue
;
// failed
}
}
virtual
void
release
(
T
id
)
{
availableConnIds
.
push
(
id
);
}
protected
:
T
minValue
=
0
;
T
maxValue
=
0
;
T
currentMax
=
0
;
std
::
queue
<
T
>
availableConnIds
{};
};
// thread safe
template
<
typename
T
>
class
IdQueue2
:
public
IdQueue
<
T
>
{
public
:
explicit
IdQueue2
(
T
min_val
=
0
,
T
max_val
=
std
::
numeric_limits
<
T
>::
max
(),
T
init_hot
=
50
)
:
IdQueue
<
T
>
(
min_val
,
max_val
,
init_hot
)
{}
virtual
T
aquire
()
override
{
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex
);
return
IdQueue
<
T
>::
aquire
();
}
virtual
void
release
(
T
id
)
override
{
std
::
lock_guard
<
std
::
mutex
>
lg
(
mutex
);
IdQueue
<
T
>::
release
(
id
);
}
protected
:
std
::
mutex
mutex
{};
};
using
IntIdQ
=
IdQueue
<
int
>
;
using
IntIdQ2
=
IdQueue2
<
int
>
;
using
UInt32IdQ
=
IdQueue
<
uint32_t
>
;
using
UInt32IdQ2
=
IdQueue2
<
uint32_t
>
;
using
UInt64IdQ
=
IdQueue
<
uint64_t
>
;
using
UInt64IdQ2
=
IdQueue2
<
uint64_t
>
;
}
jlib/win32/process.h
View file @
b21e9e32
...
...
@@ -42,6 +42,9 @@ inline DWORD daemon(const std::wstring& path, bool wait_app_exit = true, bool sh
}
else
{
return
pi
.
dwProcessId
;
}
}
else
{
auto
msg
=
formatLastError
(
""
);
msg
.
length
();
}
return
0xFFFFFFFF
;
}
...
...
test/test.sln
View file @
b21e9e32
...
...
@@ -101,6 +101,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "util", "util", "{E13021FA-C
ProjectSection(SolutionItems) = preProject
..\jlib\util\chrono_wrapper.h = ..\jlib\util\chrono_wrapper.h
..\jlib\util\curl_wrapper.h = ..\jlib\util\curl_wrapper.h
..\jlib\util\id_queue.h = ..\jlib\util\id_queue.h
..\jlib\util\jsoncpp_helper.h = ..\jlib\util\jsoncpp_helper.h
..\jlib\util\mem_tool.h = ..\jlib\util\mem_tool.h
..\jlib\util\micro_getter_setter.h = ..\jlib\util\micro_getter_setter.h
...
...
@@ -341,6 +342,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sudoku_clients", "sudoku_cl
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simple_libevent_clients_md", "simple_libevent_clients_md\simple_libevent_clients_md.vcxproj", "{9A68AAC1-2293-4E85-944E-47356E5313E7}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_id_queue", "test_id_queue\test_id_queue.vcxproj", "{52AF7381-83F5-4425-BED2-AA8F2FE3A085}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
...
...
@@ -1021,6 +1024,18 @@ Global
{9A68AAC1-2293-4E85-944E-47356E5313E7}.Release|x64.Build.0 = Release|x64
{9A68AAC1-2293-4E85-944E-47356E5313E7}.Release|x86.ActiveCfg = Release|Win32
{9A68AAC1-2293-4E85-944E-47356E5313E7}.Release|x86.Build.0 = Release|Win32
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Debug|ARM.ActiveCfg = Debug|Win32
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Debug|ARM64.ActiveCfg = Debug|Win32
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Debug|x64.ActiveCfg = Debug|x64
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Debug|x64.Build.0 = Debug|x64
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Debug|x86.ActiveCfg = Debug|Win32
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Debug|x86.Build.0 = Debug|Win32
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Release|ARM.ActiveCfg = Release|Win32
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Release|ARM64.ActiveCfg = Release|Win32
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Release|x64.ActiveCfg = Release|x64
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Release|x64.Build.0 = Release|x64
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Release|x86.ActiveCfg = Release|Win32
{52AF7381-83F5-4425-BED2-AA8F2FE3A085}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
@@ -1107,6 +1122,7 @@ Global
{4BE991D8-F6BB-47C7-B4DE-3767DE77DDB6} = {77DBD16D-112C-448D-BA6A-CE566A9331FC}
{B87D5885-6846-40E8-ACDC-B0F8798368AE} = {77DBD16D-112C-448D-BA6A-CE566A9331FC}
{9A68AAC1-2293-4E85-944E-47356E5313E7} = {729A65CE-3F07-4C2E-ACDC-F9EEC6477F2A}
{52AF7381-83F5-4425-BED2-AA8F2FE3A085} = {ABCB8CF8-5E82-4C47-A0FC-E82DF105DF99}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A8EBEA58-739C-4DED-99C0-239779F57D5D}
...
...
test/test_id_queue/test_id_queue.cpp
0 → 100644
View file @
b21e9e32
#include "../../jlib/util/id_queue.h"
#include <assert.h>
template
<
typename
Q
>
void
test
(
typename
Q
::
value_type
max_val
=
100
)
{
Q
q
;
typedef
Q
::
value_type
T
;
for
(
T
i
=
0
;
i
<
max_val
;
i
++
)
{
assert
(
q
.
aquire
()
==
i
);
}
assert
(
q
.
aquire
()
==
max_val
);
for
(
T
i
=
0
;
i
<
max_val
;
i
++
)
{
q
.
release
(
i
);
}
for
(
T
i
=
0
;
i
<
max_val
;
i
++
)
{
assert
(
q
.
aquire
()
==
i
);
}
}
int
main
()
{
/*jlib::IntIdQ q(0, 100);
for (int i = 0; i < 100; i++) {
assert(q.aquire() == i);
}
assert(q.aquire() == 100);
for (int i = 0; i < 100; i++) {
q.release(i);
}
for (int i = 0; i < 100; i++) {
assert(q.aquire() == i);
}*/
test
<
jlib
::
IntIdQ
>
();
test
<
jlib
::
IntIdQ2
>
();
test
<
jlib
::
UInt32IdQ
>
();
test
<
jlib
::
UInt32IdQ2
>
();
test
<
jlib
::
UInt64IdQ
>
();
test
<
jlib
::
UInt64IdQ2
>
();
}
test/test_id_queue/test_id_queue.vcxproj
0 → 100644
View file @
b21e9e32
<?xml version="1.0" encoding="utf-8"?>
<Project
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup
Label=
"ProjectConfigurations"
>
<ProjectConfiguration
Include=
"Debug|Win32"
>
<Configuration>
Debug
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|Win32"
>
<Configuration>
Release
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Debug|x64"
>
<Configuration>
Debug
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|x64"
>
<Configuration>
Release
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup
Label=
"Globals"
>
<VCProjectVersion>
16.0
</VCProjectVersion>
<Keyword>
Win32Proj
</Keyword>
<ProjectGuid>
{52af7381-83f5-4425-bed2-aa8f2fe3a085}
</ProjectGuid>
<RootNamespace>
testidqueue
</RootNamespace>
<WindowsTargetPlatformVersion>
10.0
</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.Default.props"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
true
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
false
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
true
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
false
</UseDebugLibraries>
<PlatformToolset>
v142
</PlatformToolset>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<CharacterSet>
Unicode
</CharacterSet>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.props"
/>
<ImportGroup
Label=
"ExtensionSettings"
>
</ImportGroup>
<ImportGroup
Label=
"Shared"
>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<PropertyGroup
Label=
"UserMacros"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<LinkIncremental>
true
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<LinkIncremental>
false
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<LinkIncremental>
true
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<LinkIncremental>
false
</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile
Include=
"test_id_queue.cpp"
/>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"..\..\jlib\util\id_queue.h"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
</ImportGroup>
</Project>
\ No newline at end of file
test/test_id_queue/test_id_queue.vcxproj.filters
0 → 100644
View file @
b21e9e32
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup>
<Filter
Include=
"Source Files"
>
<UniqueIdentifier>
{4FC737F1-C7A5-4376-A066-2A32D752A2FF}
</UniqueIdentifier>
<Extensions>
cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
</Extensions>
</Filter>
<Filter
Include=
"Header Files"
>
<UniqueIdentifier>
{93995380-89BD-4b04-88EB-625FBE52EBFB}
</UniqueIdentifier>
<Extensions>
h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
</Extensions>
</Filter>
<Filter
Include=
"Resource Files"
>
<UniqueIdentifier>
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
</UniqueIdentifier>
<Extensions>
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"test_id_queue.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"..\..\jlib\util\id_queue.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
test/test_id_queue/test_id_queue.vcxproj.user
0 → 100644
View file @
b21e9e32
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"Current"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup
/>
</Project>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment